Show More
@@ -33,16 +33,16 b' from pylons.controllers.util import abor' | |||
|
33 | 33 | from pylons.i18n.translation import _ |
|
34 | 34 | |
|
35 | 35 | from rhodecode.lib import helpers as h |
|
36 |
from rhodecode.lib.exceptions import User |
|
|
36 | from rhodecode.lib.exceptions import UserGroupsAssignedException | |
|
37 | 37 | from rhodecode.lib.utils2 import safe_unicode, str2bool |
|
38 | 38 | from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator |
|
39 | 39 | from rhodecode.lib.base import BaseController, render |
|
40 | 40 | |
|
41 |
from rhodecode.model.users_group import User |
|
|
41 | from rhodecode.model.users_group import UserGroupModel | |
|
42 | 42 | |
|
43 |
from rhodecode.model.db import User, User |
|
|
44 |
User |
|
|
45 |
from rhodecode.model.forms import User |
|
|
43 | from rhodecode.model.db import User, UserGroup, UserGroupToPerm,\ | |
|
44 | UserGroupRepoToPerm, UserGroupRepoGroupToPerm | |
|
45 | from rhodecode.model.forms import UserGroupForm | |
|
46 | 46 | from rhodecode.model.meta import Session |
|
47 | 47 | from rhodecode.lib.utils import action_logger |
|
48 | 48 | from sqlalchemy.orm import joinedload |
@@ -67,17 +67,17 b' class UsersGroupsController(BaseControll' | |||
|
67 | 67 | def index(self, format='html'): |
|
68 | 68 | """GET /users_groups: All items in the collection""" |
|
69 | 69 | # url('users_groups') |
|
70 |
c.users_groups_list = User |
|
|
70 | c.users_groups_list = UserGroup().query().all() | |
|
71 | 71 | return render('admin/users_groups/users_groups.html') |
|
72 | 72 | |
|
73 | 73 | def create(self): |
|
74 | 74 | """POST /users_groups: Create a new item""" |
|
75 | 75 | # url('users_groups') |
|
76 | 76 | |
|
77 |
users_group_form = User |
|
|
77 | users_group_form = UserGroupForm()() | |
|
78 | 78 | try: |
|
79 | 79 | form_result = users_group_form.to_python(dict(request.POST)) |
|
80 |
User |
|
|
80 | UserGroupModel().create(name=form_result['users_group_name'], | |
|
81 | 81 | active=form_result['users_group_active']) |
|
82 | 82 | gr = form_result['users_group_name'] |
|
83 | 83 | action_logger(self.rhodecode_user, |
@@ -110,20 +110,20 b' class UsersGroupsController(BaseControll' | |||
|
110 | 110 | 'repositories_groups': {} |
|
111 | 111 | } |
|
112 | 112 | |
|
113 |
ugroup_repo_perms = User |
|
|
114 |
.options(joinedload(User |
|
|
115 |
.options(joinedload(User |
|
|
116 |
.filter(User |
|
|
113 | ugroup_repo_perms = UserGroupRepoToPerm.query()\ | |
|
114 | .options(joinedload(UserGroupRepoToPerm.permission))\ | |
|
115 | .options(joinedload(UserGroupRepoToPerm.repository))\ | |
|
116 | .filter(UserGroupRepoToPerm.users_group_id == id)\ | |
|
117 | 117 | .all() |
|
118 | 118 | |
|
119 | 119 | for gr in ugroup_repo_perms: |
|
120 | 120 | c.users_group.permissions['repositories'][gr.repository.repo_name] \ |
|
121 | 121 | = gr.permission.permission_name |
|
122 | 122 | |
|
123 |
ugroup_group_perms = User |
|
|
124 |
.options(joinedload(User |
|
|
125 |
.options(joinedload(User |
|
|
126 |
.filter(User |
|
|
123 | ugroup_group_perms = UserGroupRepoGroupToPerm.query()\ | |
|
124 | .options(joinedload(UserGroupRepoGroupToPerm.permission))\ | |
|
125 | .options(joinedload(UserGroupRepoGroupToPerm.group))\ | |
|
126 | .filter(UserGroupRepoGroupToPerm.users_group_id == id)\ | |
|
127 | 127 | .all() |
|
128 | 128 | |
|
129 | 129 | for gr in ugroup_group_perms: |
@@ -145,18 +145,18 b' class UsersGroupsController(BaseControll' | |||
|
145 | 145 | # method='put') |
|
146 | 146 | # url('users_group', id=ID) |
|
147 | 147 | |
|
148 |
c.users_group = User |
|
|
148 | c.users_group = UserGroup.get_or_404(id) | |
|
149 | 149 | self._load_data(id) |
|
150 | 150 | |
|
151 | 151 | available_members = [safe_unicode(x[0]) for x in c.available_members] |
|
152 | 152 | |
|
153 |
users_group_form = User |
|
|
153 | users_group_form = UserGroupForm(edit=True, | |
|
154 | 154 | old_data=c.users_group.get_dict(), |
|
155 | 155 | available_members=available_members)() |
|
156 | 156 | |
|
157 | 157 | try: |
|
158 | 158 | form_result = users_group_form.to_python(request.POST) |
|
159 |
User |
|
|
159 | UserGroupModel().update(c.users_group, form_result) | |
|
160 | 160 | gr = form_result['users_group_name'] |
|
161 | 161 | action_logger(self.rhodecode_user, |
|
162 | 162 | 'admin_updated_users_group:%s' % gr, |
@@ -164,7 +164,7 b' class UsersGroupsController(BaseControll' | |||
|
164 | 164 | h.flash(_('updated user group %s') % gr, category='success') |
|
165 | 165 | Session().commit() |
|
166 | 166 | except formencode.Invalid, errors: |
|
167 |
ug_model = User |
|
|
167 | ug_model = UserGroupModel() | |
|
168 | 168 | defaults = errors.value |
|
169 | 169 | e = errors.error_dict or {} |
|
170 | 170 | defaults.update({ |
@@ -196,12 +196,12 b' class UsersGroupsController(BaseControll' | |||
|
196 | 196 | # h.form(url('users_group', id=ID), |
|
197 | 197 | # method='delete') |
|
198 | 198 | # url('users_group', id=ID) |
|
199 |
usr_gr = User |
|
|
199 | usr_gr = UserGroup.get_or_404(id) | |
|
200 | 200 | try: |
|
201 |
User |
|
|
201 | UserGroupModel().delete(usr_gr) | |
|
202 | 202 | Session().commit() |
|
203 | 203 | h.flash(_('successfully deleted user group'), category='success') |
|
204 |
except User |
|
|
204 | except UserGroupsAssignedException, e: | |
|
205 | 205 | h.flash(e, category='error') |
|
206 | 206 | except Exception: |
|
207 | 207 | log.error(traceback.format_exc()) |
@@ -217,10 +217,10 b' class UsersGroupsController(BaseControll' | |||
|
217 | 217 | """GET /users_groups/id/edit: Form to edit an existing item""" |
|
218 | 218 | # url('edit_users_group', id=ID) |
|
219 | 219 | |
|
220 |
c.users_group = User |
|
|
220 | c.users_group = UserGroup.get_or_404(id) | |
|
221 | 221 | self._load_data(id) |
|
222 | 222 | |
|
223 |
ug_model = User |
|
|
223 | ug_model = UserGroupModel() | |
|
224 | 224 | defaults = c.users_group.get_dict() |
|
225 | 225 | defaults.update({ |
|
226 | 226 | 'create_repo_perm': ug_model.has_perm(c.users_group, |
@@ -240,36 +240,36 b' class UsersGroupsController(BaseControll' | |||
|
240 | 240 | """PUT /users_perm/id: Update an existing item""" |
|
241 | 241 | # url('users_group_perm', id=ID, method='put') |
|
242 | 242 | |
|
243 |
users_group = User |
|
|
243 | users_group = UserGroup.get_or_404(id) | |
|
244 | 244 | grant_create_perm = str2bool(request.POST.get('create_repo_perm')) |
|
245 | 245 | grant_fork_perm = str2bool(request.POST.get('fork_repo_perm')) |
|
246 | 246 | inherit_perms = str2bool(request.POST.get('inherit_default_permissions')) |
|
247 | 247 | |
|
248 |
user |
|
|
248 | usergroup_model = UserGroupModel() | |
|
249 | 249 | |
|
250 | 250 | try: |
|
251 | 251 | users_group.inherit_default_permissions = inherit_perms |
|
252 | 252 | Session().add(users_group) |
|
253 | 253 | |
|
254 | 254 | if grant_create_perm: |
|
255 |
user |
|
|
256 |
user |
|
|
255 | usergroup_model.revoke_perm(id, 'hg.create.none') | |
|
256 | usergroup_model.grant_perm(id, 'hg.create.repository') | |
|
257 | 257 | h.flash(_("Granted 'repository create' permission to user group"), |
|
258 | 258 | category='success') |
|
259 | 259 | else: |
|
260 |
user |
|
|
261 |
user |
|
|
260 | usergroup_model.revoke_perm(id, 'hg.create.repository') | |
|
261 | usergroup_model.grant_perm(id, 'hg.create.none') | |
|
262 | 262 | h.flash(_("Revoked 'repository create' permission to user group"), |
|
263 | 263 | category='success') |
|
264 | 264 | |
|
265 | 265 | if grant_fork_perm: |
|
266 |
user |
|
|
267 |
user |
|
|
266 | usergroup_model.revoke_perm(id, 'hg.fork.none') | |
|
267 | usergroup_model.grant_perm(id, 'hg.fork.repository') | |
|
268 | 268 | h.flash(_("Granted 'repository fork' permission to user group"), |
|
269 | 269 | category='success') |
|
270 | 270 | else: |
|
271 |
user |
|
|
272 |
user |
|
|
271 | usergroup_model.revoke_perm(id, 'hg.fork.repository') | |
|
272 | usergroup_model.grant_perm(id, 'hg.fork.none') | |
|
273 | 273 | h.flash(_("Revoked 'repository fork' permission to user group"), |
|
274 | 274 | category='success') |
|
275 | 275 |
@@ -38,7 +38,7 b' from rhodecode.model.meta import Session' | |||
|
38 | 38 | from rhodecode.model.scm import ScmModel |
|
39 | 39 | from rhodecode.model.repo import RepoModel |
|
40 | 40 | from rhodecode.model.user import UserModel |
|
41 |
from rhodecode.model.users_group import User |
|
|
41 | from rhodecode.model.users_group import UserGroupModel | |
|
42 | 42 | from rhodecode.model.permission import PermissionModel |
|
43 | 43 | from rhodecode.model.db import Repository, RhodeCodeSetting, UserIpMap |
|
44 | 44 | |
@@ -125,7 +125,7 b' def get_users_group_or_error(usersgroupi' | |||
|
125 | 125 | |
|
126 | 126 | :param userid: |
|
127 | 127 | """ |
|
128 |
users_group = User |
|
|
128 | users_group = UserGroupModel().get_group(usersgroupid) | |
|
129 | 129 | if users_group is None: |
|
130 | 130 | raise JSONRPCError('user group `%s` does not exist' % usersgroupid) |
|
131 | 131 | return users_group |
@@ -474,7 +474,7 b' class ApiController(JSONRPCController):' | |||
|
474 | 474 | """ |
|
475 | 475 | |
|
476 | 476 | result = [] |
|
477 |
for users_group in User |
|
|
477 | for users_group in UserGroupModel().get_all(): | |
|
478 | 478 | result.append(users_group.get_api_data()) |
|
479 | 479 | return result |
|
480 | 480 | |
@@ -488,12 +488,12 b' class ApiController(JSONRPCController):' | |||
|
488 | 488 | :param active: |
|
489 | 489 | """ |
|
490 | 490 | |
|
491 |
if User |
|
|
491 | if UserGroupModel().get_by_name(group_name): | |
|
492 | 492 | raise JSONRPCError("user group `%s` already exist" % group_name) |
|
493 | 493 | |
|
494 | 494 | try: |
|
495 | 495 | active = Optional.extract(active) |
|
496 |
ug = User |
|
|
496 | ug = UserGroupModel().create(name=group_name, active=active) | |
|
497 | 497 | Session().commit() |
|
498 | 498 | return dict( |
|
499 | 499 | msg='created new user group `%s`' % group_name, |
@@ -516,7 +516,7 b' class ApiController(JSONRPCController):' | |||
|
516 | 516 | users_group = get_users_group_or_error(usersgroupid) |
|
517 | 517 | |
|
518 | 518 | try: |
|
519 |
ugm = User |
|
|
519 | ugm = UserGroupModel().add_user_to_group(users_group, user) | |
|
520 | 520 | success = True if ugm != True else False |
|
521 | 521 | msg = 'added member `%s` to user group `%s`' % ( |
|
522 | 522 | user.username, users_group.users_group_name |
@@ -549,7 +549,7 b' class ApiController(JSONRPCController):' | |||
|
549 | 549 | users_group = get_users_group_or_error(usersgroupid) |
|
550 | 550 | |
|
551 | 551 | try: |
|
552 |
success = User |
|
|
552 | success = UserGroupModel().remove_user_from_group(users_group, | |
|
553 | 553 | user) |
|
554 | 554 | msg = 'removed member `%s` from user group `%s`' % ( |
|
555 | 555 | user.username, users_group.users_group_name |
@@ -41,7 +41,7 b' from rhodecode.lib.vcs.utils.lazy import' | |||
|
41 | 41 | |
|
42 | 42 | from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \ |
|
43 | 43 | generate_api_key, safe_unicode |
|
44 |
from rhodecode.lib.exceptions import User |
|
|
44 | from rhodecode.lib.exceptions import UserGroupsAssignedException | |
|
45 | 45 | from rhodecode.lib.compat import json |
|
46 | 46 | |
|
47 | 47 | from rhodecode.model.meta import Base, Session |
@@ -282,7 +282,7 b' class User(Base, BaseModel):' | |||
|
282 | 282 | user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all') |
|
283 | 283 | repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all') |
|
284 | 284 | |
|
285 |
group_member = relationship('User |
|
|
285 | group_member = relationship('UserGroupMember', cascade='all') | |
|
286 | 286 | |
|
287 | 287 | @property |
|
288 | 288 | def full_contact(self): |
@@ -361,7 +361,7 b' class UserLog(Base, BaseModel):' | |||
|
361 | 361 | repository = relationship('Repository') |
|
362 | 362 | |
|
363 | 363 | |
|
364 |
class User |
|
|
364 | class UserGroup(Base, BaseModel): | |
|
365 | 365 | __tablename__ = 'users_groups' |
|
366 | 366 | __table_args__ = {'extend_existing':True} |
|
367 | 367 | |
@@ -369,7 +369,7 b' class UsersGroup(Base, BaseModel):' | |||
|
369 | 369 | users_group_name = Column("users_group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
|
370 | 370 | users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None) |
|
371 | 371 | |
|
372 |
members = relationship('User |
|
|
372 | members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined") | |
|
373 | 373 | |
|
374 | 374 | def __repr__(self): |
|
375 | 375 | return '<userGroup(%s)>' % (self.users_group_name) |
@@ -425,7 +425,7 b' class UsersGroup(Base, BaseModel):' | |||
|
425 | 425 | if v: |
|
426 | 426 | v = [v] if isinstance(v, basestring) else v |
|
427 | 427 | for u_id in set(v): |
|
428 |
member = User |
|
|
428 | member = UserGroupMember(users_group_id, u_id) | |
|
429 | 429 | members_list.append(member) |
|
430 | 430 | setattr(users_group, 'members', members_list) |
|
431 | 431 | setattr(users_group, k, v) |
@@ -442,12 +442,12 b' class UsersGroup(Base, BaseModel):' | |||
|
442 | 442 | try: |
|
443 | 443 | |
|
444 | 444 | # check if this group is not assigned to repo |
|
445 |
assigned_groups = User |
|
|
446 |
.filter(User |
|
|
445 | assigned_groups = UserGroupRepoToPerm.query()\ | |
|
446 | .filter(UserGroupRepoToPerm.users_group_id == | |
|
447 | 447 | users_group_id).all() |
|
448 | 448 | |
|
449 | 449 | if assigned_groups: |
|
450 |
raise User |
|
|
450 | raise UserGroupsAssignedException('RepoGroup assigned to %s' % | |
|
451 | 451 | assigned_groups) |
|
452 | 452 | |
|
453 | 453 | users_group = cls.get(users_group_id, cache=False) |
@@ -458,7 +458,7 b' class UsersGroup(Base, BaseModel):' | |||
|
458 | 458 | Session.rollback() |
|
459 | 459 | raise |
|
460 | 460 | |
|
461 |
class User |
|
|
461 | class UserGroupMember(Base, BaseModel): | |
|
462 | 462 | __tablename__ = 'users_groups_members' |
|
463 | 463 | __table_args__ = {'extend_existing':True} |
|
464 | 464 | |
@@ -467,7 +467,7 b' class UsersGroupMember(Base, BaseModel):' | |||
|
467 | 467 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
|
468 | 468 | |
|
469 | 469 | user = relationship('User', lazy='joined') |
|
470 |
users_group = relationship('User |
|
|
470 | users_group = relationship('UserGroup') | |
|
471 | 471 | |
|
472 | 472 | def __init__(self, gr_id='', u_id=''): |
|
473 | 473 | self.users_group_id = gr_id |
@@ -475,7 +475,7 b' class UsersGroupMember(Base, BaseModel):' | |||
|
475 | 475 | |
|
476 | 476 | @staticmethod |
|
477 | 477 | def add_user_to_group(group, user): |
|
478 |
ugm = User |
|
|
478 | ugm = UserGroupMember() | |
|
479 | 479 | ugm.users_group = group |
|
480 | 480 | ugm.user = user |
|
481 | 481 | Session.add(ugm) |
@@ -505,7 +505,7 b' class Repository(Base, BaseModel):' | |||
|
505 | 505 | fork = relationship('Repository', remote_side=repo_id) |
|
506 | 506 | group = relationship('RepoGroup') |
|
507 | 507 | repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id') |
|
508 |
users_group_to_perm = relationship('User |
|
|
508 | users_group_to_perm = relationship('UserGroupRepoToPerm', cascade='all') | |
|
509 | 509 | stats = relationship('Statistics', cascade='all', uselist=False) |
|
510 | 510 | |
|
511 | 511 | followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all') |
@@ -909,7 +909,7 b' class UserToPerm(Base, BaseModel):' | |||
|
909 | 909 | except: |
|
910 | 910 | Session.rollback() |
|
911 | 911 | |
|
912 |
class User |
|
|
912 | class UserGroupRepoToPerm(Base, BaseModel): | |
|
913 | 913 | __tablename__ = 'users_group_repo_to_perm' |
|
914 | 914 | __table_args__ = (UniqueConstraint('repository_id', 'users_group_id', 'permission_id'), {'extend_existing':True}) |
|
915 | 915 | users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
@@ -917,21 +917,21 b' class UsersGroupRepoToPerm(Base, BaseMod' | |||
|
917 | 917 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
918 | 918 | repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) |
|
919 | 919 | |
|
920 |
users_group = relationship('User |
|
|
920 | users_group = relationship('UserGroup') | |
|
921 | 921 | permission = relationship('Permission') |
|
922 | 922 | repository = relationship('Repository') |
|
923 | 923 | |
|
924 | 924 | def __repr__(self): |
|
925 | 925 | return '<userGroup:%s => %s >' % (self.users_group, self.repository) |
|
926 | 926 | |
|
927 |
class User |
|
|
927 | class UserGroupToPerm(Base, BaseModel): | |
|
928 | 928 | __tablename__ = 'users_group_to_perm' |
|
929 | 929 | __table_args__ = {'extend_existing':True} |
|
930 | 930 | users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
931 | 931 | users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
|
932 | 932 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
933 | 933 | |
|
934 |
users_group = relationship('User |
|
|
934 | users_group = relationship('UserGroup') | |
|
935 | 935 | permission = relationship('Permission') |
|
936 | 936 | |
|
937 | 937 |
@@ -305,7 +305,7 b' class User(Base, BaseModel):' | |||
|
305 | 305 | repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all') |
|
306 | 306 | repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all') |
|
307 | 307 | |
|
308 |
group_member = relationship('User |
|
|
308 | group_member = relationship('UserGroupMember', cascade='all') | |
|
309 | 309 | |
|
310 | 310 | notifications = relationship('UserNotification', cascade='all') |
|
311 | 311 | # notifications assigned to this user |
@@ -423,7 +423,7 b' class UserLog(Base, BaseModel):' | |||
|
423 | 423 | repository = relationship('Repository', cascade='') |
|
424 | 424 | |
|
425 | 425 | |
|
426 |
class User |
|
|
426 | class UserGroup(Base, BaseModel): | |
|
427 | 427 | __tablename__ = 'users_groups' |
|
428 | 428 | __table_args__ = ( |
|
429 | 429 | {'extend_existing': True, 'mysql_engine':'InnoDB', |
@@ -434,9 +434,9 b' class UsersGroup(Base, BaseModel):' | |||
|
434 | 434 | users_group_name = Column("users_group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
|
435 | 435 | users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None) |
|
436 | 436 | |
|
437 |
members = relationship('User |
|
|
438 |
users_group_to_perm = relationship('User |
|
|
439 |
users_group_repo_to_perm = relationship('User |
|
|
437 | members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined") | |
|
438 | users_group_to_perm = relationship('UserGroupToPerm', cascade='all') | |
|
439 | users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all') | |
|
440 | 440 | |
|
441 | 441 | def __unicode__(self): |
|
442 | 442 | return u'<userGroup(%s)>' % (self.users_group_name) |
@@ -465,7 +465,7 b' class UsersGroup(Base, BaseModel):' | |||
|
465 | 465 | return users_group.get(users_group_id) |
|
466 | 466 | |
|
467 | 467 | |
|
468 |
class User |
|
|
468 | class UserGroupMember(Base, BaseModel): | |
|
469 | 469 | __tablename__ = 'users_groups_members' |
|
470 | 470 | __table_args__ = ( |
|
471 | 471 | {'extend_existing': True, 'mysql_engine':'InnoDB', |
@@ -477,7 +477,7 b' class UsersGroupMember(Base, BaseModel):' | |||
|
477 | 477 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
|
478 | 478 | |
|
479 | 479 | user = relationship('User', lazy='joined') |
|
480 |
users_group = relationship('User |
|
|
480 | users_group = relationship('UserGroup') | |
|
481 | 481 | |
|
482 | 482 | def __init__(self, gr_id='', u_id=''): |
|
483 | 483 | self.users_group_id = gr_id |
@@ -510,7 +510,7 b' class Repository(Base, BaseModel):' | |||
|
510 | 510 | fork = relationship('Repository', remote_side=repo_id) |
|
511 | 511 | group = relationship('RepoGroup') |
|
512 | 512 | repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id') |
|
513 |
users_group_to_perm = relationship('User |
|
|
513 | users_group_to_perm = relationship('UserGroupRepoToPerm', cascade='all') | |
|
514 | 514 | stats = relationship('Statistics', cascade='all', uselist=False) |
|
515 | 515 | |
|
516 | 516 | followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all') |
@@ -749,7 +749,7 b' class RepoGroup(Base, BaseModel):' | |||
|
749 | 749 | group_description = Column("group_description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
750 | 750 | |
|
751 | 751 | repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id') |
|
752 |
users_group_to_perm = relationship('User |
|
|
752 | users_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all') | |
|
753 | 753 | |
|
754 | 754 | parent_group = relationship('RepoGroup', remote_side=group_id) |
|
755 | 755 | |
@@ -946,7 +946,7 b' class UserToPerm(Base, BaseModel):' | |||
|
946 | 946 | permission = relationship('Permission', lazy='joined') |
|
947 | 947 | |
|
948 | 948 | |
|
949 |
class User |
|
|
949 | class UserGroupRepoToPerm(Base, BaseModel): | |
|
950 | 950 | __tablename__ = 'users_group_repo_to_perm' |
|
951 | 951 | __table_args__ = ( |
|
952 | 952 | UniqueConstraint('repository_id', 'users_group_id', 'permission_id'), |
@@ -958,7 +958,7 b' class UsersGroupRepoToPerm(Base, BaseMod' | |||
|
958 | 958 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
959 | 959 | repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) |
|
960 | 960 | |
|
961 |
users_group = relationship('User |
|
|
961 | users_group = relationship('UserGroup') | |
|
962 | 962 | permission = relationship('Permission') |
|
963 | 963 | repository = relationship('Repository') |
|
964 | 964 | |
@@ -975,7 +975,7 b' class UsersGroupRepoToPerm(Base, BaseMod' | |||
|
975 | 975 | return u'<userGroup:%s => %s >' % (self.users_group, self.repository) |
|
976 | 976 | |
|
977 | 977 | |
|
978 |
class User |
|
|
978 | class UserGroupToPerm(Base, BaseModel): | |
|
979 | 979 | __tablename__ = 'users_group_to_perm' |
|
980 | 980 | __table_args__ = ( |
|
981 | 981 | UniqueConstraint('users_group_id', 'permission_id',), |
@@ -986,7 +986,7 b' class UsersGroupToPerm(Base, BaseModel):' | |||
|
986 | 986 | users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
|
987 | 987 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
988 | 988 | |
|
989 |
users_group = relationship('User |
|
|
989 | users_group = relationship('UserGroup') | |
|
990 | 990 | permission = relationship('Permission') |
|
991 | 991 | |
|
992 | 992 | |
@@ -1008,7 +1008,7 b' class UserRepoGroupToPerm(Base, BaseMode' | |||
|
1008 | 1008 | permission = relationship('Permission') |
|
1009 | 1009 | |
|
1010 | 1010 | |
|
1011 |
class User |
|
|
1011 | class UserGroupRepoGroupToPerm(Base, BaseModel): | |
|
1012 | 1012 | __tablename__ = 'users_group_repo_group_to_perm' |
|
1013 | 1013 | __table_args__ = ( |
|
1014 | 1014 | UniqueConstraint('users_group_id', 'group_id'), |
@@ -1021,7 +1021,7 b' class UsersGroupRepoGroupToPerm(Base, Ba' | |||
|
1021 | 1021 | group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None) |
|
1022 | 1022 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
1023 | 1023 | |
|
1024 |
users_group = relationship('User |
|
|
1024 | users_group = relationship('UserGroup') | |
|
1025 | 1025 | permission = relationship('Permission') |
|
1026 | 1026 | group = relationship('RepoGroup') |
|
1027 | 1027 |
@@ -322,7 +322,7 b' class User(Base, BaseModel):' | |||
|
322 | 322 | repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all') |
|
323 | 323 | repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all') |
|
324 | 324 | |
|
325 |
group_member = relationship('User |
|
|
325 | group_member = relationship('UserGroupMember', cascade='all') | |
|
326 | 326 | |
|
327 | 327 | notifications = relationship('UserNotification', cascade='all') |
|
328 | 328 | # notifications assigned to this user |
@@ -521,7 +521,7 b' class UserLog(Base, BaseModel):' | |||
|
521 | 521 | repository = relationship('Repository', cascade='') |
|
522 | 522 | |
|
523 | 523 | |
|
524 |
class User |
|
|
524 | class UserGroup(Base, BaseModel): | |
|
525 | 525 | __tablename__ = 'users_groups' |
|
526 | 526 | __table_args__ = ( |
|
527 | 527 | {'extend_existing': True, 'mysql_engine': 'InnoDB', |
@@ -533,9 +533,9 b' class UsersGroup(Base, BaseModel):' | |||
|
533 | 533 | users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None) |
|
534 | 534 | inherit_default_permissions = Column("users_group_inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True) |
|
535 | 535 | |
|
536 |
members = relationship('User |
|
|
537 |
users_group_to_perm = relationship('User |
|
|
538 |
users_group_repo_to_perm = relationship('User |
|
|
536 | members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined") | |
|
537 | users_group_to_perm = relationship('UserGroupToPerm', cascade='all') | |
|
538 | users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all') | |
|
539 | 539 | |
|
540 | 540 | def __unicode__(self): |
|
541 | 541 | return u'<userGroup(%s)>' % (self.users_group_name) |
@@ -575,7 +575,7 b' class UsersGroup(Base, BaseModel):' | |||
|
575 | 575 | return data |
|
576 | 576 | |
|
577 | 577 | |
|
578 |
class User |
|
|
578 | class UserGroupMember(Base, BaseModel): | |
|
579 | 579 | __tablename__ = 'users_groups_members' |
|
580 | 580 | __table_args__ = ( |
|
581 | 581 | {'extend_existing': True, 'mysql_engine': 'InnoDB', |
@@ -587,7 +587,7 b' class UsersGroupMember(Base, BaseModel):' | |||
|
587 | 587 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
|
588 | 588 | |
|
589 | 589 | user = relationship('User', lazy='joined') |
|
590 |
users_group = relationship('User |
|
|
590 | users_group = relationship('UserGroup') | |
|
591 | 591 | |
|
592 | 592 | def __init__(self, gr_id='', u_id=''): |
|
593 | 593 | self.users_group_id = gr_id |
@@ -625,7 +625,7 b' class Repository(Base, BaseModel):' | |||
|
625 | 625 | fork = relationship('Repository', remote_side=repo_id) |
|
626 | 626 | group = relationship('RepoGroup') |
|
627 | 627 | repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id') |
|
628 |
users_group_to_perm = relationship('User |
|
|
628 | users_group_to_perm = relationship('UserGroupRepoToPerm', cascade='all') | |
|
629 | 629 | stats = relationship('Statistics', cascade='all', uselist=False) |
|
630 | 630 | |
|
631 | 631 | followers = relationship('UserFollowing', |
@@ -1013,7 +1013,7 b' class RepoGroup(Base, BaseModel):' | |||
|
1013 | 1013 | enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False) |
|
1014 | 1014 | |
|
1015 | 1015 | repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id') |
|
1016 |
users_group_to_perm = relationship('User |
|
|
1016 | users_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all') | |
|
1017 | 1017 | |
|
1018 | 1018 | parent_group = relationship('RepoGroup', remote_side=group_id) |
|
1019 | 1019 | |
@@ -1277,7 +1277,7 b' class UserToPerm(Base, BaseModel):' | |||
|
1277 | 1277 | permission = relationship('Permission', lazy='joined') |
|
1278 | 1278 | |
|
1279 | 1279 | |
|
1280 |
class User |
|
|
1280 | class UserGroupRepoToPerm(Base, BaseModel): | |
|
1281 | 1281 | __tablename__ = 'users_group_repo_to_perm' |
|
1282 | 1282 | __table_args__ = ( |
|
1283 | 1283 | UniqueConstraint('repository_id', 'users_group_id', 'permission_id'), |
@@ -1289,7 +1289,7 b' class UsersGroupRepoToPerm(Base, BaseMod' | |||
|
1289 | 1289 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
1290 | 1290 | repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) |
|
1291 | 1291 | |
|
1292 |
users_group = relationship('User |
|
|
1292 | users_group = relationship('UserGroup') | |
|
1293 | 1293 | permission = relationship('Permission') |
|
1294 | 1294 | repository = relationship('Repository') |
|
1295 | 1295 | |
@@ -1306,7 +1306,7 b' class UsersGroupRepoToPerm(Base, BaseMod' | |||
|
1306 | 1306 | return u'<userGroup:%s => %s >' % (self.users_group, self.repository) |
|
1307 | 1307 | |
|
1308 | 1308 | |
|
1309 |
class User |
|
|
1309 | class UserGroupToPerm(Base, BaseModel): | |
|
1310 | 1310 | __tablename__ = 'users_group_to_perm' |
|
1311 | 1311 | __table_args__ = ( |
|
1312 | 1312 | UniqueConstraint('users_group_id', 'permission_id',), |
@@ -1317,7 +1317,7 b' class UsersGroupToPerm(Base, BaseModel):' | |||
|
1317 | 1317 | users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
|
1318 | 1318 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
1319 | 1319 | |
|
1320 |
users_group = relationship('User |
|
|
1320 | users_group = relationship('UserGroup') | |
|
1321 | 1321 | permission = relationship('Permission') |
|
1322 | 1322 | |
|
1323 | 1323 | |
@@ -1339,7 +1339,7 b' class UserRepoGroupToPerm(Base, BaseMode' | |||
|
1339 | 1339 | permission = relationship('Permission') |
|
1340 | 1340 | |
|
1341 | 1341 | |
|
1342 |
class User |
|
|
1342 | class UserGroupRepoGroupToPerm(Base, BaseModel): | |
|
1343 | 1343 | __tablename__ = 'users_group_repo_group_to_perm' |
|
1344 | 1344 | __table_args__ = ( |
|
1345 | 1345 | UniqueConstraint('users_group_id', 'group_id'), |
@@ -1352,7 +1352,7 b' class UsersGroupRepoGroupToPerm(Base, Ba' | |||
|
1352 | 1352 | group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None) |
|
1353 | 1353 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
1354 | 1354 | |
|
1355 |
users_group = relationship('User |
|
|
1355 | users_group = relationship('UserGroup') | |
|
1356 | 1356 | permission = relationship('Permission') |
|
1357 | 1357 | group = relationship('RepoGroup') |
|
1358 | 1358 |
@@ -341,7 +341,7 b' class User(Base, BaseModel):' | |||
|
341 | 341 | repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all') |
|
342 | 342 | repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all') |
|
343 | 343 | |
|
344 |
group_member = relationship('User |
|
|
344 | group_member = relationship('UserGroupMember', cascade='all') | |
|
345 | 345 | |
|
346 | 346 | notifications = relationship('UserNotification', cascade='all') |
|
347 | 347 | # notifications assigned to this user |
@@ -541,7 +541,7 b' class UserLog(Base, BaseModel):' | |||
|
541 | 541 | repository = relationship('Repository', cascade='') |
|
542 | 542 | |
|
543 | 543 | |
|
544 |
class User |
|
|
544 | class UserGroup(Base, BaseModel): | |
|
545 | 545 | __tablename__ = 'users_groups' |
|
546 | 546 | __table_args__ = ( |
|
547 | 547 | {'extend_existing': True, 'mysql_engine': 'InnoDB', |
@@ -553,9 +553,9 b' class UsersGroup(Base, BaseModel):' | |||
|
553 | 553 | users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None) |
|
554 | 554 | inherit_default_permissions = Column("users_group_inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True) |
|
555 | 555 | |
|
556 |
members = relationship('User |
|
|
557 |
users_group_to_perm = relationship('User |
|
|
558 |
users_group_repo_to_perm = relationship('User |
|
|
556 | members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined") | |
|
557 | users_group_to_perm = relationship('UserGroupToPerm', cascade='all') | |
|
558 | users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all') | |
|
559 | 559 | |
|
560 | 560 | def __unicode__(self): |
|
561 | 561 | return u'<userGroup(%s)>' % (self.users_group_name) |
@@ -595,7 +595,7 b' class UsersGroup(Base, BaseModel):' | |||
|
595 | 595 | return data |
|
596 | 596 | |
|
597 | 597 | |
|
598 |
class User |
|
|
598 | class UserGroupMember(Base, BaseModel): | |
|
599 | 599 | __tablename__ = 'users_groups_members' |
|
600 | 600 | __table_args__ = ( |
|
601 | 601 | {'extend_existing': True, 'mysql_engine': 'InnoDB', |
@@ -607,7 +607,7 b' class UsersGroupMember(Base, BaseModel):' | |||
|
607 | 607 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
|
608 | 608 | |
|
609 | 609 | user = relationship('User', lazy='joined') |
|
610 |
users_group = relationship('User |
|
|
610 | users_group = relationship('UserGroup') | |
|
611 | 611 | |
|
612 | 612 | def __init__(self, gr_id='', u_id=''): |
|
613 | 613 | self.users_group_id = gr_id |
@@ -645,7 +645,7 b' class Repository(Base, BaseModel):' | |||
|
645 | 645 | fork = relationship('Repository', remote_side=repo_id) |
|
646 | 646 | group = relationship('RepoGroup') |
|
647 | 647 | repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id') |
|
648 |
users_group_to_perm = relationship('User |
|
|
648 | users_group_to_perm = relationship('UserGroupRepoToPerm', cascade='all') | |
|
649 | 649 | stats = relationship('Statistics', cascade='all', uselist=False) |
|
650 | 650 | |
|
651 | 651 | followers = relationship('UserFollowing', |
@@ -1033,7 +1033,7 b' class RepoGroup(Base, BaseModel):' | |||
|
1033 | 1033 | enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False) |
|
1034 | 1034 | |
|
1035 | 1035 | repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id') |
|
1036 |
users_group_to_perm = relationship('User |
|
|
1036 | users_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all') | |
|
1037 | 1037 | |
|
1038 | 1038 | parent_group = relationship('RepoGroup', remote_side=group_id) |
|
1039 | 1039 | |
@@ -1297,7 +1297,7 b' class UserToPerm(Base, BaseModel):' | |||
|
1297 | 1297 | permission = relationship('Permission', lazy='joined') |
|
1298 | 1298 | |
|
1299 | 1299 | |
|
1300 |
class User |
|
|
1300 | class UserGroupRepoToPerm(Base, BaseModel): | |
|
1301 | 1301 | __tablename__ = 'users_group_repo_to_perm' |
|
1302 | 1302 | __table_args__ = ( |
|
1303 | 1303 | UniqueConstraint('repository_id', 'users_group_id', 'permission_id'), |
@@ -1309,7 +1309,7 b' class UsersGroupRepoToPerm(Base, BaseMod' | |||
|
1309 | 1309 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
1310 | 1310 | repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) |
|
1311 | 1311 | |
|
1312 |
users_group = relationship('User |
|
|
1312 | users_group = relationship('UserGroup') | |
|
1313 | 1313 | permission = relationship('Permission') |
|
1314 | 1314 | repository = relationship('Repository') |
|
1315 | 1315 | |
@@ -1326,7 +1326,7 b' class UsersGroupRepoToPerm(Base, BaseMod' | |||
|
1326 | 1326 | return u'<userGroup:%s => %s >' % (self.users_group, self.repository) |
|
1327 | 1327 | |
|
1328 | 1328 | |
|
1329 |
class User |
|
|
1329 | class UserGroupToPerm(Base, BaseModel): | |
|
1330 | 1330 | __tablename__ = 'users_group_to_perm' |
|
1331 | 1331 | __table_args__ = ( |
|
1332 | 1332 | UniqueConstraint('users_group_id', 'permission_id',), |
@@ -1337,7 +1337,7 b' class UsersGroupToPerm(Base, BaseModel):' | |||
|
1337 | 1337 | users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
|
1338 | 1338 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
1339 | 1339 | |
|
1340 |
users_group = relationship('User |
|
|
1340 | users_group = relationship('UserGroup') | |
|
1341 | 1341 | permission = relationship('Permission') |
|
1342 | 1342 | |
|
1343 | 1343 | |
@@ -1359,7 +1359,7 b' class UserRepoGroupToPerm(Base, BaseMode' | |||
|
1359 | 1359 | permission = relationship('Permission') |
|
1360 | 1360 | |
|
1361 | 1361 | |
|
1362 |
class User |
|
|
1362 | class UserGroupRepoGroupToPerm(Base, BaseModel): | |
|
1363 | 1363 | __tablename__ = 'users_group_repo_group_to_perm' |
|
1364 | 1364 | __table_args__ = ( |
|
1365 | 1365 | UniqueConstraint('users_group_id', 'group_id'), |
@@ -1372,7 +1372,7 b' class UsersGroupRepoGroupToPerm(Base, Ba' | |||
|
1372 | 1372 | group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None) |
|
1373 | 1373 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
1374 | 1374 | |
|
1375 |
users_group = relationship('User |
|
|
1375 | users_group = relationship('UserGroup') | |
|
1376 | 1376 | permission = relationship('Permission') |
|
1377 | 1377 | group = relationship('RepoGroup') |
|
1378 | 1378 |
@@ -341,7 +341,7 b' class User(Base, BaseModel):' | |||
|
341 | 341 | repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all') |
|
342 | 342 | repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all') |
|
343 | 343 | |
|
344 |
group_member = relationship('User |
|
|
344 | group_member = relationship('UserGroupMember', cascade='all') | |
|
345 | 345 | |
|
346 | 346 | notifications = relationship('UserNotification', cascade='all') |
|
347 | 347 | # notifications assigned to this user |
@@ -575,7 +575,7 b' class UserLog(Base, BaseModel):' | |||
|
575 | 575 | repository = relationship('Repository', cascade='') |
|
576 | 576 | |
|
577 | 577 | |
|
578 |
class User |
|
|
578 | class UserGroup(Base, BaseModel): | |
|
579 | 579 | __tablename__ = 'users_groups' |
|
580 | 580 | __table_args__ = ( |
|
581 | 581 | {'extend_existing': True, 'mysql_engine': 'InnoDB', |
@@ -587,9 +587,9 b' class UsersGroup(Base, BaseModel):' | |||
|
587 | 587 | users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None) |
|
588 | 588 | inherit_default_permissions = Column("users_group_inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True) |
|
589 | 589 | |
|
590 |
members = relationship('User |
|
|
591 |
users_group_to_perm = relationship('User |
|
|
592 |
users_group_repo_to_perm = relationship('User |
|
|
590 | members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined") | |
|
591 | users_group_to_perm = relationship('UserGroupToPerm', cascade='all') | |
|
592 | users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all') | |
|
593 | 593 | |
|
594 | 594 | def __unicode__(self): |
|
595 | 595 | return u'<userGroup(%s)>' % (self.users_group_name) |
@@ -629,7 +629,7 b' class UsersGroup(Base, BaseModel):' | |||
|
629 | 629 | return data |
|
630 | 630 | |
|
631 | 631 | |
|
632 |
class User |
|
|
632 | class UserGroupMember(Base, BaseModel): | |
|
633 | 633 | __tablename__ = 'users_groups_members' |
|
634 | 634 | __table_args__ = ( |
|
635 | 635 | {'extend_existing': True, 'mysql_engine': 'InnoDB', |
@@ -641,7 +641,7 b' class UsersGroupMember(Base, BaseModel):' | |||
|
641 | 641 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
|
642 | 642 | |
|
643 | 643 | user = relationship('User', lazy='joined') |
|
644 |
users_group = relationship('User |
|
|
644 | users_group = relationship('UserGroup') | |
|
645 | 645 | |
|
646 | 646 | def __init__(self, gr_id='', u_id=''): |
|
647 | 647 | self.users_group_id = gr_id |
@@ -680,7 +680,7 b' class Repository(Base, BaseModel):' | |||
|
680 | 680 | fork = relationship('Repository', remote_side=repo_id) |
|
681 | 681 | group = relationship('RepoGroup') |
|
682 | 682 | repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id') |
|
683 |
users_group_to_perm = relationship('User |
|
|
683 | users_group_to_perm = relationship('UserGroupRepoToPerm', cascade='all') | |
|
684 | 684 | stats = relationship('Statistics', cascade='all', uselist=False) |
|
685 | 685 | |
|
686 | 686 | followers = relationship('UserFollowing', |
@@ -1139,7 +1139,7 b' class RepoGroup(Base, BaseModel):' | |||
|
1139 | 1139 | enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False) |
|
1140 | 1140 | |
|
1141 | 1141 | repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id') |
|
1142 |
users_group_to_perm = relationship('User |
|
|
1142 | users_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all') | |
|
1143 | 1143 | |
|
1144 | 1144 | parent_group = relationship('RepoGroup', remote_side=group_id) |
|
1145 | 1145 | |
@@ -1403,7 +1403,7 b' class UserToPerm(Base, BaseModel):' | |||
|
1403 | 1403 | permission = relationship('Permission', lazy='joined') |
|
1404 | 1404 | |
|
1405 | 1405 | |
|
1406 |
class User |
|
|
1406 | class UserGroupRepoToPerm(Base, BaseModel): | |
|
1407 | 1407 | __tablename__ = 'users_group_repo_to_perm' |
|
1408 | 1408 | __table_args__ = ( |
|
1409 | 1409 | UniqueConstraint('repository_id', 'users_group_id', 'permission_id'), |
@@ -1415,7 +1415,7 b' class UsersGroupRepoToPerm(Base, BaseMod' | |||
|
1415 | 1415 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
1416 | 1416 | repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) |
|
1417 | 1417 | |
|
1418 |
users_group = relationship('User |
|
|
1418 | users_group = relationship('UserGroup') | |
|
1419 | 1419 | permission = relationship('Permission') |
|
1420 | 1420 | repository = relationship('Repository') |
|
1421 | 1421 | |
@@ -1432,7 +1432,7 b' class UsersGroupRepoToPerm(Base, BaseMod' | |||
|
1432 | 1432 | return u'<userGroup:%s => %s >' % (self.users_group, self.repository) |
|
1433 | 1433 | |
|
1434 | 1434 | |
|
1435 |
class User |
|
|
1435 | class UserGroupToPerm(Base, BaseModel): | |
|
1436 | 1436 | __tablename__ = 'users_group_to_perm' |
|
1437 | 1437 | __table_args__ = ( |
|
1438 | 1438 | UniqueConstraint('users_group_id', 'permission_id',), |
@@ -1443,7 +1443,7 b' class UsersGroupToPerm(Base, BaseModel):' | |||
|
1443 | 1443 | users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
|
1444 | 1444 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
1445 | 1445 | |
|
1446 |
users_group = relationship('User |
|
|
1446 | users_group = relationship('UserGroup') | |
|
1447 | 1447 | permission = relationship('Permission') |
|
1448 | 1448 | |
|
1449 | 1449 | |
@@ -1465,7 +1465,7 b' class UserRepoGroupToPerm(Base, BaseMode' | |||
|
1465 | 1465 | permission = relationship('Permission') |
|
1466 | 1466 | |
|
1467 | 1467 | |
|
1468 |
class User |
|
|
1468 | class UserGroupRepoGroupToPerm(Base, BaseModel): | |
|
1469 | 1469 | __tablename__ = 'users_group_repo_group_to_perm' |
|
1470 | 1470 | __table_args__ = ( |
|
1471 | 1471 | UniqueConstraint('users_group_id', 'group_id'), |
@@ -1478,7 +1478,7 b' class UsersGroupRepoGroupToPerm(Base, Ba' | |||
|
1478 | 1478 | group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None) |
|
1479 | 1479 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
1480 | 1480 | |
|
1481 |
users_group = relationship('User |
|
|
1481 | users_group = relationship('UserGroup') | |
|
1482 | 1482 | permission = relationship('Permission') |
|
1483 | 1483 | group = relationship('RepoGroup') |
|
1484 | 1484 |
@@ -34,26 +34,26 b' def upgrade(migrate_engine):' | |||
|
34 | 34 | #========================================================================== |
|
35 | 35 | # Add table `users_groups` |
|
36 | 36 | #========================================================================== |
|
37 |
from rhodecode.lib.dbmigrate.schema.db_1_2_0 import User |
|
|
38 |
User |
|
|
37 | from rhodecode.lib.dbmigrate.schema.db_1_2_0 import UserGroup | |
|
38 | UserGroup().__table__.create() | |
|
39 | 39 | |
|
40 | 40 | #========================================================================== |
|
41 | 41 | # Add table `users_groups_members` |
|
42 | 42 | #========================================================================== |
|
43 |
from rhodecode.lib.dbmigrate.schema.db_1_2_0 import User |
|
|
44 |
User |
|
|
43 | from rhodecode.lib.dbmigrate.schema.db_1_2_0 import UserGroupMember | |
|
44 | UserGroupMember().__table__.create() | |
|
45 | 45 | |
|
46 | 46 | #========================================================================== |
|
47 | 47 | # Add table `users_group_repo_to_perm` |
|
48 | 48 | #========================================================================== |
|
49 |
from rhodecode.lib.dbmigrate.schema.db_1_2_0 import User |
|
|
50 |
User |
|
|
49 | from rhodecode.lib.dbmigrate.schema.db_1_2_0 import UserGroupRepoToPerm | |
|
50 | UserGroupRepoToPerm().__table__.create() | |
|
51 | 51 | |
|
52 | 52 | #========================================================================== |
|
53 | 53 | # Add table `users_group_to_perm` |
|
54 | 54 | #========================================================================== |
|
55 |
from rhodecode.lib.dbmigrate.schema.db_1_2_0 import User |
|
|
56 |
User |
|
|
55 | from rhodecode.lib.dbmigrate.schema.db_1_2_0 import UserGroupToPerm | |
|
56 | UserGroupToPerm().__table__.create() | |
|
57 | 57 | |
|
58 | 58 | #========================================================================== |
|
59 | 59 | # Upgrade of `users` table |
@@ -21,8 +21,8 b' def upgrade(migrate_engine):' | |||
|
21 | 21 | #========================================================================== |
|
22 | 22 | # Add table `users_group_repo_group_to_perm` |
|
23 | 23 | #========================================================================== |
|
24 |
from rhodecode.lib.dbmigrate.schema.db_1_3_0 import User |
|
|
25 |
User |
|
|
24 | from rhodecode.lib.dbmigrate.schema.db_1_3_0 import UserGroupRepoGroupToPerm | |
|
25 | UserGroupRepoGroupToPerm().__table__.create() | |
|
26 | 26 | |
|
27 | 27 | #========================================================================== |
|
28 | 28 | # Add table `changeset_comments` |
@@ -45,8 +45,8 b' def upgrade(migrate_engine):' | |||
|
45 | 45 | #========================================================================== |
|
46 | 46 | # Add unique to table `users_group_to_perm` |
|
47 | 47 | #========================================================================== |
|
48 |
from rhodecode.lib.dbmigrate.schema.db_1_3_0 import User |
|
|
49 |
tbl = User |
|
|
48 | from rhodecode.lib.dbmigrate.schema.db_1_3_0 import UserGroupToPerm | |
|
49 | tbl = UserGroupToPerm().__table__ | |
|
50 | 50 | cons = UniqueConstraint('users_group_id', 'permission_id', table=tbl) |
|
51 | 51 | cons.create() |
|
52 | 52 |
@@ -74,8 +74,8 b' def upgrade(migrate_engine):' | |||
|
74 | 74 | #========================================================================== |
|
75 | 75 | # USERS GROUP TABLE |
|
76 | 76 | #========================================================================== |
|
77 |
from rhodecode.lib.dbmigrate.schema.db_1_3_0 import User |
|
|
78 |
tbl = User |
|
|
77 | from rhodecode.lib.dbmigrate.schema.db_1_3_0 import UserGroup | |
|
78 | tbl = UserGroup.__table__ | |
|
79 | 79 | # add inherit_default_permission column |
|
80 | 80 | gr_inherit_default_permissions = Column( |
|
81 | 81 | "users_group_inherit_default_permissions", |
@@ -50,7 +50,7 b' class UserOwnsReposException(Exception):' | |||
|
50 | 50 | pass |
|
51 | 51 | |
|
52 | 52 | |
|
53 |
class User |
|
|
53 | class UserGroupsAssignedException(Exception): | |
|
54 | 54 | pass |
|
55 | 55 | |
|
56 | 56 |
@@ -341,7 +341,7 b' class User(Base, BaseModel):' | |||
|
341 | 341 | repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all') |
|
342 | 342 | repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all') |
|
343 | 343 | |
|
344 |
group_member = relationship('User |
|
|
344 | group_member = relationship('UserGroupMember', cascade='all') | |
|
345 | 345 | |
|
346 | 346 | notifications = relationship('UserNotification', cascade='all') |
|
347 | 347 | # notifications assigned to this user |
@@ -604,7 +604,7 b' class UserLog(Base, BaseModel):' | |||
|
604 | 604 | repository = relationship('Repository', cascade='') |
|
605 | 605 | |
|
606 | 606 | |
|
607 |
class User |
|
|
607 | class UserGroup(Base, BaseModel): | |
|
608 | 608 | __tablename__ = 'users_groups' |
|
609 | 609 | __table_args__ = ( |
|
610 | 610 | {'extend_existing': True, 'mysql_engine': 'InnoDB', |
@@ -616,9 +616,9 b' class UsersGroup(Base, BaseModel):' | |||
|
616 | 616 | users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None) |
|
617 | 617 | inherit_default_permissions = Column("users_group_inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True) |
|
618 | 618 | |
|
619 |
members = relationship('User |
|
|
620 |
users_group_to_perm = relationship('User |
|
|
621 |
users_group_repo_to_perm = relationship('User |
|
|
619 | members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined") | |
|
620 | users_group_to_perm = relationship('UserGroupToPerm', cascade='all') | |
|
621 | users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all') | |
|
622 | 622 | |
|
623 | 623 | def __unicode__(self): |
|
624 | 624 | return u'<userGroup(%s)>' % (self.users_group_name) |
@@ -658,7 +658,7 b' class UsersGroup(Base, BaseModel):' | |||
|
658 | 658 | return data |
|
659 | 659 | |
|
660 | 660 | |
|
661 |
class User |
|
|
661 | class UserGroupMember(Base, BaseModel): | |
|
662 | 662 | __tablename__ = 'users_groups_members' |
|
663 | 663 | __table_args__ = ( |
|
664 | 664 | {'extend_existing': True, 'mysql_engine': 'InnoDB', |
@@ -670,7 +670,7 b' class UsersGroupMember(Base, BaseModel):' | |||
|
670 | 670 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
|
671 | 671 | |
|
672 | 672 | user = relationship('User', lazy='joined') |
|
673 |
users_group = relationship('User |
|
|
673 | users_group = relationship('UserGroup') | |
|
674 | 674 | |
|
675 | 675 | def __init__(self, gr_id='', u_id=''): |
|
676 | 676 | self.users_group_id = gr_id |
@@ -747,7 +747,7 b' class Repository(Base, BaseModel):' | |||
|
747 | 747 | fork = relationship('Repository', remote_side=repo_id) |
|
748 | 748 | group = relationship('RepoGroup') |
|
749 | 749 | repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id') |
|
750 |
users_group_to_perm = relationship('User |
|
|
750 | users_group_to_perm = relationship('UserGroupRepoToPerm', cascade='all') | |
|
751 | 751 | stats = relationship('Statistics', cascade='all', uselist=False) |
|
752 | 752 | |
|
753 | 753 | followers = relationship('UserFollowing', |
@@ -1227,7 +1227,7 b' class RepoGroup(Base, BaseModel):' | |||
|
1227 | 1227 | enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False) |
|
1228 | 1228 | |
|
1229 | 1229 | repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id') |
|
1230 |
users_group_to_perm = relationship('User |
|
|
1230 | users_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all') | |
|
1231 | 1231 | |
|
1232 | 1232 | parent_group = relationship('RepoGroup', remote_side=group_id) |
|
1233 | 1233 | |
@@ -1490,7 +1490,7 b' class UserToPerm(Base, BaseModel):' | |||
|
1490 | 1490 | permission = relationship('Permission', lazy='joined') |
|
1491 | 1491 | |
|
1492 | 1492 | |
|
1493 |
class User |
|
|
1493 | class UserGroupRepoToPerm(Base, BaseModel): | |
|
1494 | 1494 | __tablename__ = 'users_group_repo_to_perm' |
|
1495 | 1495 | __table_args__ = ( |
|
1496 | 1496 | UniqueConstraint('repository_id', 'users_group_id', 'permission_id'), |
@@ -1502,7 +1502,7 b' class UsersGroupRepoToPerm(Base, BaseMod' | |||
|
1502 | 1502 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
1503 | 1503 | repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) |
|
1504 | 1504 | |
|
1505 |
users_group = relationship('User |
|
|
1505 | users_group = relationship('UserGroup') | |
|
1506 | 1506 | permission = relationship('Permission') |
|
1507 | 1507 | repository = relationship('Repository') |
|
1508 | 1508 | |
@@ -1519,7 +1519,7 b' class UsersGroupRepoToPerm(Base, BaseMod' | |||
|
1519 | 1519 | return u'<userGroup:%s => %s >' % (self.users_group, self.repository) |
|
1520 | 1520 | |
|
1521 | 1521 | |
|
1522 |
class User |
|
|
1522 | class UserGroupToPerm(Base, BaseModel): | |
|
1523 | 1523 | __tablename__ = 'users_group_to_perm' |
|
1524 | 1524 | __table_args__ = ( |
|
1525 | 1525 | UniqueConstraint('users_group_id', 'permission_id',), |
@@ -1530,7 +1530,7 b' class UsersGroupToPerm(Base, BaseModel):' | |||
|
1530 | 1530 | users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
|
1531 | 1531 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
1532 | 1532 | |
|
1533 |
users_group = relationship('User |
|
|
1533 | users_group = relationship('UserGroup') | |
|
1534 | 1534 | permission = relationship('Permission') |
|
1535 | 1535 | |
|
1536 | 1536 | |
@@ -1552,7 +1552,7 b' class UserRepoGroupToPerm(Base, BaseMode' | |||
|
1552 | 1552 | permission = relationship('Permission') |
|
1553 | 1553 | |
|
1554 | 1554 | |
|
1555 |
class User |
|
|
1555 | class UserGroupRepoGroupToPerm(Base, BaseModel): | |
|
1556 | 1556 | __tablename__ = 'users_group_repo_group_to_perm' |
|
1557 | 1557 | __table_args__ = ( |
|
1558 | 1558 | UniqueConstraint('users_group_id', 'group_id'), |
@@ -1565,7 +1565,7 b' class UsersGroupRepoGroupToPerm(Base, Ba' | |||
|
1565 | 1565 | group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None) |
|
1566 | 1566 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
1567 | 1567 | |
|
1568 |
users_group = relationship('User |
|
|
1568 | users_group = relationship('UserGroup') | |
|
1569 | 1569 | permission = relationship('Permission') |
|
1570 | 1570 | group = relationship('RepoGroup') |
|
1571 | 1571 |
@@ -94,14 +94,14 b' def UserForm(edit=False, old_data={}):' | |||
|
94 | 94 | return _UserForm |
|
95 | 95 | |
|
96 | 96 | |
|
97 |
def User |
|
|
98 |
class _User |
|
|
97 | def UserGroupForm(edit=False, old_data={}, available_members=[]): | |
|
98 | class _UserGroupForm(formencode.Schema): | |
|
99 | 99 | allow_extra_fields = True |
|
100 | 100 | filter_extra_fields = True |
|
101 | 101 | |
|
102 | 102 | users_group_name = All( |
|
103 | 103 | v.UnicodeString(strip=True, min=1, not_empty=True), |
|
104 |
v.ValidUser |
|
|
104 | v.ValidUserGroup(edit, old_data) | |
|
105 | 105 | ) |
|
106 | 106 | |
|
107 | 107 | users_group_active = v.StringBoolean(if_missing=False) |
@@ -112,7 +112,7 b' def UsersGroupForm(edit=False, old_data=' | |||
|
112 | 112 | if_missing=None, not_empty=False |
|
113 | 113 | ) |
|
114 | 114 | |
|
115 |
return _User |
|
|
115 | return _UserGroupForm | |
|
116 | 116 | |
|
117 | 117 | |
|
118 | 118 | def ReposGroupForm(edit=False, old_data={}, available_groups=[], |
@@ -38,7 +38,7 b' from rhodecode.lib.hooks import log_crea' | |||
|
38 | 38 | |
|
39 | 39 | from rhodecode.model import BaseModel |
|
40 | 40 | from rhodecode.model.db import Repository, UserRepoToPerm, User, Permission, \ |
|
41 |
Statistics, User |
|
|
41 | Statistics, UserGroup, UserGroupRepoToPerm, RhodeCodeUi, RepoGroup,\ | |
|
42 | 42 | RhodeCodeSetting, RepositoryField |
|
43 | 43 | from rhodecode.lib import helpers as h |
|
44 | 44 | from rhodecode.lib.auth import HasRepoPermissionAny |
@@ -54,8 +54,8 b' class RepoModel(BaseModel):' | |||
|
54 | 54 | URL_SEPARATOR = Repository.url_sep() |
|
55 | 55 | |
|
56 | 56 | def __get_users_group(self, users_group): |
|
57 |
return self._get_instance(User |
|
|
58 |
callback=User |
|
|
57 | return self._get_instance(UserGroup, users_group, | |
|
58 | callback=UserGroup.get_by_group_name) | |
|
59 | 59 | |
|
60 | 60 | def _get_repos_group(self, repos_group): |
|
61 | 61 | return self._get_instance(RepoGroup, repos_group, |
@@ -120,8 +120,8 b' class RepoModel(BaseModel):' | |||
|
120 | 120 | ) |
|
121 | 121 | |
|
122 | 122 | def get_users_groups_js(self): |
|
123 |
users_groups = self.sa.query(User |
|
|
124 |
.filter(User |
|
|
123 | users_groups = self.sa.query(UserGroup)\ | |
|
124 | .filter(UserGroup.users_group_active == True).all() | |
|
125 | 125 | |
|
126 | 126 | return json.dumps([ |
|
127 | 127 | { |
@@ -415,15 +415,15 b' class RepoModel(BaseModel):' | |||
|
415 | 415 | repo = fork_of |
|
416 | 416 | user_perms = UserRepoToPerm.query()\ |
|
417 | 417 | .filter(UserRepoToPerm.repository == repo).all() |
|
418 |
group_perms = User |
|
|
419 |
.filter(User |
|
|
418 | group_perms = UserGroupRepoToPerm.query()\ | |
|
419 | .filter(UserGroupRepoToPerm.repository == repo).all() | |
|
420 | 420 | |
|
421 | 421 | for perm in user_perms: |
|
422 | 422 | UserRepoToPerm.create(perm.user, new_repo, |
|
423 | 423 | perm.permission) |
|
424 | 424 | |
|
425 | 425 | for perm in group_perms: |
|
426 |
User |
|
|
426 | UserGroupRepoToPerm.create(perm.users_group, new_repo, | |
|
427 | 427 | perm.permission) |
|
428 | 428 | else: |
|
429 | 429 | _create_default_perms() |
@@ -562,14 +562,14 b' class RepoModel(BaseModel):' | |||
|
562 | 562 | permission = self._get_perm(perm) |
|
563 | 563 | |
|
564 | 564 | # check if we have that permission already |
|
565 |
obj = self.sa.query(User |
|
|
566 |
.filter(User |
|
|
567 |
.filter(User |
|
|
565 | obj = self.sa.query(UserGroupRepoToPerm)\ | |
|
566 | .filter(UserGroupRepoToPerm.users_group == group_name)\ | |
|
567 | .filter(UserGroupRepoToPerm.repository == repo)\ | |
|
568 | 568 | .scalar() |
|
569 | 569 | |
|
570 | 570 | if obj is None: |
|
571 | 571 | # create new |
|
572 |
obj = User |
|
|
572 | obj = UserGroupRepoToPerm() | |
|
573 | 573 | |
|
574 | 574 | obj.repository = repo |
|
575 | 575 | obj.users_group = group_name |
@@ -588,9 +588,9 b' class RepoModel(BaseModel):' | |||
|
588 | 588 | repo = self._get_repo(repo) |
|
589 | 589 | group_name = self.__get_users_group(group_name) |
|
590 | 590 | |
|
591 |
obj = self.sa.query(User |
|
|
592 |
.filter(User |
|
|
593 |
.filter(User |
|
|
591 | obj = self.sa.query(UserGroupRepoToPerm)\ | |
|
592 | .filter(UserGroupRepoToPerm.repository == repo)\ | |
|
593 | .filter(UserGroupRepoToPerm.users_group == group_name)\ | |
|
594 | 594 | .scalar() |
|
595 | 595 | if obj: |
|
596 | 596 | self.sa.delete(obj) |
@@ -26,7 +26,7 b'' | |||
|
26 | 26 | |
|
27 | 27 | import logging |
|
28 | 28 | from rhodecode.model import BaseModel |
|
29 |
from rhodecode.model.db import UserRepoToPerm, User |
|
|
29 | from rhodecode.model.db import UserRepoToPerm, UserGroupRepoToPerm, \ | |
|
30 | 30 | Permission |
|
31 | 31 | |
|
32 | 32 | log = logging.getLogger(__name__) |
@@ -64,9 +64,9 b' class RepositoryPermissionModel(BaseMode' | |||
|
64 | 64 | self.sa.delete(current) |
|
65 | 65 | |
|
66 | 66 | def get_users_group_permission(self, repository, users_group): |
|
67 |
return User |
|
|
68 |
.filter(User |
|
|
69 |
.filter(User |
|
|
67 | return UserGroupRepoToPerm.query() \ | |
|
68 | .filter(UserGroupRepoToPerm.users_group == users_group) \ | |
|
69 | .filter(UserGroupRepoToPerm.repository == repository) \ | |
|
70 | 70 | .scalar() |
|
71 | 71 | |
|
72 | 72 | def update_users_group_permission(self, repository, users_group, |
@@ -77,7 +77,7 b' class RepositoryPermissionModel(BaseMode' | |||
|
77 | 77 | if not current.permission is permission: |
|
78 | 78 | current.permission = permission |
|
79 | 79 | else: |
|
80 |
p = User |
|
|
80 | p = UserGroupRepoToPerm() | |
|
81 | 81 | p.users_group = users_group |
|
82 | 82 | p.repository = repository |
|
83 | 83 | p.permission = permission |
@@ -33,7 +33,7 b' from rhodecode.lib.utils2 import LazyPro' | |||
|
33 | 33 | |
|
34 | 34 | from rhodecode.model import BaseModel |
|
35 | 35 | from rhodecode.model.db import RepoGroup, RhodeCodeUi, UserRepoGroupToPerm, \ |
|
36 |
User, Permission, User |
|
|
36 | User, Permission, UserGroupRepoGroupToPerm, UserGroup, Repository | |
|
37 | 37 | |
|
38 | 38 | log = logging.getLogger(__name__) |
|
39 | 39 | |
@@ -43,8 +43,8 b' class ReposGroupModel(BaseModel):' | |||
|
43 | 43 | cls = RepoGroup |
|
44 | 44 | |
|
45 | 45 | def __get_users_group(self, users_group): |
|
46 |
return self._get_instance(User |
|
|
47 |
callback=User |
|
|
46 | return self._get_instance(UserGroup, users_group, | |
|
47 | callback=UserGroup.get_by_group_name) | |
|
48 | 48 | |
|
49 | 49 | def _get_repos_group(self, repos_group): |
|
50 | 50 | return self._get_instance(RepoGroup, repos_group, |
@@ -390,14 +390,14 b' class ReposGroupModel(BaseModel):' | |||
|
390 | 390 | permission = self._get_perm(perm) |
|
391 | 391 | |
|
392 | 392 | # check if we have that permission already |
|
393 |
obj = self.sa.query(User |
|
|
394 |
.filter(User |
|
|
395 |
.filter(User |
|
|
393 | obj = self.sa.query(UserGroupRepoGroupToPerm)\ | |
|
394 | .filter(UserGroupRepoGroupToPerm.group == repos_group)\ | |
|
395 | .filter(UserGroupRepoGroupToPerm.users_group == group_name)\ | |
|
396 | 396 | .scalar() |
|
397 | 397 | |
|
398 | 398 | if obj is None: |
|
399 | 399 | # create new |
|
400 |
obj = User |
|
|
400 | obj = UserGroupRepoGroupToPerm() | |
|
401 | 401 | |
|
402 | 402 | obj.group = repos_group |
|
403 | 403 | obj.users_group = group_name |
@@ -417,9 +417,9 b' class ReposGroupModel(BaseModel):' | |||
|
417 | 417 | repos_group = self._get_repos_group(repos_group) |
|
418 | 418 | group_name = self.__get_users_group(group_name) |
|
419 | 419 | |
|
420 |
obj = self.sa.query(User |
|
|
421 |
.filter(User |
|
|
422 |
.filter(User |
|
|
420 | obj = self.sa.query(UserGroupRepoGroupToPerm)\ | |
|
421 | .filter(UserGroupRepoGroupToPerm.group == repos_group)\ | |
|
422 | .filter(UserGroupRepoGroupToPerm.users_group == group_name)\ | |
|
423 | 423 | .scalar() |
|
424 | 424 | if obj: |
|
425 | 425 | self.sa.delete(obj) |
@@ -37,8 +37,8 b' from rhodecode.lib.utils2 import safe_un' | |||
|
37 | 37 | from rhodecode.lib.caching_query import FromCache |
|
38 | 38 | from rhodecode.model import BaseModel |
|
39 | 39 | from rhodecode.model.db import User, UserRepoToPerm, Repository, Permission, \ |
|
40 |
UserToPerm, User |
|
|
41 |
Notification, RepoGroup, UserRepoGroupToPerm, User |
|
|
40 | UserToPerm, UserGroupRepoToPerm, UserGroupToPerm, UserGroupMember, \ | |
|
41 | Notification, RepoGroup, UserRepoGroupToPerm, UserGroupRepoGroupToPerm, \ | |
|
42 | 42 | UserEmailMap, UserIpMap |
|
43 | 43 | from rhodecode.lib.exceptions import DefaultUserException, \ |
|
44 | 44 | UserOwnsReposException |
@@ -513,12 +513,12 b' class UserModel(BaseModel):' | |||
|
513 | 513 | |
|
514 | 514 | # USER GROUPS comes first |
|
515 | 515 | # user group global permissions |
|
516 |
user_perms_from_users_groups = self.sa.query(User |
|
|
517 |
.options(joinedload(User |
|
|
518 |
.join((User |
|
|
519 |
User |
|
|
520 |
.filter(User |
|
|
521 |
.order_by(User |
|
|
516 | user_perms_from_users_groups = self.sa.query(UserGroupToPerm)\ | |
|
517 | .options(joinedload(UserGroupToPerm.permission))\ | |
|
518 | .join((UserGroupMember, UserGroupToPerm.users_group_id == | |
|
519 | UserGroupMember.users_group_id))\ | |
|
520 | .filter(UserGroupMember.user_id == uid)\ | |
|
521 | .order_by(UserGroupToPerm.users_group_id)\ | |
|
522 | 522 | .all() |
|
523 | 523 | #need to group here by groups since user can be in more than one group |
|
524 | 524 | _grouped = [[x, list(y)] for x, y in |
@@ -561,19 +561,19 b' class UserModel(BaseModel):' | |||
|
561 | 561 | |
|
562 | 562 | # user group for repositories permissions |
|
563 | 563 | user_repo_perms_from_users_groups = \ |
|
564 |
self.sa.query(User |
|
|
565 |
.join((Repository, User |
|
|
564 | self.sa.query(UserGroupRepoToPerm, Permission, Repository,)\ | |
|
565 | .join((Repository, UserGroupRepoToPerm.repository_id == | |
|
566 | 566 | Repository.repo_id))\ |
|
567 |
.join((Permission, User |
|
|
567 | .join((Permission, UserGroupRepoToPerm.permission_id == | |
|
568 | 568 | Permission.permission_id))\ |
|
569 |
.join((User |
|
|
570 |
User |
|
|
571 |
.filter(User |
|
|
569 | .join((UserGroupMember, UserGroupRepoToPerm.users_group_id == | |
|
570 | UserGroupMember.users_group_id))\ | |
|
571 | .filter(UserGroupMember.user_id == uid)\ | |
|
572 | 572 | .all() |
|
573 | 573 | |
|
574 | 574 | multiple_counter = collections.defaultdict(int) |
|
575 | 575 | for perm in user_repo_perms_from_users_groups: |
|
576 |
r_k = perm.User |
|
|
576 | r_k = perm.UserGroupRepoToPerm.repository.repo_name | |
|
577 | 577 | multiple_counter[r_k] += 1 |
|
578 | 578 | p = perm.Permission.permission_name |
|
579 | 579 | cur_perm = user.permissions[RK][r_k] |
@@ -619,18 +619,18 b' class UserModel(BaseModel):' | |||
|
619 | 619 | #====================================================================== |
|
620 | 620 | # user group for repo groups permissions |
|
621 | 621 | user_repo_group_perms_from_users_groups = \ |
|
622 |
self.sa.query(User |
|
|
623 |
.join((RepoGroup, User |
|
|
624 |
.join((Permission, User |
|
|
622 | self.sa.query(UserGroupRepoGroupToPerm, Permission, RepoGroup)\ | |
|
623 | .join((RepoGroup, UserGroupRepoGroupToPerm.group_id == RepoGroup.group_id))\ | |
|
624 | .join((Permission, UserGroupRepoGroupToPerm.permission_id | |
|
625 | 625 | == Permission.permission_id))\ |
|
626 |
.join((User |
|
|
627 |
== User |
|
|
628 |
.filter(User |
|
|
626 | .join((UserGroupMember, UserGroupRepoGroupToPerm.users_group_id | |
|
627 | == UserGroupMember.users_group_id))\ | |
|
628 | .filter(UserGroupMember.user_id == uid)\ | |
|
629 | 629 | .all() |
|
630 | 630 | |
|
631 | 631 | multiple_counter = collections.defaultdict(int) |
|
632 | 632 | for perm in user_repo_group_perms_from_users_groups: |
|
633 |
g_k = perm.User |
|
|
633 | g_k = perm.UserGroupRepoGroupToPerm.group.group_name | |
|
634 | 634 | multiple_counter[g_k] += 1 |
|
635 | 635 | p = perm.Permission.permission_name |
|
636 | 636 | cur_perm = user.permissions[GK][g_k] |
@@ -28,33 +28,33 b' import logging' | |||
|
28 | 28 | import traceback |
|
29 | 29 | |
|
30 | 30 | from rhodecode.model import BaseModel |
|
31 |
from rhodecode.model.db import User |
|
|
32 |
User |
|
|
33 |
from rhodecode.lib.exceptions import User |
|
|
31 | from rhodecode.model.db import UserGroupMember, UserGroup,\ | |
|
32 | UserGroupRepoToPerm, Permission, UserGroupToPerm, User | |
|
33 | from rhodecode.lib.exceptions import UserGroupsAssignedException | |
|
34 | 34 | |
|
35 | 35 | log = logging.getLogger(__name__) |
|
36 | 36 | |
|
37 | 37 | |
|
38 |
class User |
|
|
38 | class UserGroupModel(BaseModel): | |
|
39 | 39 | |
|
40 |
cls = User |
|
|
40 | cls = UserGroup | |
|
41 | 41 | |
|
42 | 42 | def __get_users_group(self, users_group): |
|
43 |
return self._get_instance(User |
|
|
44 |
callback=User |
|
|
43 | return self._get_instance(UserGroup, users_group, | |
|
44 | callback=UserGroup.get_by_group_name) | |
|
45 | 45 | |
|
46 | 46 | def get(self, users_group_id, cache=False): |
|
47 |
return User |
|
|
47 | return UserGroup.get(users_group_id) | |
|
48 | 48 | |
|
49 | 49 | def get_group(self, users_group): |
|
50 | 50 | return self.__get_users_group(users_group) |
|
51 | 51 | |
|
52 | 52 | def get_by_name(self, name, cache=False, case_insensitive=False): |
|
53 |
return User |
|
|
53 | return UserGroup.get_by_group_name(name, cache, case_insensitive) | |
|
54 | 54 | |
|
55 | 55 | def create(self, name, active=True): |
|
56 | 56 | try: |
|
57 |
new = User |
|
|
57 | new = UserGroup() | |
|
58 | 58 | new.users_group_name = name |
|
59 | 59 | new.users_group_active = active |
|
60 | 60 | self.sa.add(new) |
@@ -76,7 +76,7 b' class UsersGroupModel(BaseModel):' | |||
|
76 | 76 | if v: |
|
77 | 77 | v = [v] if isinstance(v, basestring) else v |
|
78 | 78 | for u_id in set(v): |
|
79 |
member = User |
|
|
79 | member = UserGroupMember(users_group.users_group_id, u_id) | |
|
80 | 80 | members_list.append(member) |
|
81 | 81 | setattr(users_group, 'members', members_list) |
|
82 | 82 | setattr(users_group, k, v) |
@@ -99,11 +99,11 b' class UsersGroupModel(BaseModel):' | |||
|
99 | 99 | users_group = self.__get_users_group(users_group) |
|
100 | 100 | |
|
101 | 101 | # check if this group is not assigned to repo |
|
102 |
assigned_groups = User |
|
|
103 |
.filter(User |
|
|
102 | assigned_groups = UserGroupRepoToPerm.query()\ | |
|
103 | .filter(UserGroupRepoToPerm.users_group == users_group).all() | |
|
104 | 104 | |
|
105 | 105 | if assigned_groups and force is False: |
|
106 |
raise User |
|
|
106 | raise UserGroupsAssignedException('RepoGroup assigned to %s' % | |
|
107 | 107 | assigned_groups) |
|
108 | 108 | |
|
109 | 109 | self.sa.delete(users_group) |
@@ -121,7 +121,7 b' class UsersGroupModel(BaseModel):' | |||
|
121 | 121 | return True |
|
122 | 122 | |
|
123 | 123 | try: |
|
124 |
users_group_member = User |
|
|
124 | users_group_member = UserGroupMember() | |
|
125 | 125 | users_group_member.user = user |
|
126 | 126 | users_group_member.users_group = users_group |
|
127 | 127 | |
@@ -160,23 +160,23 b' class UsersGroupModel(BaseModel):' | |||
|
160 | 160 | users_group = self.__get_users_group(users_group) |
|
161 | 161 | perm = self._get_perm(perm) |
|
162 | 162 | |
|
163 |
return User |
|
|
164 |
.filter(User |
|
|
165 |
.filter(User |
|
|
163 | return UserGroupToPerm.query()\ | |
|
164 | .filter(UserGroupToPerm.users_group == users_group)\ | |
|
165 | .filter(UserGroupToPerm.permission == perm).scalar() is not None | |
|
166 | 166 | |
|
167 | 167 | def grant_perm(self, users_group, perm): |
|
168 | 168 | users_group = self.__get_users_group(users_group) |
|
169 | 169 | perm = self._get_perm(perm) |
|
170 | 170 | |
|
171 | 171 | # if this permission is already granted skip it |
|
172 |
_perm = User |
|
|
173 |
.filter(User |
|
|
174 |
.filter(User |
|
|
172 | _perm = UserGroupToPerm.query()\ | |
|
173 | .filter(UserGroupToPerm.users_group == users_group)\ | |
|
174 | .filter(UserGroupToPerm.permission == perm)\ | |
|
175 | 175 | .scalar() |
|
176 | 176 | if _perm: |
|
177 | 177 | return |
|
178 | 178 | |
|
179 |
new = User |
|
|
179 | new = UserGroupToPerm() | |
|
180 | 180 | new.users_group = users_group |
|
181 | 181 | new.permission = perm |
|
182 | 182 | self.sa.add(new) |
@@ -185,8 +185,8 b' class UsersGroupModel(BaseModel):' | |||
|
185 | 185 | users_group = self.__get_users_group(users_group) |
|
186 | 186 | perm = self._get_perm(perm) |
|
187 | 187 | |
|
188 |
obj = User |
|
|
189 |
.filter(User |
|
|
190 |
.filter(User |
|
|
188 | obj = UserGroupToPerm.query()\ | |
|
189 | .filter(UserGroupToPerm.users_group == users_group)\ | |
|
190 | .filter(UserGroupToPerm.permission == perm).scalar() | |
|
191 | 191 | if obj: |
|
192 | 192 | self.sa.delete(obj) |
@@ -16,7 +16,7 b' from formencode.validators import (' | |||
|
16 | 16 | from rhodecode.lib.compat import OrderedSet |
|
17 | 17 | from rhodecode.lib import ipaddr |
|
18 | 18 | from rhodecode.lib.utils import repo_name_slug |
|
19 |
from rhodecode.model.db import RepoGroup, Repository, User |
|
|
19 | from rhodecode.model.db import RepoGroup, Repository, UserGroup, User,\ | |
|
20 | 20 | ChangesetStatus |
|
21 | 21 | from rhodecode.lib.exceptions import LdapImportError |
|
22 | 22 | from rhodecode.config.routing import ADMIN_PREFIX |
@@ -129,13 +129,13 b' def ValidRepoUser():' | |||
|
129 | 129 | return _validator |
|
130 | 130 | |
|
131 | 131 | |
|
132 |
def ValidUser |
|
|
132 | def ValidUserGroup(edit=False, old_data={}): | |
|
133 | 133 | class _validator(formencode.validators.FancyValidator): |
|
134 | 134 | messages = { |
|
135 | 135 | 'invalid_group': _(u'Invalid user group name'), |
|
136 |
'group_exist': _(u'User group "%(user |
|
|
137 |
'invalid_user |
|
|
138 |
_(u'user group name may only contain |
|
|
136 | 'group_exist': _(u'User group "%(usergroup)s" already exists'), | |
|
137 | 'invalid_usergroup_name': | |
|
138 | _(u'user group name may only contain alphanumeric ' | |
|
139 | 139 | 'characters underscores, periods or dashes and must begin ' |
|
140 | 140 | 'with alphanumeric character') |
|
141 | 141 | } |
@@ -150,19 +150,19 b' def ValidUsersGroup(edit=False, old_data' | |||
|
150 | 150 | old_ugname = None |
|
151 | 151 | if edit: |
|
152 | 152 | old_id = old_data.get('users_group_id') |
|
153 |
old_ugname = User |
|
|
153 | old_ugname = UserGroup.get(old_id).users_group_name | |
|
154 | 154 | |
|
155 | 155 | if old_ugname != value or not edit: |
|
156 |
is_existing_group = User |
|
|
156 | is_existing_group = UserGroup.get_by_group_name(value, | |
|
157 | 157 | case_insensitive=True) |
|
158 | 158 | if is_existing_group: |
|
159 |
msg = M(self, 'group_exist', state, user |
|
|
159 | msg = M(self, 'group_exist', state, usergroup=value) | |
|
160 | 160 | raise formencode.Invalid(msg, value, state, |
|
161 | 161 | error_dict=dict(users_group_name=msg) |
|
162 | 162 | ) |
|
163 | 163 | |
|
164 | 164 | if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+$', value) is None: |
|
165 |
msg = M(self, 'invalid_user |
|
|
165 | msg = M(self, 'invalid_usergroup_name', state) | |
|
166 | 166 | raise formencode.Invalid(msg, value, state, |
|
167 | 167 | error_dict=dict(users_group_name=msg) |
|
168 | 168 | ) |
@@ -604,9 +604,9 b" def ValidPerms(type_='repo'):" | |||
|
604 | 604 | .filter(User.active == True)\ |
|
605 | 605 | .filter(User.username == k).one() |
|
606 | 606 | if t is 'users_group': |
|
607 |
self.user_db = User |
|
|
608 |
.filter(User |
|
|
609 |
.filter(User |
|
|
607 | self.user_db = UserGroup.query()\ | |
|
608 | .filter(UserGroup.users_group_active == True)\ | |
|
609 | .filter(UserGroup.users_group_name == k).one() | |
|
610 | 610 | |
|
611 | 611 | except Exception: |
|
612 | 612 | log.exception('Updated permission failed') |
@@ -1301,7 +1301,7 b' var MembersAutoComplete = function (divi' | |||
|
1301 | 1301 | return matches; |
|
1302 | 1302 | }; |
|
1303 | 1303 | |
|
1304 |
// Define a custom search function for the DataSource of user |
|
|
1304 | // Define a custom search function for the DataSource of userGroups | |
|
1305 | 1305 | var matchGroups = function (sQuery) { |
|
1306 | 1306 | // Case insensitive matching |
|
1307 | 1307 | var query = sQuery.toLowerCase(); |
@@ -1719,7 +1719,7 b' var PullRequestAutoComplete = function (' | |||
|
1719 | 1719 | return matches; |
|
1720 | 1720 | }; |
|
1721 | 1721 | |
|
1722 |
// Define a custom search function for the DataSource of user |
|
|
1722 | // Define a custom search function for the DataSource of userGroups | |
|
1723 | 1723 | var matchGroups = function (sQuery) { |
|
1724 | 1724 | // Case insensitive matching |
|
1725 | 1725 | var query = sQuery.toLowerCase(); |
@@ -54,7 +54,7 b'' | |||
|
54 | 54 | %endif |
|
55 | 55 | </td> |
|
56 | 56 | <td> |
|
57 |
<span class="delete_icon action_button" onclick="ajaxActionUser |
|
|
57 | <span class="delete_icon action_button" onclick="ajaxActionUserGroup(${g2p.users_group.users_group_id},'${'id%s'%id(g2p.users_group.users_group_name)}')"> | |
|
58 | 58 | ${_('revoke')} |
|
59 | 59 | </span> |
|
60 | 60 | </td> |
@@ -101,7 +101,7 b' function ajaxActionUser(user_id, field_i' | |||
|
101 | 101 | var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData); |
|
102 | 102 | }; |
|
103 | 103 | |
|
104 |
function ajaxActionUser |
|
|
104 | function ajaxActionUserGroup(users_group_id,field_id){ | |
|
105 | 105 | var sUrl = "${h.url('delete_repo_users_group',repo_name=c.repo_name)}"; |
|
106 | 106 | var callback = { |
|
107 | 107 | success:function(o){ |
@@ -51,7 +51,7 b'' | |||
|
51 | 51 | <img class="perm-gravatar" src="${h.url('/images/icons/group.png')}"/>${g2p.users_group.users_group_name} |
|
52 | 52 | </td> |
|
53 | 53 | <td> |
|
54 |
<span class="delete_icon action_button" onclick="ajaxActionUser |
|
|
54 | <span class="delete_icon action_button" onclick="ajaxActionUserGroup(${g2p.users_group.users_group_id},'${'id%s'%id(g2p.users_group.users_group_name)}')"> | |
|
55 | 55 | ${_('revoke')} |
|
56 | 56 | </span> |
|
57 | 57 | </td> |
@@ -105,7 +105,7 b' function ajaxActionUser(user_id, field_i' | |||
|
105 | 105 | var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData); |
|
106 | 106 | }; |
|
107 | 107 | |
|
108 |
function ajaxActionUser |
|
|
108 | function ajaxActionUserGroup(users_group_id,field_id){ | |
|
109 | 109 | var sUrl = "${h.url('delete_repos_group_users_group_perm',group_name=c.repos_group.group_name)}"; |
|
110 | 110 | var callback = { |
|
111 | 111 | success:function(o){ |
@@ -8,7 +8,7 b'' | |||
|
8 | 8 | <%def name="breadcrumbs_links()"> |
|
9 | 9 | ${h.link_to(_('Admin'),h.url('admin_home'))} |
|
10 | 10 | » |
|
11 |
${h.link_to(_('User |
|
|
11 | ${h.link_to(_('UserGroups'),h.url('users_groups'))} | |
|
12 | 12 | » |
|
13 | 13 | ${_('edit')} "${c.users_group.users_group_name}" |
|
14 | 14 | </%def> |
@@ -6,7 +6,7 b' from rhodecode.tests import *' | |||
|
6 | 6 | from rhodecode.lib.compat import json |
|
7 | 7 | from rhodecode.lib.auth import AuthUser |
|
8 | 8 | from rhodecode.model.user import UserModel |
|
9 |
from rhodecode.model.users_group import User |
|
|
9 | from rhodecode.model.users_group import UserGroupModel | |
|
10 | 10 | from rhodecode.model.repo import RepoModel |
|
11 | 11 | from rhodecode.model.meta import Session |
|
12 | 12 | from rhodecode.model.scm import ScmModel |
@@ -43,19 +43,19 b' def api_call(test_obj, params):' | |||
|
43 | 43 | return response |
|
44 | 44 | |
|
45 | 45 | |
|
46 |
TEST_USER |
|
|
46 | TEST_USER_GROUP = 'test_users_group' | |
|
47 | 47 | |
|
48 | 48 | |
|
49 |
def make_users_group(name=TEST_USER |
|
|
50 |
gr = User |
|
|
51 |
User |
|
|
49 | def make_users_group(name=TEST_USER_GROUP): | |
|
50 | gr = UserGroupModel().create(name=name) | |
|
51 | UserGroupModel().add_user_to_group(users_group=gr, | |
|
52 | 52 | user=TEST_USER_ADMIN_LOGIN) |
|
53 | 53 | Session().commit() |
|
54 | 54 | return gr |
|
55 | 55 | |
|
56 | 56 | |
|
57 |
def destroy_users_group(name=TEST_USER |
|
|
58 |
User |
|
|
57 | def destroy_users_group(name=TEST_USER_GROUP): | |
|
58 | UserGroupModel().delete(users_group=name, force=True) | |
|
59 | 59 | Session().commit() |
|
60 | 60 | |
|
61 | 61 | |
@@ -999,10 +999,10 b' class BaseTestApi(object):' | |||
|
999 | 999 | |
|
1000 | 1000 | def test_api_get_users_group(self): |
|
1001 | 1001 | id_, params = _build_data(self.apikey, 'get_users_group', |
|
1002 |
usersgroupid=TEST_USER |
|
|
1002 | usersgroupid=TEST_USER_GROUP) | |
|
1003 | 1003 | response = api_call(self, params) |
|
1004 | 1004 | |
|
1005 |
users_group = User |
|
|
1005 | users_group = UserGroupModel().get_group(TEST_USER_GROUP) | |
|
1006 | 1006 | members = [] |
|
1007 | 1007 | for user in users_group.members: |
|
1008 | 1008 | user = user.user |
@@ -1021,13 +1021,13 b' class BaseTestApi(object):' | |||
|
1021 | 1021 | response = api_call(self, params) |
|
1022 | 1022 | |
|
1023 | 1023 | expected = [] |
|
1024 |
for gr_name in [TEST_USER |
|
|
1025 |
users_group = User |
|
|
1024 | for gr_name in [TEST_USER_GROUP, 'test_users_group2']: | |
|
1025 | users_group = UserGroupModel().get_group(gr_name) | |
|
1026 | 1026 | ret = users_group.get_api_data() |
|
1027 | 1027 | expected.append(ret) |
|
1028 | 1028 | self._compare_ok(id_, expected, given=response.body) |
|
1029 | 1029 | |
|
1030 |
User |
|
|
1030 | UserGroupModel().delete(users_group='test_users_group2') | |
|
1031 | 1031 | Session().commit() |
|
1032 | 1032 | |
|
1033 | 1033 | def test_api_create_users_group(self): |
@@ -1038,7 +1038,7 b' class BaseTestApi(object):' | |||
|
1038 | 1038 | |
|
1039 | 1039 | ret = { |
|
1040 | 1040 | 'msg': 'created new user group `%s`' % group_name, |
|
1041 |
'users_group': jsonify(User |
|
|
1041 | 'users_group': jsonify(UserGroupModel()\ | |
|
1042 | 1042 | .get_by_name(group_name)\ |
|
1043 | 1043 | .get_api_data()) |
|
1044 | 1044 | } |
@@ -1049,13 +1049,13 b' class BaseTestApi(object):' | |||
|
1049 | 1049 | |
|
1050 | 1050 | def test_api_get_users_group_that_exist(self): |
|
1051 | 1051 | id_, params = _build_data(self.apikey, 'create_users_group', |
|
1052 |
group_name=TEST_USER |
|
|
1052 | group_name=TEST_USER_GROUP) | |
|
1053 | 1053 | response = api_call(self, params) |
|
1054 | 1054 | |
|
1055 |
expected = "user group `%s` already exist" % TEST_USER |
|
|
1055 | expected = "user group `%s` already exist" % TEST_USER_GROUP | |
|
1056 | 1056 | self._compare_error(id_, expected, given=response.body) |
|
1057 | 1057 | |
|
1058 |
@mock.patch.object(User |
|
|
1058 | @mock.patch.object(UserGroupModel, 'create', crash) | |
|
1059 | 1059 | def test_api_get_users_group_exception_occurred(self): |
|
1060 | 1060 | group_name = 'exception_happens' |
|
1061 | 1061 | id_, params = _build_data(self.apikey, 'create_users_group', |
@@ -1067,7 +1067,7 b' class BaseTestApi(object):' | |||
|
1067 | 1067 | |
|
1068 | 1068 | def test_api_add_user_to_users_group(self): |
|
1069 | 1069 | gr_name = 'test_group' |
|
1070 |
User |
|
|
1070 | UserGroupModel().create(gr_name) | |
|
1071 | 1071 | Session().commit() |
|
1072 | 1072 | id_, params = _build_data(self.apikey, 'add_user_to_users_group', |
|
1073 | 1073 | usersgroupid=gr_name, |
@@ -1081,7 +1081,7 b' class BaseTestApi(object):' | |||
|
1081 | 1081 | 'success': True} |
|
1082 | 1082 | self._compare_ok(id_, expected, given=response.body) |
|
1083 | 1083 | |
|
1084 |
User |
|
|
1084 | UserGroupModel().delete(users_group=gr_name) | |
|
1085 | 1085 | Session().commit() |
|
1086 | 1086 | |
|
1087 | 1087 | def test_api_add_user_to_users_group_that_doesnt_exist(self): |
@@ -1093,10 +1093,10 b' class BaseTestApi(object):' | |||
|
1093 | 1093 | expected = 'user group `%s` does not exist' % 'false-group' |
|
1094 | 1094 | self._compare_error(id_, expected, given=response.body) |
|
1095 | 1095 | |
|
1096 |
@mock.patch.object(User |
|
|
1096 | @mock.patch.object(UserGroupModel, 'add_user_to_group', crash) | |
|
1097 | 1097 | def test_api_add_user_to_users_group_exception_occurred(self): |
|
1098 | 1098 | gr_name = 'test_group' |
|
1099 |
User |
|
|
1099 | UserGroupModel().create(gr_name) | |
|
1100 | 1100 | Session().commit() |
|
1101 | 1101 | id_, params = _build_data(self.apikey, 'add_user_to_users_group', |
|
1102 | 1102 | usersgroupid=gr_name, |
@@ -1106,13 +1106,13 b' class BaseTestApi(object):' | |||
|
1106 | 1106 | expected = 'failed to add member to user group `%s`' % gr_name |
|
1107 | 1107 | self._compare_error(id_, expected, given=response.body) |
|
1108 | 1108 | |
|
1109 |
User |
|
|
1109 | UserGroupModel().delete(users_group=gr_name) | |
|
1110 | 1110 | Session().commit() |
|
1111 | 1111 | |
|
1112 | 1112 | def test_api_remove_user_from_users_group(self): |
|
1113 | 1113 | gr_name = 'test_group_3' |
|
1114 |
gr = User |
|
|
1115 |
User |
|
|
1114 | gr = UserGroupModel().create(gr_name) | |
|
1115 | UserGroupModel().add_user_to_group(gr, user=TEST_USER_ADMIN_LOGIN) | |
|
1116 | 1116 | Session().commit() |
|
1117 | 1117 | id_, params = _build_data(self.apikey, 'remove_user_from_users_group', |
|
1118 | 1118 | usersgroupid=gr_name, |
@@ -1126,14 +1126,14 b' class BaseTestApi(object):' | |||
|
1126 | 1126 | 'success': True} |
|
1127 | 1127 | self._compare_ok(id_, expected, given=response.body) |
|
1128 | 1128 | |
|
1129 |
User |
|
|
1129 | UserGroupModel().delete(users_group=gr_name) | |
|
1130 | 1130 | Session().commit() |
|
1131 | 1131 | |
|
1132 |
@mock.patch.object(User |
|
|
1132 | @mock.patch.object(UserGroupModel, 'remove_user_from_group', crash) | |
|
1133 | 1133 | def test_api_remove_user_from_users_group_exception_occurred(self): |
|
1134 | 1134 | gr_name = 'test_group_3' |
|
1135 |
gr = User |
|
|
1136 |
User |
|
|
1135 | gr = UserGroupModel().create(gr_name) | |
|
1136 | UserGroupModel().add_user_to_group(gr, user=TEST_USER_ADMIN_LOGIN) | |
|
1137 | 1137 | Session().commit() |
|
1138 | 1138 | id_, params = _build_data(self.apikey, 'remove_user_from_users_group', |
|
1139 | 1139 | usersgroupid=gr_name, |
@@ -1143,7 +1143,7 b' class BaseTestApi(object):' | |||
|
1143 | 1143 | expected = 'failed to remove member from user group `%s`' % gr_name |
|
1144 | 1144 | self._compare_error(id_, expected, given=response.body) |
|
1145 | 1145 | |
|
1146 |
User |
|
|
1146 | UserGroupModel().delete(users_group=gr_name) | |
|
1147 | 1147 | Session().commit() |
|
1148 | 1148 | |
|
1149 | 1149 | @parameterized.expand([('none', 'repository.none'), |
@@ -1224,13 +1224,13 b' class BaseTestApi(object):' | |||
|
1224 | 1224 | def test_api_grant_users_group_permission(self, name, perm): |
|
1225 | 1225 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', |
|
1226 | 1226 | repoid=self.REPO, |
|
1227 |
usersgroupid=TEST_USER |
|
|
1227 | usersgroupid=TEST_USER_GROUP, | |
|
1228 | 1228 | perm=perm) |
|
1229 | 1229 | response = api_call(self, params) |
|
1230 | 1230 | |
|
1231 | 1231 | ret = { |
|
1232 | 1232 | 'msg': 'Granted perm: `%s` for user group: `%s` in repo: `%s`' % ( |
|
1233 |
perm, TEST_USER |
|
|
1233 | perm, TEST_USER_GROUP, self.REPO | |
|
1234 | 1234 | ), |
|
1235 | 1235 | 'success': True |
|
1236 | 1236 | } |
@@ -1241,7 +1241,7 b' class BaseTestApi(object):' | |||
|
1241 | 1241 | perm = 'haha.no.permission' |
|
1242 | 1242 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', |
|
1243 | 1243 | repoid=self.REPO, |
|
1244 |
usersgroupid=TEST_USER |
|
|
1244 | usersgroupid=TEST_USER_GROUP, | |
|
1245 | 1245 | perm=perm) |
|
1246 | 1246 | response = api_call(self, params) |
|
1247 | 1247 | |
@@ -1253,28 +1253,28 b' class BaseTestApi(object):' | |||
|
1253 | 1253 | perm = 'repository.read' |
|
1254 | 1254 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', |
|
1255 | 1255 | repoid=self.REPO, |
|
1256 |
usersgroupid=TEST_USER |
|
|
1256 | usersgroupid=TEST_USER_GROUP, | |
|
1257 | 1257 | perm=perm) |
|
1258 | 1258 | response = api_call(self, params) |
|
1259 | 1259 | |
|
1260 | 1260 | expected = 'failed to edit permission for user group: `%s` in repo: `%s`' % ( |
|
1261 |
TEST_USER |
|
|
1261 | TEST_USER_GROUP, self.REPO | |
|
1262 | 1262 | ) |
|
1263 | 1263 | self._compare_error(id_, expected, given=response.body) |
|
1264 | 1264 | |
|
1265 | 1265 | def test_api_revoke_users_group_permission(self): |
|
1266 | 1266 | RepoModel().grant_users_group_permission(repo=self.REPO, |
|
1267 |
group_name=TEST_USER |
|
|
1267 | group_name=TEST_USER_GROUP, | |
|
1268 | 1268 | perm='repository.read') |
|
1269 | 1269 | Session().commit() |
|
1270 | 1270 | id_, params = _build_data(self.apikey, 'revoke_users_group_permission', |
|
1271 | 1271 | repoid=self.REPO, |
|
1272 |
usersgroupid=TEST_USER |
|
|
1272 | usersgroupid=TEST_USER_GROUP,) | |
|
1273 | 1273 | response = api_call(self, params) |
|
1274 | 1274 | |
|
1275 | 1275 | expected = { |
|
1276 | 1276 | 'msg': 'Revoked perm for user group: `%s` in repo: `%s`' % ( |
|
1277 |
TEST_USER |
|
|
1277 | TEST_USER_GROUP, self.REPO | |
|
1278 | 1278 | ), |
|
1279 | 1279 | 'success': True |
|
1280 | 1280 | } |
@@ -1285,10 +1285,10 b' class BaseTestApi(object):' | |||
|
1285 | 1285 | |
|
1286 | 1286 | id_, params = _build_data(self.apikey, 'revoke_users_group_permission', |
|
1287 | 1287 | repoid=self.REPO, |
|
1288 |
usersgroupid=TEST_USER |
|
|
1288 | usersgroupid=TEST_USER_GROUP,) | |
|
1289 | 1289 | response = api_call(self, params) |
|
1290 | 1290 | |
|
1291 | 1291 | expected = 'failed to edit permission for user group: `%s` in repo: `%s`' % ( |
|
1292 |
TEST_USER |
|
|
1292 | TEST_USER_GROUP, self.REPO | |
|
1293 | 1293 | ) |
|
1294 | 1294 | self._compare_error(id_, expected, given=response.body) |
@@ -1,7 +1,7 b'' | |||
|
1 | 1 | from rhodecode.tests import * |
|
2 |
from rhodecode.model.db import User |
|
|
2 | from rhodecode.model.db import UserGroup, UserGroupToPerm, Permission | |
|
3 | 3 | |
|
4 |
TEST_USER |
|
|
4 | TEST_USER_GROUP = 'admins_test' | |
|
5 | 5 | |
|
6 | 6 | |
|
7 | 7 | class TestAdminUsersGroupsController(TestController): |
@@ -15,14 +15,14 b' class TestAdminUsersGroupsController(Tes' | |||
|
15 | 15 | |
|
16 | 16 | def test_create(self): |
|
17 | 17 | self.log_user() |
|
18 |
users_group_name = TEST_USER |
|
|
18 | users_group_name = TEST_USER_GROUP | |
|
19 | 19 | response = self.app.post(url('users_groups'), |
|
20 | 20 | {'users_group_name': users_group_name, |
|
21 | 21 | 'active':True}) |
|
22 | 22 | response.follow() |
|
23 | 23 | |
|
24 | 24 | self.checkSessionFlash(response, |
|
25 |
'created user group %s' % TEST_USER |
|
|
25 | 'created user group %s' % TEST_USER_GROUP) | |
|
26 | 26 | |
|
27 | 27 | def test_new(self): |
|
28 | 28 | response = self.app.get(url('new_users_group')) |
@@ -39,7 +39,7 b' class TestAdminUsersGroupsController(Tes' | |||
|
39 | 39 | |
|
40 | 40 | def test_delete(self): |
|
41 | 41 | self.log_user() |
|
42 |
users_group_name = TEST_USER |
|
|
42 | users_group_name = TEST_USER_GROUP + 'another' | |
|
43 | 43 | response = self.app.post(url('users_groups'), |
|
44 | 44 | {'users_group_name':users_group_name, |
|
45 | 45 | 'active':True}) |
@@ -48,27 +48,27 b' class TestAdminUsersGroupsController(Tes' | |||
|
48 | 48 | self.checkSessionFlash(response, |
|
49 | 49 | 'created user group %s' % users_group_name) |
|
50 | 50 | |
|
51 |
gr = self.Session.query(User |
|
|
52 |
.filter(User |
|
|
51 | gr = self.Session.query(UserGroup)\ | |
|
52 | .filter(UserGroup.users_group_name == | |
|
53 | 53 | users_group_name).one() |
|
54 | 54 | |
|
55 | 55 | response = self.app.delete(url('users_group', id=gr.users_group_id)) |
|
56 | 56 | |
|
57 |
gr = self.Session.query(User |
|
|
58 |
.filter(User |
|
|
57 | gr = self.Session.query(UserGroup)\ | |
|
58 | .filter(UserGroup.users_group_name == | |
|
59 | 59 | users_group_name).scalar() |
|
60 | 60 | |
|
61 | 61 | self.assertEqual(gr, None) |
|
62 | 62 | |
|
63 | 63 | def test_enable_repository_read_on_group(self): |
|
64 | 64 | self.log_user() |
|
65 |
users_group_name = TEST_USER |
|
|
65 | users_group_name = TEST_USER_GROUP + 'another2' | |
|
66 | 66 | response = self.app.post(url('users_groups'), |
|
67 | 67 | {'users_group_name': users_group_name, |
|
68 | 68 | 'active': True}) |
|
69 | 69 | response.follow() |
|
70 | 70 | |
|
71 |
ug = User |
|
|
71 | ug = UserGroup.get_by_group_name(users_group_name) | |
|
72 | 72 | self.checkSessionFlash(response, |
|
73 | 73 | 'created user group %s' % users_group_name) |
|
74 | 74 | ## ENABLE REPO CREATE ON A GROUP |
@@ -76,13 +76,13 b' class TestAdminUsersGroupsController(Tes' | |||
|
76 | 76 | {'create_repo_perm': True}) |
|
77 | 77 | |
|
78 | 78 | response.follow() |
|
79 |
ug = User |
|
|
79 | ug = UserGroup.get_by_group_name(users_group_name) | |
|
80 | 80 | p = Permission.get_by_key('hg.create.repository') |
|
81 | 81 | p2 = Permission.get_by_key('hg.fork.none') |
|
82 | 82 | # check if user has this perms, they should be here since |
|
83 | 83 | # defaults are on |
|
84 |
perms = User |
|
|
85 |
.filter(User |
|
|
84 | perms = UserGroupToPerm.query()\ | |
|
85 | .filter(UserGroupToPerm.users_group == ug).all() | |
|
86 | 86 | |
|
87 | 87 | self.assertEqual( |
|
88 | 88 | [[x.users_group_id, x.permission_id, ] for x in perms], |
@@ -95,13 +95,13 b' class TestAdminUsersGroupsController(Tes' | |||
|
95 | 95 | {}) |
|
96 | 96 | |
|
97 | 97 | response.follow() |
|
98 |
ug = User |
|
|
98 | ug = UserGroup.get_by_group_name(users_group_name) | |
|
99 | 99 | p = Permission.get_by_key('hg.create.none') |
|
100 | 100 | p2 = Permission.get_by_key('hg.fork.none') |
|
101 | 101 | # check if user has this perms, they should be here since |
|
102 | 102 | # defaults are on |
|
103 |
perms = User |
|
|
104 |
.filter(User |
|
|
103 | perms = UserGroupToPerm.query()\ | |
|
104 | .filter(UserGroupToPerm.users_group == ug).all() | |
|
105 | 105 | |
|
106 | 106 | self.assertEqual( |
|
107 | 107 | sorted([[x.users_group_id, x.permission_id, ] for x in perms]), |
@@ -110,18 +110,18 b' class TestAdminUsersGroupsController(Tes' | |||
|
110 | 110 | ) |
|
111 | 111 | |
|
112 | 112 | # DELETE ! |
|
113 |
ug = User |
|
|
113 | ug = UserGroup.get_by_group_name(users_group_name) | |
|
114 | 114 | ugid = ug.users_group_id |
|
115 | 115 | response = self.app.delete(url('users_group', id=ug.users_group_id)) |
|
116 | 116 | response = response.follow() |
|
117 |
gr = self.Session.query(User |
|
|
118 |
.filter(User |
|
|
117 | gr = self.Session.query(UserGroup)\ | |
|
118 | .filter(UserGroup.users_group_name == | |
|
119 | 119 | users_group_name).scalar() |
|
120 | 120 | |
|
121 | 121 | self.assertEqual(gr, None) |
|
122 | 122 | p = Permission.get_by_key('hg.create.repository') |
|
123 |
perms = User |
|
|
124 |
.filter(User |
|
|
123 | perms = UserGroupToPerm.query()\ | |
|
124 | .filter(UserGroupToPerm.users_group_id == ugid).all() | |
|
125 | 125 | perms = [[x.users_group_id, |
|
126 | 126 | x.permission_id, ] for x in perms] |
|
127 | 127 | self.assertEqual( |
@@ -131,13 +131,13 b' class TestAdminUsersGroupsController(Tes' | |||
|
131 | 131 | |
|
132 | 132 | def test_enable_repository_fork_on_group(self): |
|
133 | 133 | self.log_user() |
|
134 |
users_group_name = TEST_USER |
|
|
134 | users_group_name = TEST_USER_GROUP + 'another2' | |
|
135 | 135 | response = self.app.post(url('users_groups'), |
|
136 | 136 | {'users_group_name': users_group_name, |
|
137 | 137 | 'active': True}) |
|
138 | 138 | response.follow() |
|
139 | 139 | |
|
140 |
ug = User |
|
|
140 | ug = UserGroup.get_by_group_name(users_group_name) | |
|
141 | 141 | self.checkSessionFlash(response, |
|
142 | 142 | 'created user group %s' % users_group_name) |
|
143 | 143 | ## ENABLE REPO CREATE ON A GROUP |
@@ -145,13 +145,13 b' class TestAdminUsersGroupsController(Tes' | |||
|
145 | 145 | {'fork_repo_perm': True}) |
|
146 | 146 | |
|
147 | 147 | response.follow() |
|
148 |
ug = User |
|
|
148 | ug = UserGroup.get_by_group_name(users_group_name) | |
|
149 | 149 | p = Permission.get_by_key('hg.create.none') |
|
150 | 150 | p2 = Permission.get_by_key('hg.fork.repository') |
|
151 | 151 | # check if user has this perms, they should be here since |
|
152 | 152 | # defaults are on |
|
153 |
perms = User |
|
|
154 |
.filter(User |
|
|
153 | perms = UserGroupToPerm.query()\ | |
|
154 | .filter(UserGroupToPerm.users_group == ug).all() | |
|
155 | 155 | |
|
156 | 156 | self.assertEqual( |
|
157 | 157 | [[x.users_group_id, x.permission_id, ] for x in perms], |
@@ -164,13 +164,13 b' class TestAdminUsersGroupsController(Tes' | |||
|
164 | 164 | {}) |
|
165 | 165 | |
|
166 | 166 | response.follow() |
|
167 |
ug = User |
|
|
167 | ug = UserGroup.get_by_group_name(users_group_name) | |
|
168 | 168 | p = Permission.get_by_key('hg.create.none') |
|
169 | 169 | p2 = Permission.get_by_key('hg.fork.none') |
|
170 | 170 | # check if user has this perms, they should be here since |
|
171 | 171 | # defaults are on |
|
172 |
perms = User |
|
|
173 |
.filter(User |
|
|
172 | perms = UserGroupToPerm.query()\ | |
|
173 | .filter(UserGroupToPerm.users_group == ug).all() | |
|
174 | 174 | |
|
175 | 175 | self.assertEqual( |
|
176 | 176 | [[x.users_group_id, x.permission_id, ] for x in perms], |
@@ -179,18 +179,18 b' class TestAdminUsersGroupsController(Tes' | |||
|
179 | 179 | ) |
|
180 | 180 | |
|
181 | 181 | # DELETE ! |
|
182 |
ug = User |
|
|
182 | ug = UserGroup.get_by_group_name(users_group_name) | |
|
183 | 183 | ugid = ug.users_group_id |
|
184 | 184 | response = self.app.delete(url('users_group', id=ug.users_group_id)) |
|
185 | 185 | response = response.follow() |
|
186 |
gr = self.Session.query(User |
|
|
187 |
.filter(User |
|
|
186 | gr = self.Session.query(UserGroup)\ | |
|
187 | .filter(UserGroup.users_group_name == | |
|
188 | 188 | users_group_name).scalar() |
|
189 | 189 | |
|
190 | 190 | self.assertEqual(gr, None) |
|
191 | 191 | p = Permission.get_by_key('hg.fork.repository') |
|
192 |
perms = User |
|
|
193 |
.filter(User |
|
|
192 | perms = UserGroupToPerm.query()\ | |
|
193 | .filter(UserGroupToPerm.users_group_id == ugid).all() | |
|
194 | 194 | perms = [[x.users_group_id, |
|
195 | 195 | x.permission_id, ] for x in perms] |
|
196 | 196 | self.assertEqual( |
@@ -4,11 +4,11 b' from rhodecode.tests import *' | |||
|
4 | 4 | from rhodecode.tests.models.common import _make_group |
|
5 | 5 | from rhodecode.model.repos_group import ReposGroupModel |
|
6 | 6 | from rhodecode.model.repo import RepoModel |
|
7 |
from rhodecode.model.db import RepoGroup, User, User |
|
|
7 | from rhodecode.model.db import RepoGroup, User, UserGroupRepoGroupToPerm | |
|
8 | 8 | from rhodecode.model.user import UserModel |
|
9 | 9 | |
|
10 | 10 | from rhodecode.model.meta import Session |
|
11 |
from rhodecode.model.users_group import User |
|
|
11 | from rhodecode.model.users_group import UserGroupModel | |
|
12 | 12 | from rhodecode.lib.auth import AuthUser |
|
13 | 13 | from rhodecode.tests.api.api_base import create_repo |
|
14 | 14 | |
@@ -51,7 +51,7 b' class TestPermissions(unittest.TestCase)' | |||
|
51 | 51 | ReposGroupModel().delete(self.g2.group_id) |
|
52 | 52 | |
|
53 | 53 | if hasattr(self, 'ug1'): |
|
54 |
User |
|
|
54 | UserGroupModel().delete(self.ug1, force=True) | |
|
55 | 55 | |
|
56 | 56 | Session().commit() |
|
57 | 57 | |
@@ -124,10 +124,10 b' class TestPermissions(unittest.TestCase)' | |||
|
124 | 124 | |
|
125 | 125 | def test_propagated_permission_from_users_group_by_explicit_perms_exist(self): |
|
126 | 126 | # make group |
|
127 |
self.ug1 = User |
|
|
127 | self.ug1 = UserGroupModel().create('G1') | |
|
128 | 128 | # add user to group |
|
129 | 129 | |
|
130 |
User |
|
|
130 | UserGroupModel().add_user_to_group(self.ug1, self.u1) | |
|
131 | 131 | |
|
132 | 132 | # set permission to lower |
|
133 | 133 | new_perm = 'repository.none' |
@@ -158,10 +158,10 b' class TestPermissions(unittest.TestCase)' | |||
|
158 | 158 | |
|
159 | 159 | def test_propagated_permission_from_users_group(self): |
|
160 | 160 | # make group |
|
161 |
self.ug1 = User |
|
|
161 | self.ug1 = UserGroupModel().create('G1') | |
|
162 | 162 | # add user to group |
|
163 | 163 | |
|
164 |
User |
|
|
164 | UserGroupModel().add_user_to_group(self.ug1, self.u3) | |
|
165 | 165 | |
|
166 | 166 | # grant perm for group this should override default permission from user |
|
167 | 167 | new_perm_gr = 'repository.write' |
@@ -183,9 +183,9 b' class TestPermissions(unittest.TestCase)' | |||
|
183 | 183 | |
|
184 | 184 | def test_propagated_permission_from_users_group_lower_weight(self): |
|
185 | 185 | # make group |
|
186 |
self.ug1 = User |
|
|
186 | self.ug1 = UserGroupModel().create('G1') | |
|
187 | 187 | # add user to group |
|
188 |
User |
|
|
188 | UserGroupModel().add_user_to_group(self.ug1, self.u1) | |
|
189 | 189 | |
|
190 | 190 | # set permission to lower |
|
191 | 191 | new_perm_h = 'repository.write' |
@@ -299,13 +299,13 b' class TestPermissions(unittest.TestCase)' | |||
|
299 | 299 | user=self.anon, |
|
300 | 300 | perm='group.none') |
|
301 | 301 | # make group |
|
302 |
self.ug1 = User |
|
|
302 | self.ug1 = UserGroupModel().create('G1') | |
|
303 | 303 | # add user to group |
|
304 |
User |
|
|
304 | UserGroupModel().add_user_to_group(self.ug1, self.u1) | |
|
305 | 305 | Session().commit() |
|
306 | 306 | |
|
307 | 307 | # check if user is in the group |
|
308 |
membrs = [x.user_id for x in User |
|
|
308 | membrs = [x.user_id for x in UserGroupModel().get(self.ug1.users_group_id).members] | |
|
309 | 309 | self.assertEqual(membrs, [self.u1.user_id]) |
|
310 | 310 | # add some user to that group |
|
311 | 311 | |
@@ -324,9 +324,9 b' class TestPermissions(unittest.TestCase)' | |||
|
324 | 324 | perm='group.read') |
|
325 | 325 | Session().commit() |
|
326 | 326 | # check if the |
|
327 |
obj = Session().query(User |
|
|
328 |
.filter(User |
|
|
329 |
.filter(User |
|
|
327 | obj = Session().query(UserGroupRepoGroupToPerm)\ | |
|
328 | .filter(UserGroupRepoGroupToPerm.group == self.g1)\ | |
|
329 | .filter(UserGroupRepoGroupToPerm.users_group == self.ug1)\ | |
|
330 | 330 | .scalar() |
|
331 | 331 | self.assertEqual(obj.permission.permission_name, 'group.read') |
|
332 | 332 | |
@@ -440,9 +440,9 b' class TestPermissions(unittest.TestCase)' | |||
|
440 | 440 | self.assertEqual(u1_auth.permissions['repositories']['myownrepo'], |
|
441 | 441 | 'repository.admin') |
|
442 | 442 | #set his permission as user group, he should still be admin |
|
443 |
self.ug1 = User |
|
|
443 | self.ug1 = UserGroupModel().create('G1') | |
|
444 | 444 | # add user to group |
|
445 |
User |
|
|
445 | UserGroupModel().add_user_to_group(self.ug1, self.u1) | |
|
446 | 446 | RepoModel().grant_users_group_permission(repo, group_name=self.ug1, |
|
447 | 447 | perm='repository.none') |
|
448 | 448 |
@@ -1,12 +1,12 b'' | |||
|
1 | 1 | import unittest |
|
2 | 2 | from rhodecode.tests import * |
|
3 | 3 | |
|
4 |
from rhodecode.model.db import User, User |
|
|
4 | from rhodecode.model.db import User, UserGroup, UserGroupMember, UserEmailMap,\ | |
|
5 | 5 | Permission |
|
6 | 6 | from rhodecode.model.user import UserModel |
|
7 | 7 | |
|
8 | 8 | from rhodecode.model.meta import Session |
|
9 |
from rhodecode.model.users_group import User |
|
|
9 | from rhodecode.model.users_group import UserGroupModel | |
|
10 | 10 | |
|
11 | 11 | |
|
12 | 12 | class TestUser(unittest.TestCase): |
@@ -23,18 +23,18 b' class TestUser(unittest.TestCase):' | |||
|
23 | 23 | self.assertEqual(User.get_by_username(u'test_user'), usr) |
|
24 | 24 | |
|
25 | 25 | # make user group |
|
26 |
users_group = User |
|
|
26 | users_group = UserGroupModel().create('some_example_group') | |
|
27 | 27 | Session().commit() |
|
28 | 28 | |
|
29 |
User |
|
|
29 | UserGroupModel().add_user_to_group(users_group, usr) | |
|
30 | 30 | Session().commit() |
|
31 | 31 | |
|
32 |
self.assertEqual(User |
|
|
33 |
self.assertEqual(User |
|
|
32 | self.assertEqual(UserGroup.get(users_group.users_group_id), users_group) | |
|
33 | self.assertEqual(UserGroupMember.query().count(), 1) | |
|
34 | 34 | UserModel().delete(usr.user_id) |
|
35 | 35 | Session().commit() |
|
36 | 36 | |
|
37 |
self.assertEqual(User |
|
|
37 | self.assertEqual(UserGroupMember.query().all(), []) | |
|
38 | 38 | |
|
39 | 39 | def test_additonal_email_as_main(self): |
|
40 | 40 | usr = UserModel().create_or_update(username=u'test_user', |
@@ -10,7 +10,7 b' from rhodecode.model.meta import Session' | |||
|
10 | 10 | from nose.tools import with_setup |
|
11 | 11 | from rhodecode.tests.models.common import _create_project_tree, check_tree_perms, \ |
|
12 | 12 | _get_perms, _check_expected_count, expected_count, _destroy_project_tree |
|
13 |
from rhodecode.model.users_group import User |
|
|
13 | from rhodecode.model.users_group import UserGroupModel | |
|
14 | 14 | from rhodecode.model.repo import RepoModel |
|
15 | 15 | |
|
16 | 16 | |
@@ -40,10 +40,10 b' def setup_module():' | |||
|
40 | 40 | Session().commit() |
|
41 | 41 | test_u2_id = test_u2.user_id |
|
42 | 42 | |
|
43 |
gr1 = User |
|
|
43 | gr1 = UserGroupModel().create(name='perms_group_1') | |
|
44 | 44 | Session().commit() |
|
45 | 45 | test_u2_gr_id = gr1.users_group_id |
|
46 |
User |
|
|
46 | UserGroupModel().add_user_to_group(gr1, user=test_u2_id) | |
|
47 | 47 | Session().commit() |
|
48 | 48 | |
|
49 | 49 | _get_repo_perms = functools.partial(_get_perms, key='repositories', |
@@ -5,7 +5,7 b' import formencode' | |||
|
5 | 5 | from rhodecode.tests import * |
|
6 | 6 | |
|
7 | 7 | from rhodecode.model import validators as v |
|
8 |
from rhodecode.model.users_group import User |
|
|
8 | from rhodecode.model.users_group import UserGroupModel | |
|
9 | 9 | |
|
10 | 10 | from rhodecode.model.meta import Session |
|
11 | 11 | from rhodecode.model.repos_group import ReposGroupModel |
@@ -51,25 +51,25 b' class TestReposGroups(unittest.TestCase)' | |||
|
51 | 51 | self.assertEqual(TEST_USER_ADMIN_LOGIN, |
|
52 | 52 | validator.to_python(TEST_USER_ADMIN_LOGIN)) |
|
53 | 53 | |
|
54 |
def test_ValidUser |
|
|
55 |
validator = v.ValidUser |
|
|
54 | def test_ValidUserGroup(self): | |
|
55 | validator = v.ValidUserGroup() | |
|
56 | 56 | self.assertRaises(formencode.Invalid, validator.to_python, 'default') |
|
57 | 57 | self.assertRaises(formencode.Invalid, validator.to_python, '.,') |
|
58 | 58 | |
|
59 |
gr = User |
|
|
60 |
gr2 = User |
|
|
59 | gr = UserGroupModel().create('test') | |
|
60 | gr2 = UserGroupModel().create('tes2') | |
|
61 | 61 | Session.commit() |
|
62 | 62 | self.assertRaises(formencode.Invalid, validator.to_python, 'test') |
|
63 | 63 | assert gr.users_group_id != None |
|
64 |
validator = v.ValidUser |
|
|
64 | validator = v.ValidUserGroup(edit=True, | |
|
65 | 65 | old_data={'users_group_id': |
|
66 | 66 | gr2.users_group_id}) |
|
67 | 67 | |
|
68 | 68 | self.assertRaises(formencode.Invalid, validator.to_python, 'test') |
|
69 | 69 | self.assertRaises(formencode.Invalid, validator.to_python, 'TesT') |
|
70 | 70 | self.assertRaises(formencode.Invalid, validator.to_python, 'TEST') |
|
71 |
User |
|
|
72 |
User |
|
|
71 | UserGroupModel().delete(gr) | |
|
72 | UserGroupModel().delete(gr2) | |
|
73 | 73 | Session.commit() |
|
74 | 74 | |
|
75 | 75 | def test_ValidReposGroup(self): |
General Comments 0
You need to be logged in to leave comments.
Login now