def set_template_args(self, user, all_roles): super().set_template_args() # Get list of role uuids the grantee already has user_roles = list(user['roles'].keys()) try: all_roles = roles.list_metadata() except DataRequestException: all_roles = [] # Get a list of role uuids the current grantor can grant try: role_permissions = users.actions_on_type('roles') except DataRequestException: role_permissions = {} grantable_roles = [ role_id for role_id, actions in role_permissions.items() if 'grant' in actions ] # Remove any roles the grantee already has or grantor cannot grant. # Note that no user should have grant priveleges on a role belonging to # another organization, as this is disallowed at the API. all_roles = [ role for role in all_roles if role['role_id'] not in user_roles and role['role_id'] in grantable_roles ] self.template_args['user'] = user self.template_args['table_data'] = all_roles
def get(self): roles_list = roles.list_metadata().json() if 'errors' in roles_list: roles_list = None return render_template('forms/admin/roles.html', table_data=roles_list, **self.template_args())
def get(self, uuid): try: user = users.get_metadata(uuid) role_list = roles.list_metadata() except DataRequestException as e: self.flash_api_errors(e.errors) return render_template('forms/admin/user.html') else: self.set_template_args(user, role_list) return render_template('forms/admin/user.html', **self.template_args)
def get(self, uuid, **kwargs): """Form for adding roles to a user. """ try: user = users.get_metadata(uuid) all_roles = roles.list_metadata() except DataRequestException as e: self.flash_api_errors(e.errors) return render_template(self.template) else: self.set_template_args(user, all_roles) return render_template(self.template, **self.template_args, **kwargs)
def get(self, uuid): user = users.get_metadata(uuid).json() if 'errors' in user: user = None else: role_list = roles.list_metadata().json() role_map = {role['role_id']: role for role in role_list} user['roles'] = { k: { 'added_to_user': v, **role_map[k] } for k, v in user['roles'].items() if k in role_map } return render_template('forms/admin/user.html', user=user, **self.template_args())