# HG changeset patch # User Marcin Kuzminski # Date 2010-08-25 16:15:50 # Node ID 16253f3300946c9100d3f64982bb3e7735ff0a9c # Parent a6000c18a8db513ae6b5e3758fe2ce2f9f1f7368 fixes #30. Rewrite default permissions query + some other small fixes diff --git a/pylons_app/lib/auth.py b/pylons_app/lib/auth.py --- a/pylons_app/lib/auth.py +++ b/pylons_app/lib/auth.py @@ -141,16 +141,15 @@ def fill_perms(user): #=========================================================================== # fetch default permissions #=========================================================================== - default_perms = sa.query(RepoToPerm, UserToPerm, Repository, Permission)\ - .outerjoin((UserToPerm, RepoToPerm.user_id == UserToPerm.user_id))\ + default_perms = sa.query(RepoToPerm, Repository, Permission)\ .join((Repository, RepoToPerm.repository_id == Repository.repo_id))\ .join((Permission, RepoToPerm.permission_id == Permission.permission_id))\ - .filter(RepoToPerm.user_id == sa.query(User).filter(User.username == - 'default').one().user_id).all() + .filter(RepoToPerm.user == sa.query(User).filter(User.username == + 'default').scalar()).all() if user.is_admin: #======================================================================= - # #admin have all rights set to admin + # #admin have all default rights set to admin #======================================================================= user.permissions['global'].add('hg.admin') @@ -164,8 +163,12 @@ def fill_perms(user): #======================================================================= #default global - for perm in default_perms: - user.permissions['global'].add(perm.UserToPerm.permission.permission_name) + default_global_perms = sa.query(UserToPerm)\ + .filter(UserToPerm.user == sa.query(User).filter(User.username == + 'default').one()) + + for perm in default_global_perms: + user.permissions['global'].add(perm.permission.permission_name) #default repositories for perm in default_perms: @@ -183,8 +186,7 @@ def fill_perms(user): #======================================================================= # #overwrite default with user permissions if any #======================================================================= - user_perms = sa.query(RepoToPerm, UserToPerm, Permission, Repository)\ - .outerjoin((UserToPerm, RepoToPerm.user_id == UserToPerm.user_id))\ + user_perms = sa.query(RepoToPerm, Permission, Repository)\ .join((Repository, RepoToPerm.repository_id == Repository.repo_id))\ .join((Permission, RepoToPerm.permission_id == Permission.permission_id))\ .filter(RepoToPerm.user_id == user.user_id).all()