def get_tenant_users(self, admin_token, tenant_id, marker, limit, url): self.__validate_token(admin_token, False) if tenant_id == None: raise fault.BadRequestFault("Expecting a Tenant Id") dtenant = api.TENANT.get(tenant_id) if dtenant is None: raise fault.ItemNotFoundFault("The tenant not found") if not dtenant.enabled: raise fault.TenantDisabledFault("Your account has been disabled") ts = [] dtenantusers = api.USER.users_get_by_tenant_get_page( tenant_id, marker, limit) for dtenantuser in dtenantusers: ts.append( User( None, dtenantuser.id, dtenantuser.name, tenant_id, dtenantuser.email, dtenantuser.eppn, dtenantuser.enabled, dtenantuser.tenant_roles if hasattr( dtenantuser, "tenant_roles") else None)) links = [] if ts.__len__(): prev, next = api.USER.users_get_by_tenant_get_page_markers( tenant_id, marker, limit) if prev: links.append( atom.Link('prev', "%s?'marker=%s&limit=%s'" % (url, prev, limit))) if next: links.append( atom.Link('next', "%s?'marker=%s&limit=%s'" % (url, next, limit))) return Users(ts, links)
def get_users(self, admin_token, marker, limit, url): self.__validate_admin_token(admin_token) ts = [] dusers = api.USER.users_get_page(marker, limit) for duser in dusers: ts.append(User(None, duser.id, duser.name, duser.tenant_id, duser.email, duser.enabled)) links = [] if ts.__len__(): prev, next = api.USER.users_get_page_markers(marker, limit) if prev: links.append(atom.Link('prev', "%s?'marker=%s&limit=%s'" % (url, prev, limit))) if next: links.append(atom.Link('next', "%s?'marker=%s&limit=%s'" % (url, next, limit))) return Users(ts, links)
def update_user(self, admin_token, user_id, user): self.__validate_admin_token(admin_token) duser = api.USER.get(user_id) if not duser: raise fault.ItemNotFoundFault("The user could not be found") if not isinstance(user, User): raise fault.BadRequestFault("Expecting a User") if user.email != duser.email and \ api.USER.get_by_email(user.email) is not None: raise fault.EmailConflictFault("Email already exists") values = {'email': user.email} api.USER.update(user_id, values) duser = api.USER.user_get_update(user_id) return User(duser.password, duser.id, duser.name, duser.tenant_id, duser.email, duser.enabled)