def get_group(group_id): group = Group.find_by_id(group_id) if group: return jsonify(status='ok', total=1, group=group.serialize) else: raise ApiError('not found', 404)
def get_group_users(group_id): if not Group.find_by_id(group_id): raise ApiError('not found', 404) group_users = GroupUsers.find_by_id(group_id) if group_users: return jsonify(status='ok', users=[user.serialize for user in group_users], total=len(group_users)) else: return jsonify(status='ok', users=[], total=0)
def delete_group(group_id): group = Group.find_by_id(group_id) if not group: raise ApiError('not found', 404) admin_audit_trail.send(current_app._get_current_object(), event='group-deleted', message='', user=g.login, customers=g.customers, scopes=g.scopes, resource_id=group.id, type='group', request=request) if group.delete(): return jsonify(status='ok') else: raise ApiError('failed to delete user group', 500)
def remove_user_from_group(group_id, user_id): group = Group.find_by_id(group_id) if not group: raise ApiError('not found', 404) user = User.find_by_id(user_id) if not user: raise ApiError('invalid user', 400) admin_audit_trail.send(current_app._get_current_object(), event='user-attributes-updated', message='', user=g.login, customers=g.customers, scopes=g.scopes, resource_id=user.id, type='user', request=request) if group.remove_user(user_id): return jsonify(status='ok') else: raise ApiError('failed to remove user from group', 500)
def update_group(group_id): if not request.json: raise ApiError('nothing to change', 400) group = Group.find_by_id(group_id) if not group: raise ApiError('not found', 404) admin_audit_trail.send(current_app._get_current_object(), event='group-updated', message='', user=g.user, customers=g.customers, scopes=g.scopes, resource_id=group.id, type='group', request=request) if group.update(**request.json): return jsonify(status='ok') else: raise ApiError('failed to update user group', 500)