| | |
| | | |
| | | async def role_list(db, page_size: int, page_index: int, keyword: str, role_key:str, user_id): |
| | | query = db.query(RoleModel) |
| | | if role_key != "admin": |
| | | query.filter(RoleModel.creator==user_id) |
| | | # if role_key != "admin": |
| | | # query.filter(RoleModel.creator==user_id) |
| | | if keyword: |
| | | query = query.filter(RoleModel.name.like('%{}%'.format(keyword))) |
| | | roles = query.order_by(RoleModel.id.desc()).limit(page_size).offset( |
| | |
| | | |
| | | async def create_role(db, role_name: str, description: str, role_key, data_scope, user_id): |
| | | try: |
| | | role_model = RoleModel(id=str(uuid.uuid4()),name=role_name, description=description,creator=user_id, data_scope=data_scope) |
| | | role_model = RoleModel(id=str(uuid.uuid4()),name=role_name, description=description,creator=user_id, dataScope=data_scope) |
| | | if role_key: |
| | | role_model.roleKey = role_key |
| | | db.add(role_model) |
| | |
| | | if role_key: |
| | | role.roleKey = role_key |
| | | if data_scope: |
| | | role.data_scope = data_scope |
| | | role.dataScope = data_scope |
| | | else: |
| | | role.resources = [db.get(ResourceModel, resourcesId) for resourcesId in resources] |
| | | db.add(role) |