Show More
@@ -222,7 +222,7 b' class ReposController(BaseController):' | |||||
222 |
|
222 | |||
223 | c.users_array = repo_model.get_users_js() |
|
223 | c.users_array = repo_model.get_users_js() | |
224 |
|
224 | |||
225 |
for p in c.repo_info.repo |
|
225 | for p in c.repo_info.repo_to_perm: | |
226 | defaults.update({'perm_%s' % p.user.username: |
|
226 | defaults.update({'perm_%s' % p.user.username: | |
227 | p.permission.permission_name}) |
|
227 | p.permission.permission_name}) | |
228 |
|
228 |
@@ -60,7 +60,7 b' class SettingsController(BaseController)' | |||||
60 | defaults.update({'user':c.repo_info.user.username}) |
|
60 | defaults.update({'user':c.repo_info.user.username}) | |
61 | c.users_array = repo_model.get_users_js() |
|
61 | c.users_array = repo_model.get_users_js() | |
62 |
|
62 | |||
63 |
for p in c.repo_info.repo |
|
63 | for p in c.repo_info.repo_to_perm: | |
64 | defaults.update({'perm_%s' % p.user.username: |
|
64 | defaults.update({'perm_%s' % p.user.username: | |
65 | p.permission.permission_name}) |
|
65 | p.permission.permission_name}) | |
66 |
|
66 |
@@ -27,7 +27,7 b' from pylons import config, session, url,' | |||||
27 | from pylons.controllers.util import abort, redirect |
|
27 | from pylons.controllers.util import abort, redirect | |
28 | from pylons_app.lib.utils import get_repo_slug |
|
28 | from pylons_app.lib.utils import get_repo_slug | |
29 | from pylons_app.model import meta |
|
29 | from pylons_app.model import meta | |
30 |
from pylons_app.model.db import User, Repo |
|
30 | from pylons_app.model.db import User, RepoToPerm, Repository, Permission | |
31 | from sqlalchemy.exc import OperationalError |
|
31 | from sqlalchemy.exc import OperationalError | |
32 | from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound |
|
32 | from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound | |
33 | import crypt |
|
33 | import crypt | |
@@ -134,10 +134,10 b' def fill_perms(user):' | |||||
134 | user.permissions['global'] = set() |
|
134 | user.permissions['global'] = set() | |
135 |
|
135 | |||
136 | #first fetch default permissions |
|
136 | #first fetch default permissions | |
137 |
default_perms = sa.query(Repo |
|
137 | default_perms = sa.query(RepoToPerm, Repository, Permission)\ | |
138 |
.join((Repository, Repo |
|
138 | .join((Repository, RepoToPerm.repository_id == Repository.repo_id))\ | |
139 |
.join((Permission, Repo |
|
139 | .join((Permission, RepoToPerm.permission_id == Permission.permission_id))\ | |
140 |
.filter(Repo |
|
140 | .filter(RepoToPerm.user_id == sa.query(User).filter(User.username == | |
141 | 'default').one().user_id).all() |
|
141 | 'default').one().user_id).all() | |
142 |
|
142 | |||
143 | if user.is_admin: |
|
143 | if user.is_admin: | |
@@ -145,7 +145,7 b' def fill_perms(user):' | |||||
145 | #admin have all rights set to admin |
|
145 | #admin have all rights set to admin | |
146 | for perm in default_perms: |
|
146 | for perm in default_perms: | |
147 | p = 'repository.admin' |
|
147 | p = 'repository.admin' | |
148 |
user.permissions['repositories'][perm.Repo |
|
148 | user.permissions['repositories'][perm.RepoToPerm.repository.repo_name] = p | |
149 |
|
149 | |||
150 | else: |
|
150 | else: | |
151 | user.permissions['global'].add('repository.create') |
|
151 | user.permissions['global'].add('repository.create') | |
@@ -159,13 +159,13 b' def fill_perms(user):' | |||||
159 | else: |
|
159 | else: | |
160 | p = perm.Permission.permission_name |
|
160 | p = perm.Permission.permission_name | |
161 |
|
161 | |||
162 |
user.permissions['repositories'][perm.Repo |
|
162 | user.permissions['repositories'][perm.RepoToPerm.repository.repo_name] = p | |
163 |
|
163 | |||
164 |
|
164 | |||
165 |
user_perms = sa.query(Repo |
|
165 | user_perms = sa.query(RepoToPerm, Permission, Repository)\ | |
166 |
.join((Repository, Repo |
|
166 | .join((Repository, RepoToPerm.repository_id == Repository.repo_id))\ | |
167 |
.join((Permission, Repo |
|
167 | .join((Permission, RepoToPerm.permission_id == Permission.permission_id))\ | |
168 |
.filter(Repo |
|
168 | .filter(RepoToPerm.user_id == user.user_id).all() | |
169 | #overwrite userpermissions with defaults |
|
169 | #overwrite userpermissions with defaults | |
170 | for perm in user_perms: |
|
170 | for perm in user_perms: | |
171 | #set write if owner |
|
171 | #set write if owner | |
@@ -173,7 +173,7 b' def fill_perms(user):' | |||||
173 | p = 'repository.write' |
|
173 | p = 'repository.write' | |
174 | else: |
|
174 | else: | |
175 | p = perm.Permission.permission_name |
|
175 | p = perm.Permission.permission_name | |
176 |
user.permissions['repositories'][perm.Repo |
|
176 | user.permissions['repositories'][perm.RepoToPerm.repository.repo_name] = p | |
177 | meta.Session.remove() |
|
177 | meta.Session.remove() | |
178 | return user |
|
178 | return user | |
179 |
|
179 |
@@ -64,7 +64,7 b' class Repository(Base):' | |||||
64 | description = Column("description", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
64 | description = Column("description", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
65 |
|
65 | |||
66 | user = relation('User') |
|
66 | user = relation('User') | |
67 |
repo |
|
67 | repo_to_perm = relation('RepoToPerm', cascade='all') | |
68 |
|
68 | |||
69 | class Permission(Base): |
|
69 | class Permission(Base): | |
70 | __tablename__ = 'permissions' |
|
70 | __tablename__ = 'permissions' | |
@@ -76,10 +76,10 b' class Permission(Base):' | |||||
76 | def __repr__(self): |
|
76 | def __repr__(self): | |
77 | return "<Permission('%s:%s')>" % (self.permission_id, self.permission_name) |
|
77 | return "<Permission('%s:%s')>" % (self.permission_id, self.permission_name) | |
78 |
|
78 | |||
79 |
class Repo |
|
79 | class RepoToPerm(Base): | |
80 | __tablename__ = 'repo_to_perm' |
|
80 | __tablename__ = 'repo_to_perm' | |
81 | __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True}) |
|
81 | __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True}) | |
82 |
repo |
|
82 | repo_to_perm_id = Column("repo_to_perm_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True) | |
83 | user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None) |
|
83 | user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None) | |
84 | permission_id = Column("permission_id", INTEGER(), ForeignKey(u'permissions.permission_id'), nullable=False, unique=None, default=None) |
|
84 | permission_id = Column("permission_id", INTEGER(), ForeignKey(u'permissions.permission_id'), nullable=False, unique=None, default=None) | |
85 | repository_id = Column("repository_id", INTEGER(), ForeignKey(u'repositories.repo_id'), nullable=False, unique=None, default=None) |
|
85 | repository_id = Column("repository_id", INTEGER(), ForeignKey(u'repositories.repo_id'), nullable=False, unique=None, default=None) | |
@@ -87,3 +87,17 b' class Repo2Perm(Base):' | |||||
87 | user = relation('User') |
|
87 | user = relation('User') | |
88 | permission = relation('Permission') |
|
88 | permission = relation('Permission') | |
89 | repository = relation('Repository') |
|
89 | repository = relation('Repository') | |
|
90 | ||||
|
91 | class UserToPerm(Base): | |||
|
92 | __tablename__ = 'user_to_perm' | |||
|
93 | __table_args__ = {'useexisting':True} | |||
|
94 | user_to_perm_id = Column("user_to_perm_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True) | |||
|
95 | user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None) | |||
|
96 | permission_id = Column("permission_id", INTEGER(), ForeignKey(u'permissions.permission_id'), nullable=False, unique=None, default=None) | |||
|
97 | ||||
|
98 | user = relation('User') | |||
|
99 | permission = relation('Permission') | |||
|
100 | ||||
|
101 | ||||
|
102 | ||||
|
103 |
@@ -24,7 +24,7 b' model for handling repositories actions' | |||||
24 | from datetime import datetime |
|
24 | from datetime import datetime | |
25 | from pylons import app_globals as g |
|
25 | from pylons import app_globals as g | |
26 | from pylons_app.lib.utils import check_repo |
|
26 | from pylons_app.lib.utils import check_repo | |
27 |
from pylons_app.model.db import Repository, Repo |
|
27 | from pylons_app.model.db import Repository, RepoToPerm, User, Permission | |
28 | from pylons_app.model.meta import Session |
|
28 | from pylons_app.model.meta import Session | |
29 | import logging |
|
29 | import logging | |
30 | import os |
|
30 | import os | |
@@ -55,10 +55,10 b' class RepoModel(object):' | |||||
55 |
|
55 | |||
56 | #update permissions |
|
56 | #update permissions | |
57 | for username, perm in form_data['perms_updates']: |
|
57 | for username, perm in form_data['perms_updates']: | |
58 |
r2p = self.sa.query(Repo |
|
58 | r2p = self.sa.query(RepoToPerm)\ | |
59 |
.filter(Repo |
|
59 | .filter(RepoToPerm.user == self.sa.query(User)\ | |
60 | .filter(User.username == username).one())\ |
|
60 | .filter(User.username == username).one())\ | |
61 |
.filter(Repo |
|
61 | .filter(RepoToPerm.repository == self.get(repo_name))\ | |
62 | .one() |
|
62 | .one() | |
63 |
|
63 | |||
64 | r2p.permission_id = self.sa.query(Permission).filter( |
|
64 | r2p.permission_id = self.sa.query(Permission).filter( | |
@@ -68,7 +68,7 b' class RepoModel(object):' | |||||
68 |
|
68 | |||
69 | #set new permissions |
|
69 | #set new permissions | |
70 | for username, perm in form_data['perms_new']: |
|
70 | for username, perm in form_data['perms_new']: | |
71 |
r2p = Repo |
|
71 | r2p = RepoToPerm() | |
72 | r2p.repository = self.get(repo_name) |
|
72 | r2p.repository = self.get(repo_name) | |
73 | r2p.user = self.sa.query(User)\ |
|
73 | r2p.user = self.sa.query(User)\ | |
74 | .filter(User.username == username).one() |
|
74 | .filter(User.username == username).one() | |
@@ -110,18 +110,18 b' class RepoModel(object):' | |||||
110 | self.sa.add(new_repo) |
|
110 | self.sa.add(new_repo) | |
111 |
|
111 | |||
112 | #create default permission |
|
112 | #create default permission | |
113 |
repo |
|
113 | repo_to_perm = RepoToPerm() | |
114 | default_perm = 'repository.none' if form_data['private'] \ |
|
114 | default_perm = 'repository.none' if form_data['private'] \ | |
115 | else 'repository.read' |
|
115 | else 'repository.read' | |
116 |
repo |
|
116 | repo_to_perm.permission_id = self.sa.query(Permission)\ | |
117 | .filter(Permission.permission_name == default_perm)\ |
|
117 | .filter(Permission.permission_name == default_perm)\ | |
118 | .one().permission_id |
|
118 | .one().permission_id | |
119 |
|
119 | |||
120 |
repo |
|
120 | repo_to_perm.repository_id = new_repo.repo_id | |
121 |
repo |
|
121 | repo_to_perm.user_id = self.sa.query(User)\ | |
122 | .filter(User.username == 'default').one().user_id |
|
122 | .filter(User.username == 'default').one().user_id | |
123 |
|
123 | |||
124 |
self.sa.add(repo |
|
124 | self.sa.add(repo_to_perm) | |
125 | self.sa.commit() |
|
125 | self.sa.commit() | |
126 | if not just_db: |
|
126 | if not just_db: | |
127 | self.__create_repo(repo_name) |
|
127 | self.__create_repo(repo_name) | |
@@ -142,9 +142,9 b' class RepoModel(object):' | |||||
142 |
|
142 | |||
143 | def delete_perm_user(self, form_data, repo_name): |
|
143 | def delete_perm_user(self, form_data, repo_name): | |
144 | try: |
|
144 | try: | |
145 |
self.sa.query(Repo |
|
145 | self.sa.query(RepoToPerm)\ | |
146 |
.filter(Repo |
|
146 | .filter(RepoToPerm.repository == self.get(repo_name))\ | |
147 |
.filter(Repo |
|
147 | .filter(RepoToPerm.user_id == form_data['user_id']).delete() | |
148 | self.sa.commit() |
|
148 | self.sa.commit() | |
149 | except: |
|
149 | except: | |
150 | log.error(traceback.format_exc()) |
|
150 | log.error(traceback.format_exc()) |
@@ -81,7 +81,7 b'' | |||||
81 | <td></td> |
|
81 | <td></td> | |
82 | </tr> |
|
82 | </tr> | |
83 |
|
83 | |||
84 |
%for r2p in c.repo_info.repo |
|
84 | %for r2p in c.repo_info.repo_to_perm: | |
85 | %if r2p.user.username =='default' and c.repo_info.private: |
|
85 | %if r2p.user.username =='default' and c.repo_info.private: | |
86 | <tr> |
|
86 | <tr> | |
87 | <td colspan="4"> |
|
87 | <td colspan="4"> |
@@ -66,7 +66,7 b'' | |||||
66 | <td></td> |
|
66 | <td></td> | |
67 | </tr> |
|
67 | </tr> | |
68 |
|
68 | |||
69 |
%for r2p in c.repo_info.repo |
|
69 | %for r2p in c.repo_info.repo_to_perm: | |
70 | %if r2p.user.username =='default' and c.repo_info.private: |
|
70 | %if r2p.user.username =='default' and c.repo_info.private: | |
71 | <tr> |
|
71 | <tr> | |
72 | <td colspan="4"> |
|
72 | <td colspan="4"> |
General Comments 0
You need to be logged in to leave comments.
Login now