Mercurial > kallithea
changeset 8624:8596a0a86673
auth: extract private parts from get_user_permissions
Prepare for splitting it up.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Sun, 23 Aug 2020 14:27:42 +0200 |
parents | ae3d9b4c043e |
children | 4c79659e11e5 |
files | kallithea/lib/auth.py |
diffstat | 1 files changed, 13 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/auth.py Sun Aug 23 14:26:21 2020 +0200 +++ b/kallithea/lib/auth.py Sun Aug 23 14:27:42 2020 +0200 @@ -117,25 +117,26 @@ return False +PERM_WEIGHTS = Permission.PERM_WEIGHTS + +def bump_permission(permissions, key, new_perm): + """Add a new permission for key to permissions. + Assuming the permissions are comparable, set the new permission if it + has higher weight, else drop it and keep the old permission. + """ + cur_perm = permissions[key] + new_perm_val = PERM_WEIGHTS[new_perm] + cur_perm_val = PERM_WEIGHTS[cur_perm] + if new_perm_val > cur_perm_val: + permissions[key] = new_perm + def get_user_permissions(user_id, user_is_admin): - PERM_WEIGHTS = Permission.PERM_WEIGHTS repository_permissions = {} repository_group_permissions = {} user_group_permissions = {} global_permissions = set() - def bump_permission(permissions, key, new_perm): - """Add a new permission for key to permissions. - Assuming the permissions are comparable, set the new permission if it - has higher weight, else drop it and keep the old permission. - """ - cur_perm = permissions[key] - new_perm_val = PERM_WEIGHTS[new_perm] - cur_perm_val = PERM_WEIGHTS[cur_perm] - if new_perm_val > cur_perm_val: - permissions[key] = new_perm - #====================================================================== # fetch default permissions #======================================================================