# HG changeset patch # User Mads Kiilerich # Date 1598185662 -7200 # Node ID 8596a0a866737f1b5616c7c11d33438ae15275e0 # Parent ae3d9b4c043ed7b27d9c064ae2e11c235fd7b412 auth: extract private parts from get_user_permissions Prepare for splitting it up. diff -r ae3d9b4c043e -r 8596a0a86673 kallithea/lib/auth.py --- 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 #======================================================================