Compare commits
No commits in common. "50892fc3d28fc54363e5ca8361c1f6f4710582d5" and "ebd678a43d753f93bbfd4478cde8068721110f43" have entirely different histories.
50892fc3d2
...
ebd678a43d
@ -172,38 +172,15 @@ where a.id = c.userid
|
|||||||
self.ur_caches.set(userid, sorted(list(set(roles))))
|
self.ur_caches.set(userid, sorted(list(set(roles))))
|
||||||
|
|
||||||
def check_roles_path(self, roles, path):
|
def check_roles_path(self, roles, path):
|
||||||
"""Check if any of the roles has access to the given path.
|
"""Check if any of the roles has access to the given path."""
|
||||||
|
ret = False
|
||||||
Supports:
|
|
||||||
- Exact match: '/customer_management/index.ui' or '/main/login.ui'
|
|
||||||
- Wildcard prefix match: '/customer_management/**' matches any path starting with '/customer_management/'
|
|
||||||
- Path normalization: tries both the raw path and path with /main stripped
|
|
||||||
"""
|
|
||||||
for role in roles:
|
for role in roles:
|
||||||
paths = self.rp_caches.get(role)
|
paths = self.rp_caches.get(role)
|
||||||
if not paths:
|
if not paths:
|
||||||
continue
|
continue
|
||||||
# Try exact match with raw path
|
|
||||||
if path in paths:
|
if path in paths:
|
||||||
return True
|
return True
|
||||||
# Try with /main prefix stripped: /main/xxx -> /xxx
|
return ret
|
||||||
if path.startswith('/main/'):
|
|
||||||
normalized = '/' + path[6:]
|
|
||||||
if normalized in paths:
|
|
||||||
return True
|
|
||||||
# Also try wildcard match with normalized path
|
|
||||||
for perm_path in paths:
|
|
||||||
if perm_path.endswith('**'):
|
|
||||||
prefix = perm_path[:-2]
|
|
||||||
if normalized.startswith(prefix) or path.startswith(prefix):
|
|
||||||
return True
|
|
||||||
# Wildcard prefix match with raw path
|
|
||||||
for perm_path in paths:
|
|
||||||
if perm_path.endswith('**'):
|
|
||||||
prefix = perm_path[:-2]
|
|
||||||
if path.startswith(prefix):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
async def is_user_has_path_perm(self, userid, path):
|
async def is_user_has_path_perm(self, userid, path):
|
||||||
"""Check if a user has permission for the given path.
|
"""Check if a user has permission for the given path.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user