Show More
@@ -32,6 +32,7 b' from pylons import request, session, tmp' | |||||
32 | from pylons.controllers.util import abort, redirect |
|
32 | from pylons.controllers.util import abort, redirect | |
33 | from pylons.i18n.translation import _ |
|
33 | from pylons.i18n.translation import _ | |
34 |
|
34 | |||
|
35 | from rhodecode.lib.exceptions import UsersGroupsAssignedException | |||
35 | from rhodecode.lib import helpers as h |
|
36 | from rhodecode.lib import helpers as h | |
36 | from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator |
|
37 | from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator | |
37 | from rhodecode.lib.base import BaseController, render |
|
38 | from rhodecode.lib.base import BaseController, render | |
@@ -153,6 +154,8 b' class UsersGroupsController(BaseControll' | |||||
153 | try: |
|
154 | try: | |
154 | users_group_model.delete(id) |
|
155 | users_group_model.delete(id) | |
155 | h.flash(_('successfully deleted users group'), category='success') |
|
156 | h.flash(_('successfully deleted users group'), category='success') | |
|
157 | except UsersGroupsAssignedException, e: | |||
|
158 | h.flash(e, category='error') | |||
156 | except Exception: |
|
159 | except Exception: | |
157 | h.flash(_('An error occurred during deletion of users group'), |
|
160 | h.flash(_('An error occurred during deletion of users group'), | |
158 | category='error') |
|
161 | category='error') |
@@ -45,3 +45,6 b' class DefaultUserException(Exception):' | |||||
45 |
|
45 | |||
46 | class UserOwnsReposException(Exception): |
|
46 | class UserOwnsReposException(Exception): | |
47 | pass |
|
47 | pass | |
|
48 | ||||
|
49 | class UsersGroupsAssignedException(Exception): | |||
|
50 | pass |
@@ -286,6 +286,8 b' class UsersGroup(Base, BaseModel):' | |||||
286 |
|
286 | |||
287 | members = relationship('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined") |
|
287 | members = relationship('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined") | |
288 |
|
288 | |||
|
289 | def __repr__(self): | |||
|
290 | return '<userGroup(%s)>' % (self.users_group_name) | |||
289 |
|
291 | |||
290 | @classmethod |
|
292 | @classmethod | |
291 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
293 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
@@ -677,6 +679,8 b' class UsersGroupRepoToPerm(Base, BaseMod' | |||||
677 | permission = relationship('Permission') |
|
679 | permission = relationship('Permission') | |
678 | repository = relationship('Repository') |
|
680 | repository = relationship('Repository') | |
679 |
|
681 | |||
|
682 | def __repr__(self): | |||
|
683 | return '<userGroup:%s => %s >' % (self.users_group, self.repository) | |||
680 |
|
684 | |||
681 | class UsersGroupToPerm(Base, BaseModel): |
|
685 | class UsersGroupToPerm(Base, BaseModel): | |
682 | __tablename__ = 'users_group_to_perm' |
|
686 | __tablename__ = 'users_group_to_perm' |
@@ -28,9 +28,11 b' import traceback' | |||||
28 |
|
28 | |||
29 | from pylons.i18n.translation import _ |
|
29 | from pylons.i18n.translation import _ | |
30 |
|
30 | |||
|
31 | from rhodecode.lib.exceptions import UsersGroupsAssignedException | |||
31 | from rhodecode.model import BaseModel |
|
32 | from rhodecode.model import BaseModel | |
32 | from rhodecode.model.caching_query import FromCache |
|
33 | from rhodecode.model.caching_query import FromCache | |
33 | from rhodecode.model.db import UsersGroup, UsersGroupMember |
|
34 | from rhodecode.model.db import UsersGroup, UsersGroupMember, \ | |
|
35 | UsersGroupRepoToPerm | |||
34 |
|
36 | |||
35 | log = logging.getLogger(__name__) |
|
37 | log = logging.getLogger(__name__) | |
36 |
|
38 | |||
@@ -84,6 +86,16 b' class UsersGroupModel(BaseModel):' | |||||
84 |
|
86 | |||
85 | def delete(self, users_group_id): |
|
87 | def delete(self, users_group_id): | |
86 | try: |
|
88 | try: | |
|
89 | ||||
|
90 | # check if this group is not assigned to repo | |||
|
91 | assigned_groups = UsersGroupRepoToPerm.query()\ | |||
|
92 | .filter(UsersGroupRepoToPerm.users_group_id == | |||
|
93 | users_group_id).all() | |||
|
94 | ||||
|
95 | if assigned_groups: | |||
|
96 | raise UsersGroupsAssignedException('Group assigned to %s' % | |||
|
97 | assigned_groups) | |||
|
98 | ||||
87 | users_group = self.get(users_group_id, cache=False) |
|
99 | users_group = self.get(users_group_id, cache=False) | |
88 | self.sa.delete(users_group) |
|
100 | self.sa.delete(users_group) | |
89 | self.sa.commit() |
|
101 | self.sa.commit() |
General Comments 0
You need to be logged in to leave comments.
Login now