feature: 动态菜单生成
This commit is contained in:
@@ -5,6 +5,7 @@ from flask import Blueprint, make_response, redirect, request
|
||||
from flask_jwt_extended import (
|
||||
create_access_token,
|
||||
create_refresh_token,
|
||||
get_current_user,
|
||||
jwt_required,
|
||||
set_access_cookies,
|
||||
set_refresh_cookies,
|
||||
@@ -13,7 +14,7 @@ from flask_jwt_extended import (
|
||||
)
|
||||
|
||||
from pear_admin.extensions import db
|
||||
from pear_admin.orms import RightsORM, UserORM
|
||||
from pear_admin.orms import RightsORM, RoleORM, UserORM
|
||||
|
||||
passport_api = Blueprint("passport", __name__)
|
||||
|
||||
@@ -54,7 +55,13 @@ def logout():
|
||||
@passport_api.get("/menu")
|
||||
@jwt_required()
|
||||
def menus_api():
|
||||
rights_orm_list = RightsORM.query.filter(RightsORM.type != "auth").all()
|
||||
rights_orm_list = set()
|
||||
current_user: UserORM = get_current_user()
|
||||
for role in current_user.role_list:
|
||||
for rights_orm in role.rights_list:
|
||||
if rights_orm.type != "auth":
|
||||
rights_orm_list.add(rights_orm)
|
||||
|
||||
rights_list = [rights_orm.menu_json() for rights_orm in rights_orm_list]
|
||||
rights_list.sort(key=lambda x: (x["pid"], x["id"]), reverse=True)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
id,name,code,desc,rights_ids
|
||||
1,超级管理员,super_admin,,100:101:102:103:104:105:106:107:109:108:110:111:112:113:114:115:116:117:118:119:120
|
||||
1,超级管理员,super_admin,,100:101:102:103:104:105:106:107:109:108:110:111:112:113:114:115:116:117:118:119:120:124:125:126
|
||||
2,普通管理员,admin,,106:107:109:108:110:111:112:113:114:115:116:117:118:119:120
|
||||
3,普通用户,user,,111:112:113:114:115:116:117:118:119:120
|
||||
|
@@ -1,4 +1,4 @@
|
||||
id,nickname,username,password,mobile,email,avatar,department_id,role_ids
|
||||
1,admin,超级管理员,123456,15543526531,8540854@qq.com,,1,1
|
||||
2,就眠仪式,就眠仪式,123456,155324324234,8540854@qq.com,,1,2
|
||||
3,zhengxinonly,正心全栈编程,123456,18675867241,pyxxponly@gmail.com,,1,3
|
||||
3,zhengxinonly,正心全栈编程,123456,18675867241,pyxxponly@gmail.com,,1,1
|
||||
|
Reference in New Issue
Block a user