##// END OF EJS Templates
further cleanup of UsersGroup...
Mads Kiilerich -
r3417:fa6ba672 beta
parent child Browse files
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 UsersGroupsAssignedException
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 UsersGroupModel
41 from rhodecode.model.users_group import UserGroupModel
42 42
43 from rhodecode.model.db import User, UsersGroup, UsersGroupToPerm,\
44 UsersGroupRepoToPerm, UsersGroupRepoGroupToPerm
45 from rhodecode.model.forms import UsersGroupForm
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 = UsersGroup().query().all()
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 = UsersGroupForm()()
77 users_group_form = UserGroupForm()()
78 78 try:
79 79 form_result = users_group_form.to_python(dict(request.POST))
80 UsersGroupModel().create(name=form_result['users_group_name'],
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 = UsersGroupRepoToPerm.query()\
114 .options(joinedload(UsersGroupRepoToPerm.permission))\
115 .options(joinedload(UsersGroupRepoToPerm.repository))\
116 .filter(UsersGroupRepoToPerm.users_group_id == id)\
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 = UsersGroupRepoGroupToPerm.query()\
124 .options(joinedload(UsersGroupRepoGroupToPerm.permission))\
125 .options(joinedload(UsersGroupRepoGroupToPerm.group))\
126 .filter(UsersGroupRepoGroupToPerm.users_group_id == id)\
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 = UsersGroup.get_or_404(id)
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 = UsersGroupForm(edit=True,
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 UsersGroupModel().update(c.users_group, form_result)
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 = UsersGroupModel()
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 = UsersGroup.get_or_404(id)
199 usr_gr = UserGroup.get_or_404(id)
200 200 try:
201 UsersGroupModel().delete(usr_gr)
201 UserGroupModel().delete(usr_gr)
202 202 Session().commit()
203 203 h.flash(_('successfully deleted user group'), category='success')
204 except UsersGroupsAssignedException, e:
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 = UsersGroup.get_or_404(id)
220 c.users_group = UserGroup.get_or_404(id)
221 221 self._load_data(id)
222 222
223 ug_model = UsersGroupModel()
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 = UsersGroup.get_or_404(id)
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 usersgroup_model = UsersGroupModel()
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 usersgroup_model.revoke_perm(id, 'hg.create.none')
256 usersgroup_model.grant_perm(id, 'hg.create.repository')
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 usersgroup_model.revoke_perm(id, 'hg.create.repository')
261 usersgroup_model.grant_perm(id, 'hg.create.none')
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 usersgroup_model.revoke_perm(id, 'hg.fork.none')
267 usersgroup_model.grant_perm(id, 'hg.fork.repository')
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 usersgroup_model.revoke_perm(id, 'hg.fork.repository')
272 usersgroup_model.grant_perm(id, 'hg.fork.none')
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 UsersGroupModel
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 = UsersGroupModel().get_group(usersgroupid)
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 UsersGroupModel().get_all():
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 UsersGroupModel().get_by_name(group_name):
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 = UsersGroupModel().create(name=group_name, active=active)
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 = UsersGroupModel().add_user_to_group(users_group, 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 = UsersGroupModel().remove_user_from_group(users_group,
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 UsersGroupsAssignedException
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('UsersGroupMember', cascade='all')
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 UsersGroup(Base, BaseModel):
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('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
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 = UsersGroupMember(users_group_id, u_id)
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 = UsersGroupRepoToPerm.query()\
446 .filter(UsersGroupRepoToPerm.users_group_id ==
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 UsersGroupsAssignedException('RepoGroup assigned to %s' %
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 UsersGroupMember(Base, BaseModel):
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('UsersGroup')
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 = UsersGroupMember()
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('UsersGroupRepoToPerm', cascade='all')
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 UsersGroupRepoToPerm(Base, BaseModel):
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('UsersGroup')
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 UsersGroupToPerm(Base, BaseModel):
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('UsersGroup')
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('UsersGroupMember', cascade='all')
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 UsersGroup(Base, BaseModel):
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('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
438 users_group_to_perm = relationship('UsersGroupToPerm', cascade='all')
439 users_group_repo_to_perm = relationship('UsersGroupRepoToPerm', cascade='all')
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 UsersGroupMember(Base, BaseModel):
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('UsersGroup')
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('UsersGroupRepoToPerm', cascade='all')
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('UsersGroupRepoGroupToPerm', cascade='all')
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 UsersGroupRepoToPerm(Base, BaseModel):
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('UsersGroup')
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 UsersGroupToPerm(Base, BaseModel):
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('UsersGroup')
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 UsersGroupRepoGroupToPerm(Base, BaseModel):
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('UsersGroup')
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('UsersGroupMember', cascade='all')
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 UsersGroup(Base, BaseModel):
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('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
537 users_group_to_perm = relationship('UsersGroupToPerm', cascade='all')
538 users_group_repo_to_perm = relationship('UsersGroupRepoToPerm', cascade='all')
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 UsersGroupMember(Base, BaseModel):
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('UsersGroup')
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('UsersGroupRepoToPerm', cascade='all')
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('UsersGroupRepoGroupToPerm', cascade='all')
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 UsersGroupRepoToPerm(Base, BaseModel):
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('UsersGroup')
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 UsersGroupToPerm(Base, BaseModel):
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('UsersGroup')
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 UsersGroupRepoGroupToPerm(Base, BaseModel):
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('UsersGroup')
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('UsersGroupMember', cascade='all')
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 UsersGroup(Base, BaseModel):
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('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
557 users_group_to_perm = relationship('UsersGroupToPerm', cascade='all')
558 users_group_repo_to_perm = relationship('UsersGroupRepoToPerm', cascade='all')
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 UsersGroupMember(Base, BaseModel):
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('UsersGroup')
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('UsersGroupRepoToPerm', cascade='all')
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('UsersGroupRepoGroupToPerm', cascade='all')
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 UsersGroupRepoToPerm(Base, BaseModel):
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('UsersGroup')
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 UsersGroupToPerm(Base, BaseModel):
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('UsersGroup')
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 UsersGroupRepoGroupToPerm(Base, BaseModel):
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('UsersGroup')
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('UsersGroupMember', cascade='all')
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 UsersGroup(Base, BaseModel):
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('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
591 users_group_to_perm = relationship('UsersGroupToPerm', cascade='all')
592 users_group_repo_to_perm = relationship('UsersGroupRepoToPerm', cascade='all')
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 UsersGroupMember(Base, BaseModel):
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('UsersGroup')
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('UsersGroupRepoToPerm', cascade='all')
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('UsersGroupRepoGroupToPerm', cascade='all')
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 UsersGroupRepoToPerm(Base, BaseModel):
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('UsersGroup')
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 UsersGroupToPerm(Base, BaseModel):
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('UsersGroup')
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 UsersGroupRepoGroupToPerm(Base, BaseModel):
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('UsersGroup')
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 UsersGroup
38 UsersGroup().__table__.create()
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 UsersGroupMember
44 UsersGroupMember().__table__.create()
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 UsersGroupRepoToPerm
50 UsersGroupRepoToPerm().__table__.create()
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 UsersGroupToPerm
56 UsersGroupToPerm().__table__.create()
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 UsersGroupRepoGroupToPerm
25 UsersGroupRepoGroupToPerm().__table__.create()
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 UsersGroupToPerm
49 tbl = UsersGroupToPerm().__table__
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 UsersGroup
78 tbl = UsersGroup.__table__
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 UsersGroupsAssignedException(Exception):
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('UsersGroupMember', cascade='all')
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 UsersGroup(Base, BaseModel):
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('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
620 users_group_to_perm = relationship('UsersGroupToPerm', cascade='all')
621 users_group_repo_to_perm = relationship('UsersGroupRepoToPerm', cascade='all')
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 UsersGroupMember(Base, BaseModel):
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('UsersGroup')
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('UsersGroupRepoToPerm', cascade='all')
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('UsersGroupRepoGroupToPerm', cascade='all')
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 UsersGroupRepoToPerm(Base, BaseModel):
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('UsersGroup')
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 UsersGroupToPerm(Base, BaseModel):
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('UsersGroup')
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 UsersGroupRepoGroupToPerm(Base, BaseModel):
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('UsersGroup')
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 UsersGroupForm(edit=False, old_data={}, available_members=[]):
98 class _UsersGroupForm(formencode.Schema):
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.ValidUsersGroup(edit, old_data)
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 _UsersGroupForm
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, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi, RepoGroup,\
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(UsersGroup, users_group,
58 callback=UsersGroup.get_by_group_name)
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(UsersGroup)\
124 .filter(UsersGroup.users_group_active == True).all()
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 = UsersGroupRepoToPerm.query()\
419 .filter(UsersGroupRepoToPerm.repository == repo).all()
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 UsersGroupRepoToPerm.create(perm.users_group, new_repo,
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(UsersGroupRepoToPerm)\
566 .filter(UsersGroupRepoToPerm.users_group == group_name)\
567 .filter(UsersGroupRepoToPerm.repository == repo)\
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 = UsersGroupRepoToPerm()
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(UsersGroupRepoToPerm)\
592 .filter(UsersGroupRepoToPerm.repository == repo)\
593 .filter(UsersGroupRepoToPerm.users_group == group_name)\
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, UsersGroupRepoToPerm, \
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 UsersGroupRepoToPerm.query() \
68 .filter(UsersGroupRepoToPerm.users_group == users_group) \
69 .filter(UsersGroupRepoToPerm.repository == repository) \
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 = UsersGroupRepoToPerm()
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, UsersGroupRepoGroupToPerm, UsersGroup, Repository
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(UsersGroup, users_group,
47 callback=UsersGroup.get_by_group_name)
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(UsersGroupRepoGroupToPerm)\
394 .filter(UsersGroupRepoGroupToPerm.group == repos_group)\
395 .filter(UsersGroupRepoGroupToPerm.users_group == group_name)\
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 = UsersGroupRepoGroupToPerm()
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(UsersGroupRepoGroupToPerm)\
421 .filter(UsersGroupRepoGroupToPerm.group == repos_group)\
422 .filter(UsersGroupRepoGroupToPerm.users_group == group_name)\
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, UsersGroupRepoToPerm, UsersGroupToPerm, UsersGroupMember, \
41 Notification, RepoGroup, UserRepoGroupToPerm, UsersGroupRepoGroupToPerm, \
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(UsersGroupToPerm)\
517 .options(joinedload(UsersGroupToPerm.permission))\
518 .join((UsersGroupMember, UsersGroupToPerm.users_group_id ==
519 UsersGroupMember.users_group_id))\
520 .filter(UsersGroupMember.user_id == uid)\
521 .order_by(UsersGroupToPerm.users_group_id)\
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(UsersGroupRepoToPerm, Permission, Repository,)\
565 .join((Repository, UsersGroupRepoToPerm.repository_id ==
564 self.sa.query(UserGroupRepoToPerm, Permission, Repository,)\
565 .join((Repository, UserGroupRepoToPerm.repository_id ==
566 566 Repository.repo_id))\
567 .join((Permission, UsersGroupRepoToPerm.permission_id ==
567 .join((Permission, UserGroupRepoToPerm.permission_id ==
568 568 Permission.permission_id))\
569 .join((UsersGroupMember, UsersGroupRepoToPerm.users_group_id ==
570 UsersGroupMember.users_group_id))\
571 .filter(UsersGroupMember.user_id == uid)\
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.UsersGroupRepoToPerm.repository.repo_name
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(UsersGroupRepoGroupToPerm, Permission, RepoGroup)\
623 .join((RepoGroup, UsersGroupRepoGroupToPerm.group_id == RepoGroup.group_id))\
624 .join((Permission, UsersGroupRepoGroupToPerm.permission_id
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((UsersGroupMember, UsersGroupRepoGroupToPerm.users_group_id
627 == UsersGroupMember.users_group_id))\
628 .filter(UsersGroupMember.user_id == uid)\
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.UsersGroupRepoGroupToPerm.group.group_name
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 UsersGroupMember, UsersGroup,\
32 UsersGroupRepoToPerm, Permission, UsersGroupToPerm, User
33 from rhodecode.lib.exceptions import UsersGroupsAssignedException
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 UsersGroupModel(BaseModel):
38 class UserGroupModel(BaseModel):
39 39
40 cls = UsersGroup
40 cls = UserGroup
41 41
42 42 def __get_users_group(self, users_group):
43 return self._get_instance(UsersGroup, users_group,
44 callback=UsersGroup.get_by_group_name)
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 UsersGroup.get(users_group_id)
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 UsersGroup.get_by_group_name(name, cache, case_insensitive)
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 = UsersGroup()
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 = UsersGroupMember(users_group.users_group_id, u_id)
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 = UsersGroupRepoToPerm.query()\
103 .filter(UsersGroupRepoToPerm.users_group == users_group).all()
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 UsersGroupsAssignedException('RepoGroup assigned to %s' %
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 = UsersGroupMember()
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 UsersGroupToPerm.query()\
164 .filter(UsersGroupToPerm.users_group == users_group)\
165 .filter(UsersGroupToPerm.permission == perm).scalar() is not None
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 = UsersGroupToPerm.query()\
173 .filter(UsersGroupToPerm.users_group == users_group)\
174 .filter(UsersGroupToPerm.permission == perm)\
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 = UsersGroupToPerm()
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 = UsersGroupToPerm.query()\
189 .filter(UsersGroupToPerm.users_group == users_group)\
190 .filter(UsersGroupToPerm.permission == perm).scalar()
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, UsersGroup, 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 ValidUsersGroup(edit=False, old_data={}):
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 "%(usersgroup)s" already exists'),
137 'invalid_usersgroup_name':
138 _(u'user group name may only contain alphanumeric '
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 = UsersGroup.get(old_id).users_group_name
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 = UsersGroup.get_by_group_name(value,
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, usersgroup=value)
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_usersgroup_name', state)
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 = UsersGroup.query()\
608 .filter(UsersGroup.users_group_active == True)\
609 .filter(UsersGroup.users_group_name == k).one()
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 usersGroups
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 usersGroups
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="ajaxActionUsersGroup(${g2p.users_group.users_group_id},'${'id%s'%id(g2p.users_group.users_group_name)}')">
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 ajaxActionUsersGroup(users_group_id,field_id){
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="ajaxActionUsersGroup(${g2p.users_group.users_group_id},'${'id%s'%id(g2p.users_group.users_group_name)}')">
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 ajaxActionUsersGroup(users_group_id,field_id){
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 &raquo;
11 ${h.link_to(_('UsersGroups'),h.url('users_groups'))}
11 ${h.link_to(_('UserGroups'),h.url('users_groups'))}
12 12 &raquo;
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 UsersGroupModel
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_USERS_GROUP = 'test_users_group'
46 TEST_USER_GROUP = 'test_users_group'
47 47
48 48
49 def make_users_group(name=TEST_USERS_GROUP):
50 gr = UsersGroupModel().create(name=name)
51 UsersGroupModel().add_user_to_group(users_group=gr,
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_USERS_GROUP):
58 UsersGroupModel().delete(users_group=name, force=True)
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_USERS_GROUP)
1002 usersgroupid=TEST_USER_GROUP)
1003 1003 response = api_call(self, params)
1004 1004
1005 users_group = UsersGroupModel().get_group(TEST_USERS_GROUP)
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_USERS_GROUP, 'test_users_group2']:
1025 users_group = UsersGroupModel().get_group(gr_name)
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 UsersGroupModel().delete(users_group='test_users_group2')
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(UsersGroupModel()\
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_USERS_GROUP)
1052 group_name=TEST_USER_GROUP)
1053 1053 response = api_call(self, params)
1054 1054
1055 expected = "user group `%s` already exist" % TEST_USERS_GROUP
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(UsersGroupModel, 'create', crash)
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 UsersGroupModel().create(gr_name)
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 UsersGroupModel().delete(users_group=gr_name)
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(UsersGroupModel, 'add_user_to_group', crash)
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 UsersGroupModel().create(gr_name)
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 UsersGroupModel().delete(users_group=gr_name)
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 = UsersGroupModel().create(gr_name)
1115 UsersGroupModel().add_user_to_group(gr, user=TEST_USER_ADMIN_LOGIN)
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 UsersGroupModel().delete(users_group=gr_name)
1129 UserGroupModel().delete(users_group=gr_name)
1130 1130 Session().commit()
1131 1131
1132 @mock.patch.object(UsersGroupModel, 'remove_user_from_group', crash)
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 = UsersGroupModel().create(gr_name)
1136 UsersGroupModel().add_user_to_group(gr, user=TEST_USER_ADMIN_LOGIN)
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 UsersGroupModel().delete(users_group=gr_name)
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_USERS_GROUP,
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_USERS_GROUP, self.REPO
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_USERS_GROUP,
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_USERS_GROUP,
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_USERS_GROUP, self.REPO
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_USERS_GROUP,
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_USERS_GROUP,)
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_USERS_GROUP, self.REPO
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_USERS_GROUP,)
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_USERS_GROUP, self.REPO
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 UsersGroup, UsersGroupToPerm, Permission
2 from rhodecode.model.db import UserGroup, UserGroupToPerm, Permission
3 3
4 TEST_USERS_GROUP = 'admins_test'
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_USERS_GROUP
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_USERS_GROUP)
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_USERS_GROUP + 'another'
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(UsersGroup)\
52 .filter(UsersGroup.users_group_name ==
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(UsersGroup)\
58 .filter(UsersGroup.users_group_name ==
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_USERS_GROUP + 'another2'
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 = UsersGroup.get_by_group_name(users_group_name)
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 = UsersGroup.get_by_group_name(users_group_name)
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 = UsersGroupToPerm.query()\
85 .filter(UsersGroupToPerm.users_group == ug).all()
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 = UsersGroup.get_by_group_name(users_group_name)
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 = UsersGroupToPerm.query()\
104 .filter(UsersGroupToPerm.users_group == ug).all()
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 = UsersGroup.get_by_group_name(users_group_name)
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(UsersGroup)\
118 .filter(UsersGroup.users_group_name ==
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 = UsersGroupToPerm.query()\
124 .filter(UsersGroupToPerm.users_group_id == ugid).all()
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_USERS_GROUP + 'another2'
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 = UsersGroup.get_by_group_name(users_group_name)
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 = UsersGroup.get_by_group_name(users_group_name)
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 = UsersGroupToPerm.query()\
154 .filter(UsersGroupToPerm.users_group == ug).all()
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 = UsersGroup.get_by_group_name(users_group_name)
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 = UsersGroupToPerm.query()\
173 .filter(UsersGroupToPerm.users_group == ug).all()
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 = UsersGroup.get_by_group_name(users_group_name)
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(UsersGroup)\
187 .filter(UsersGroup.users_group_name ==
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 = UsersGroupToPerm.query()\
193 .filter(UsersGroupToPerm.users_group_id == ugid).all()
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, UsersGroupRepoGroupToPerm
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 UsersGroupModel
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 UsersGroupModel().delete(self.ug1, force=True)
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 = UsersGroupModel().create('G1')
127 self.ug1 = UserGroupModel().create('G1')
128 128 # add user to group
129 129
130 UsersGroupModel().add_user_to_group(self.ug1, self.u1)
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 = UsersGroupModel().create('G1')
161 self.ug1 = UserGroupModel().create('G1')
162 162 # add user to group
163 163
164 UsersGroupModel().add_user_to_group(self.ug1, self.u3)
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 = UsersGroupModel().create('G1')
186 self.ug1 = UserGroupModel().create('G1')
187 187 # add user to group
188 UsersGroupModel().add_user_to_group(self.ug1, self.u1)
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 = UsersGroupModel().create('G1')
302 self.ug1 = UserGroupModel().create('G1')
303 303 # add user to group
304 UsersGroupModel().add_user_to_group(self.ug1, self.u1)
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 UsersGroupModel().get(self.ug1.users_group_id).members]
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(UsersGroupRepoGroupToPerm)\
328 .filter(UsersGroupRepoGroupToPerm.group == self.g1)\
329 .filter(UsersGroupRepoGroupToPerm.users_group == self.ug1)\
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 = UsersGroupModel().create('G1')
443 self.ug1 = UserGroupModel().create('G1')
444 444 # add user to group
445 UsersGroupModel().add_user_to_group(self.ug1, self.u1)
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, UsersGroup, UsersGroupMember, UserEmailMap,\
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 UsersGroupModel
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 = UsersGroupModel().create('some_example_group')
26 users_group = UserGroupModel().create('some_example_group')
27 27 Session().commit()
28 28
29 UsersGroupModel().add_user_to_group(users_group, usr)
29 UserGroupModel().add_user_to_group(users_group, usr)
30 30 Session().commit()
31 31
32 self.assertEqual(UsersGroup.get(users_group.users_group_id), users_group)
33 self.assertEqual(UsersGroupMember.query().count(), 1)
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(UsersGroupMember.query().all(), [])
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 UsersGroupModel
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 = UsersGroupModel().create(name='perms_group_1')
43 gr1 = UserGroupModel().create(name='perms_group_1')
44 44 Session().commit()
45 45 test_u2_gr_id = gr1.users_group_id
46 UsersGroupModel().add_user_to_group(gr1, user=test_u2_id)
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 UsersGroupModel
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_ValidUsersGroup(self):
55 validator = v.ValidUsersGroup()
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 = UsersGroupModel().create('test')
60 gr2 = UsersGroupModel().create('tes2')
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.ValidUsersGroup(edit=True,
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 UsersGroupModel().delete(gr)
72 UsersGroupModel().delete(gr2)
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