1.添加各种级别权限角色,修改权限状态
This commit is contained in:
parent
2e02a18dad
commit
38e2261a4e
@ -1172,7 +1172,7 @@ async def api_list(
|
||||
return schemas.Msg(code=200, msg='ok', data=res)
|
||||
|
||||
|
||||
@router.post("/del_api_module")
|
||||
@router.post("/alter_api_module")
|
||||
async def add_policy(
|
||||
request: Request,
|
||||
data_in: schemas.Add_module,
|
||||
@ -1183,23 +1183,10 @@ async def add_policy(
|
||||
res = await crud.api_module.get_one_module(db, data_in)
|
||||
for i in range(len(res['state'])):
|
||||
if data_in.url == res['api_list'][i]:
|
||||
res['state'][i] = False
|
||||
await crud.api_module.update_one_module(db, res)
|
||||
return schemas.Msg(code=200, msg='修改成功', data='')
|
||||
|
||||
|
||||
@router.post("/add_api_module")
|
||||
async def add_policy(
|
||||
request: Request,
|
||||
data_in: schemas.Add_module,
|
||||
db: AsyncIOMotorDatabase = Depends(get_database),
|
||||
# current_user: schemas.UserDB = Depends(deps.get_current_user)
|
||||
):
|
||||
"""修改api_module权限状态"""
|
||||
res = await crud.api_module.get_one_module(db, data_in)
|
||||
for i in range(len(res['state'])):
|
||||
if data_in.url == res['api_list'][i]:
|
||||
res['state'][i] = True
|
||||
if data_in.types == False:
|
||||
res['state'][i] = False
|
||||
else:
|
||||
res['state'][i] = True
|
||||
await crud.api_module.update_one_module(db, res)
|
||||
return schemas.Msg(code=200, msg='修改成功', data='')
|
||||
|
||||
@ -1340,3 +1327,68 @@ async def roles(
|
||||
data_dcit['system'] = system[0]
|
||||
data.append(data_dcit)
|
||||
return schemas.Msg(code=200, msg='ok', data=data)
|
||||
|
||||
|
||||
@router.post("/add_roles")
|
||||
async def add_roles(
|
||||
request: Request,
|
||||
data_in: schemas.Add_role,
|
||||
db: AsyncIOMotorDatabase = Depends(get_database),
|
||||
# current_user: schemas.UserDB = Depends(deps.get_current_user)
|
||||
) -> schemas.Msg:
|
||||
"""
|
||||
创建不同权限角色
|
||||
"""
|
||||
res = await crud.url_list.get_all(db)
|
||||
for i in res: # 判断创建的角色是否已经存在
|
||||
if data_in.system == 1:
|
||||
if data_in.name == i['name']:
|
||||
return schemas.Msg(code=200, msg='该角色已存在!')
|
||||
else:
|
||||
if data_in.name == i['name']:
|
||||
return schemas.Msg(code=200, msg='该角色已存在!')
|
||||
auth = []
|
||||
# 系统默认权限角色
|
||||
if data_in.system == 1:
|
||||
for i in res:
|
||||
auth.append(i['auth_id'])
|
||||
max_auth = 'ab' + str(int(max(auth).split('b')[-1]) + 1)
|
||||
api_module = await crud.api_module.get_api_module(db)
|
||||
for i in api_module:
|
||||
if i['auth_id'] in data_in.path_name:
|
||||
await crud.url_list.insert_url(db, schemas.Url_list(name=data_in.name, auth_id=max_auth,
|
||||
path_name=i['path_name'], api_list=i['api_list'],
|
||||
api_name=i['api_name'], state=i['state'],
|
||||
system=data_in.system))
|
||||
else:
|
||||
state = []
|
||||
for nu in range(len(i['state'])):
|
||||
state.append(False)
|
||||
if i['path_name'] != 'root':
|
||||
await crud.url_list.insert_url(db, schemas.Url_list(name=data_in.name, auth_id=max_auth,
|
||||
path_name=i['path_name'],
|
||||
api_list=i['api_list'], api_name=i['api_name'],
|
||||
state=state, system=data_in.system))
|
||||
return schemas.Msg(code=200, msg='添加角色成功', data='')
|
||||
else: # 系统其他权限角色
|
||||
for i in res:
|
||||
auth.append(i['auth_id'])
|
||||
max_auth = 'ab' + str(int(max(auth).split('b')[-1]) + 1)
|
||||
api_module = await crud.api_module.get_api_module(db)
|
||||
for i in api_module:
|
||||
if i['auth_id'] in data_in.path_name:
|
||||
await crud.url_list.insert_urls(db, schemas.Url_lists(name=data_in.name, auth_id=max_auth,
|
||||
path_name=i['path_name'], api_list=i['api_list'],
|
||||
api_name=i['api_name'], state=i['state'],
|
||||
system=data_in.system))
|
||||
else:
|
||||
state = []
|
||||
for nu in range(len(i['state'])):
|
||||
state.append(False)
|
||||
if i['path_name'] != 'root':
|
||||
await crud.url_list.insert_urls(db, schemas.Url_lists(name=data_in.name, auth_id=max_auth,
|
||||
path_name=i['path_name'],
|
||||
api_list=i['api_list'],
|
||||
api_name=i['api_name'], state=state,
|
||||
system=data_in.system))
|
||||
return schemas.Msg(code=200, msg='添加角色成功', data='')
|
||||
|
@ -17,3 +17,4 @@ class Url_module(BaseModel):
|
||||
class Add_module(BaseModel):
|
||||
auth_id: str # 唯一标识
|
||||
url: str # 路由
|
||||
types: bool # Ture 或者 False
|
||||
|
@ -24,7 +24,6 @@ class Url_lists(BaseModel):
|
||||
api_name: List[str] = None
|
||||
state: List[bool] = None
|
||||
system: int = None
|
||||
game: str = None
|
||||
|
||||
|
||||
class Url_data(BaseModel):
|
||||
@ -46,16 +45,20 @@ class Add_role(BaseModel):
|
||||
system: int
|
||||
name: str
|
||||
|
||||
|
||||
class Del_role(BaseModel):
|
||||
path: str
|
||||
path_name: str
|
||||
role_id: str
|
||||
|
||||
|
||||
class Editname(BaseModel):
|
||||
role_id: str #= Field(..., description='要编辑的id')
|
||||
role_id: str # = Field(..., description='要编辑的id')
|
||||
name: str = None
|
||||
desc: str = None
|
||||
|
||||
|
||||
class Del_roles(BaseModel):
|
||||
game:str
|
||||
role_id:str
|
||||
username:str
|
||||
game: str
|
||||
role_id: str
|
||||
username: str
|
||||
|
Loading…
Reference in New Issue
Block a user