def update(context, request): params = dict() domain = request.matchdict['domain'] Alias.get(request.db_session, domain) try: if "destination" in request.params: params['instance_id'] = Instance.get_by_domain( request.db_session, request.params['destination']).id if "new_domain" in request.params: check_domain_not_used(request, request.params['new_domain']) params['new_domain'] = validate_hostname( request.params['new_domain']) except NoResultFound: raise ParamsError("No instance for domain {}"\ .format(request.params['destination'])) if not params: raise ParamsError("Missing update fields") params['domain'] = domain return request.submit_task('alias.update', **params)
def login(context, request): email = urllib.unquote(request.matchdict['email']) user = User.get(request.db_session, email) # non-admin users cannot check if another user has permissions on a # given instance if authenticated_userid(request) != email and \ 'admin' not in effective_principals(request): return generate_empty_response(HTTPForbidden(), request, 403) try: # the domain could be an alias. We need the instance domain domain = Alias.get(request.db_session, request.params['domain'])\ .instance.domain except NoResultFound: domain = request.params['domain'] except KeyError: log.error('No domain in request for users.login') return generate_empty_response(HTTPForbidden(), request, 403) instance = Instance.get_by_domain(request.db_session, domain) if not user.can_access(instance): log.error('%s cannot login on %s', email, domain) return generate_empty_response(HTTPForbidden(), request, 403) return user.to_dict()
def update(session, task, domain, new_domain=None, instance_id=None): try: alias = Alias.get(session, domain) if instance_id: alias.instance = Instance.get(session, instance_id) if new_domain: alias.domain = new_domain session.flush() except: log.exception('alias.update')
def delete(session, task, domain): alias = Alias.get(session, domain) alias.delete()
def delete(context, request): domain = request.matchdict['domain'] Alias.get(request.db_session, domain) return request.submit_task('alias.delete', domain=domain)
def info(context, request): return Alias.get(request.db_session, request.matchdict['domain']).to_dict()
def list(context, request): return {a.domain: a.to_dict() for a in Alias.all(request.db_session)}