Mercurial > kallithea
changeset 8623:ae3d9b4c043e
auth: compute AuthUser.permissions lazily
Prepare for computing each kind of permissions separately so they can be
skipped in the common case.
This will undo a part of 1ecd6c0e2787 where we took the detour of assigning
permissions in __init__ - now we move it back to a LazyProperty, but in a
better way.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Sun, 23 Aug 2020 14:26:21 +0200 |
parents | cd8d45d4c3cd |
children | 8596a0a86673 |
files | kallithea/lib/auth.py |
diffstat | 1 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/auth.py Tue Aug 18 15:10:40 2020 +0200 +++ b/kallithea/lib/auth.py Sun Aug 23 14:26:21 2020 +0200 @@ -43,6 +43,7 @@ from kallithea.config.routing import url from kallithea.lib.utils import get_repo_group_slug, get_repo_slug, get_user_group_slug from kallithea.lib.utils2 import ascii_bytes, ascii_str, safe_bytes +from kallithea.lib.vcs.utils.lazy import LazyProperty from kallithea.model.db import (Permission, UserApiKeys, UserGroup, UserGroupMember, UserGroupRepoGroupToPerm, UserGroupRepoToPerm, UserGroupToPerm, UserGroupUserGroupToPerm, UserIpMap, UserToPerm) from kallithea.model.meta import Session @@ -430,12 +431,16 @@ log.debug('Getting PERMISSION tree for %s', self) (self.repository_permissions, self.repository_group_permissions, self.user_group_permissions, self.global_permissions, )= get_user_permissions(self.user_id, self.is_admin) - self.permissions = { + + @LazyProperty + def permissions(self): + """dict with all 4 kind of permissions - mainly for backwards compatibility""" + return { 'global': self.global_permissions, 'repositories': self.repository_permissions, 'repositories_groups': self.repository_group_permissions, 'user_groups': self.user_group_permissions, - } # backwards compatibility + } def has_repository_permission_level(self, repo_name, level, purpose=None): required_perms = {