63 lines
1.7 KiB
Plaintext
63 lines
1.7 KiB
Plaintext
from PDAPI import *
|
|
|
|
|
|
__metadata__ = {
|
|
"methods": ["GET"],
|
|
"blueprint": "UGM",
|
|
"permission": 1.0,
|
|
"attributes": [],
|
|
"limit": "10 per minute"
|
|
}
|
|
|
|
|
|
def HandleRequest(_CleanedData):
|
|
current_user = UGM.GetELTUser()
|
|
if not current_user:
|
|
return {"code": 401, "msg": "未登录"}, 401
|
|
|
|
current_role_uuid = flask.request.cookies.get("CurrentRoleUUID")
|
|
current_role_uuid_bytes = None
|
|
if current_role_uuid:
|
|
try:
|
|
current_role_uuid_bytes = UUIDObj(current_role_uuid).bytes
|
|
except:
|
|
current_role_uuid_bytes = None
|
|
|
|
user_roles = db.session.query(
|
|
GERPRole.RoleUUID,
|
|
GERPRole.RoleName,
|
|
GERPRole.CompanyUUID,
|
|
GERPRole.RoleStatus,
|
|
GERPCompany.CompanyName,
|
|
GERPCompany.CompanyShort
|
|
).join(
|
|
UserRole, GERPRole.RoleUUID == UserRole.RoleUUID
|
|
).outerjoin(
|
|
GERPCompany, GERPRole.CompanyUUID == GERPCompany.CompanyUUID
|
|
).filter(
|
|
UserRole.UserUUID == current_user.UserUUID
|
|
).all()
|
|
|
|
roles_data = []
|
|
for role in user_roles:
|
|
role_uuid_str = UUIDObj(role.RoleUUID).UpperStr
|
|
is_active = (current_role_uuid_bytes == role.RoleUUID) if current_role_uuid_bytes else False
|
|
|
|
roles_data.append({
|
|
"RoleUUID": role_uuid_str,
|
|
"RoleName": role.RoleName,
|
|
"CompanyUUID": UUIDObj(role.CompanyUUID).UpperStr if role.CompanyUUID else None,
|
|
"CompanyName": role.CompanyName,
|
|
"CompanyShort": role.CompanyShort,
|
|
"RoleStatus": role.RoleStatus,
|
|
"active": is_active
|
|
})
|
|
|
|
return {
|
|
"code": 0,
|
|
"data": {
|
|
"roles": roles_data,
|
|
"currentRoleUUID": current_role_uuid
|
|
}
|
|
}, 200
|