This commit is contained in:
yumoqing 2026-03-21 13:23:49 +08:00
parent 1897adeba4
commit ca7834abf2

View File

@ -25,36 +25,36 @@ class UserPermissions:
async def load_roleperms(self, sor): async def load_roleperms(self, sor):
self.rp_caches = {} self.rp_caches = {}
sql_all = """select c.orgtypeid, c.name, b.path sql_all = """select c.id, c.orgtypeid, c.name, b.path
from rolepermission a, permission b, role c from rolepermission a, permission b, role c
where a.permid = b.id where a.permid = b.id
and c.id = a.roleid and c.id = a.roleid
order by c.orgtypeid, c.name""" order by c.orgtypeid, c.name"""
recs = await sor.sqlExe(sql_all, {}) recs = await sor.sqlExe(sql_all, {})
for r in recs: for r in recs:
k = 'anonymous' if r.id == 'anonymous':
if r.name == 'any': k = 'anonymous'
elif r.id == 'any':
k = 'any' k = 'any'
elif r.orgtypeid: elif r.id == 'logined':
k = 'logined'
else r.orgtypeid:
k = f'{r.orgtypeid}.{r.name}' k = f'{r.orgtypeid}.{r.name}'
arr = self.rp_caches.get(k, []) arr = self.rp_caches.get(k, [])
arr.append(r.path) arr.append(r.path)
self.rp_caches[k] = arr self.rp_caches[k] = arr
async def get_userroles(self, sor, userid): async def get_userroles(self, sor, userid):
recs = await sor.sqlExe('''select b.orgtypeid, b.name recs = await sor.sqlExe('''select b.id, b.orgtypeid, b.name
from users a, role b, userrole c from users a, role b, userrole c
where a.id = c.userid where a.id = c.userid
and c.roleid = b.id and c.roleid = b.id
and a.id = ${userid}$''', {'userid': userid}) and a.id = ${userid}$''', {'userid': userid})
roles = ['any', '*.*'] # 登录用户 roles = ['any', 'logined'] # 登录用户
for r in recs: for r in recs:
if r.name == 'any': roles.append(f'{r.orgtypeid}.{r.name}')
roles.append('any') roles.append(f'{r.orgtypeid}.*')
else: roles.append(f'*.{r.name}')
roles.append(f'{r.orgtypeid}.{r.name}')
roles.append(f'{r.orgtypeid}.*')
roles.append(f'*.{r.name}')
self.ur_caches[userid] = sorted(list(set(roles))) self.ur_caches[userid] = sorted(list(set(roles)))
def check_roles_path(self, roles, path): def check_roles_path(self, roles, path):