diff --git a/pylons_app/controllers/admin/repos.py b/pylons_app/controllers/admin/repos.py --- a/pylons_app/controllers/admin/repos.py +++ b/pylons_app/controllers/admin/repos.py @@ -222,7 +222,7 @@ class ReposController(BaseController): c.users_array = repo_model.get_users_js() - for p in c.repo_info.repo2perm: + for p in c.repo_info.repo_to_perm: defaults.update({'perm_%s' % p.user.username: p.permission.permission_name}) diff --git a/pylons_app/controllers/settings.py b/pylons_app/controllers/settings.py --- a/pylons_app/controllers/settings.py +++ b/pylons_app/controllers/settings.py @@ -60,7 +60,7 @@ class SettingsController(BaseController) defaults.update({'user':c.repo_info.user.username}) c.users_array = repo_model.get_users_js() - for p in c.repo_info.repo2perm: + for p in c.repo_info.repo_to_perm: defaults.update({'perm_%s' % p.user.username: p.permission.permission_name}) 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 @@ -27,7 +27,7 @@ from pylons import config, session, url, from pylons.controllers.util import abort, redirect from pylons_app.lib.utils import get_repo_slug from pylons_app.model import meta -from pylons_app.model.db import User, Repo2Perm, Repository, Permission +from pylons_app.model.db import User, RepoToPerm, Repository, Permission from sqlalchemy.exc import OperationalError from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound import crypt @@ -134,10 +134,10 @@ def fill_perms(user): user.permissions['global'] = set() #first fetch default permissions - default_perms = sa.query(Repo2Perm, Repository, Permission)\ - .join((Repository, Repo2Perm.repository_id == Repository.repo_id))\ - .join((Permission, Repo2Perm.permission_id == Permission.permission_id))\ - .filter(Repo2Perm.user_id == sa.query(User).filter(User.username == + 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() if user.is_admin: @@ -145,7 +145,7 @@ def fill_perms(user): #admin have all rights set to admin for perm in default_perms: p = 'repository.admin' - user.permissions['repositories'][perm.Repo2Perm.repository.repo_name] = p + user.permissions['repositories'][perm.RepoToPerm.repository.repo_name] = p else: user.permissions['global'].add('repository.create') @@ -159,13 +159,13 @@ def fill_perms(user): else: p = perm.Permission.permission_name - user.permissions['repositories'][perm.Repo2Perm.repository.repo_name] = p + user.permissions['repositories'][perm.RepoToPerm.repository.repo_name] = p - user_perms = sa.query(Repo2Perm, Permission, Repository)\ - .join((Repository, Repo2Perm.repository_id == Repository.repo_id))\ - .join((Permission, Repo2Perm.permission_id == Permission.permission_id))\ - .filter(Repo2Perm.user_id == user.user_id).all() + 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() #overwrite userpermissions with defaults for perm in user_perms: #set write if owner @@ -173,7 +173,7 @@ def fill_perms(user): p = 'repository.write' else: p = perm.Permission.permission_name - user.permissions['repositories'][perm.Repo2Perm.repository.repo_name] = p + user.permissions['repositories'][perm.RepoToPerm.repository.repo_name] = p meta.Session.remove() return user diff --git a/pylons_app/model/db.py b/pylons_app/model/db.py --- a/pylons_app/model/db.py +++ b/pylons_app/model/db.py @@ -64,7 +64,7 @@ class Repository(Base): description = Column("description", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) user = relation('User') - repo2perm = relation('Repo2Perm', cascade='all') + repo_to_perm = relation('RepoToPerm', cascade='all') class Permission(Base): __tablename__ = 'permissions' @@ -76,10 +76,10 @@ class Permission(Base): def __repr__(self): return "" % (self.permission_id, self.permission_name) -class Repo2Perm(Base): +class RepoToPerm(Base): __tablename__ = 'repo_to_perm' __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True}) - repo2perm_id = Column("repo2perm_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True) + repo_to_perm_id = Column("repo_to_perm_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True) user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None) permission_id = Column("permission_id", INTEGER(), ForeignKey(u'permissions.permission_id'), nullable=False, unique=None, default=None) repository_id = Column("repository_id", INTEGER(), ForeignKey(u'repositories.repo_id'), nullable=False, unique=None, default=None) @@ -87,3 +87,17 @@ class Repo2Perm(Base): user = relation('User') permission = relation('Permission') repository = relation('Repository') + +class UserToPerm(Base): + __tablename__ = 'user_to_perm' + __table_args__ = {'useexisting':True} + user_to_perm_id = Column("user_to_perm_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True) + user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None) + permission_id = Column("permission_id", INTEGER(), ForeignKey(u'permissions.permission_id'), nullable=False, unique=None, default=None) + + user = relation('User') + permission = relation('Permission') + + + + diff --git a/pylons_app/model/repo_model.py b/pylons_app/model/repo_model.py --- a/pylons_app/model/repo_model.py +++ b/pylons_app/model/repo_model.py @@ -24,7 +24,7 @@ model for handling repositories actions from datetime import datetime from pylons import app_globals as g from pylons_app.lib.utils import check_repo -from pylons_app.model.db import Repository, Repo2Perm, User, Permission +from pylons_app.model.db import Repository, RepoToPerm, User, Permission from pylons_app.model.meta import Session import logging import os @@ -55,10 +55,10 @@ class RepoModel(object): #update permissions for username, perm in form_data['perms_updates']: - r2p = self.sa.query(Repo2Perm)\ - .filter(Repo2Perm.user == self.sa.query(User)\ + r2p = self.sa.query(RepoToPerm)\ + .filter(RepoToPerm.user == self.sa.query(User)\ .filter(User.username == username).one())\ - .filter(Repo2Perm.repository == self.get(repo_name))\ + .filter(RepoToPerm.repository == self.get(repo_name))\ .one() r2p.permission_id = self.sa.query(Permission).filter( @@ -68,7 +68,7 @@ class RepoModel(object): #set new permissions for username, perm in form_data['perms_new']: - r2p = Repo2Perm() + r2p = RepoToPerm() r2p.repository = self.get(repo_name) r2p.user = self.sa.query(User)\ .filter(User.username == username).one() @@ -110,18 +110,18 @@ class RepoModel(object): self.sa.add(new_repo) #create default permission - repo2perm = Repo2Perm() + repo_to_perm = RepoToPerm() default_perm = 'repository.none' if form_data['private'] \ else 'repository.read' - repo2perm.permission_id = self.sa.query(Permission)\ + repo_to_perm.permission_id = self.sa.query(Permission)\ .filter(Permission.permission_name == default_perm)\ .one().permission_id - repo2perm.repository_id = new_repo.repo_id - repo2perm.user_id = self.sa.query(User)\ + repo_to_perm.repository_id = new_repo.repo_id + repo_to_perm.user_id = self.sa.query(User)\ .filter(User.username == 'default').one().user_id - self.sa.add(repo2perm) + self.sa.add(repo_to_perm) self.sa.commit() if not just_db: self.__create_repo(repo_name) @@ -142,9 +142,9 @@ class RepoModel(object): def delete_perm_user(self, form_data, repo_name): try: - self.sa.query(Repo2Perm)\ - .filter(Repo2Perm.repository == self.get(repo_name))\ - .filter(Repo2Perm.user_id == form_data['user_id']).delete() + self.sa.query(RepoToPerm)\ + .filter(RepoToPerm.repository == self.get(repo_name))\ + .filter(RepoToPerm.user_id == form_data['user_id']).delete() self.sa.commit() except: log.error(traceback.format_exc()) diff --git a/pylons_app/templates/admin/repos/repo_edit.html b/pylons_app/templates/admin/repos/repo_edit.html --- a/pylons_app/templates/admin/repos/repo_edit.html +++ b/pylons_app/templates/admin/repos/repo_edit.html @@ -81,7 +81,7 @@ - %for r2p in c.repo_info.repo2perm: + %for r2p in c.repo_info.repo_to_perm: %if r2p.user.username =='default' and c.repo_info.private: diff --git a/pylons_app/templates/settings/repo_settings.html b/pylons_app/templates/settings/repo_settings.html --- a/pylons_app/templates/settings/repo_settings.html +++ b/pylons_app/templates/settings/repo_settings.html @@ -66,7 +66,7 @@ - %for r2p in c.repo_info.repo2perm: + %for r2p in c.repo_info.repo_to_perm: %if r2p.user.username =='default' and c.repo_info.private: