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