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