Files
@ a62af7d509ee
Branch filter:
Location: kallithea/rhodecode/model/users_group.py - annotation
a62af7d509ee
3.5 KiB
text/x-python
fixes #228 - added detection of assigned groups to prevent errors on sqlite
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c 6832ef664673 fff21c9b075c fff21c9b075c 6832ef664673 fff21c9b075c fff21c9b075c a671db5bdd58 a671db5bdd58 a671db5bdd58 a671db5bdd58 6832ef664673 fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c 6832ef664673 fff21c9b075c a671db5bdd58 fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c a62af7d509ee fff21c9b075c fff21c9b075c a62af7d509ee a62af7d509ee fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c aa7e45ad0cea fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c fff21c9b075c 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 aa7e45ad0cea aa7e45ad0cea aa7e45ad0cea 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 2c8fd84935a4 9be6d46c72d6 9be6d46c72d6 9be6d46c72d6 a62af7d509ee a62af7d509ee a62af7d509ee a62af7d509ee a62af7d509ee a62af7d509ee a62af7d509ee a62af7d509ee a62af7d509ee a62af7d509ee 9be6d46c72d6 9be6d46c72d6 9be6d46c72d6 9be6d46c72d6 9be6d46c72d6 9be6d46c72d6 9be6d46c72d6 | # -*- coding: utf-8 -*-
"""
rhodecode.model.user_group
~~~~~~~~~~~~~~~~~~~~~~~~~~
users groups model for RhodeCode
:created_on: Jan 25, 2011
:author: marcink
:copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
:license: GPLv3, see COPYING for more details.
"""
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
import traceback
from pylons.i18n.translation import _
from rhodecode.lib.exceptions import UsersGroupsAssignedException
from rhodecode.model import BaseModel
from rhodecode.model.caching_query import FromCache
from rhodecode.model.db import UsersGroup, UsersGroupMember, \
UsersGroupRepoToPerm
log = logging.getLogger(__name__)
class UsersGroupModel(BaseModel):
def get(self, users_group_id, cache=False):
users_group = self.sa.query(UsersGroup)
if cache:
users_group = users_group.options(FromCache("sql_cache_short",
"get_users_group_%s" % users_group_id))
return users_group.get(users_group_id)
def create(self, form_data):
try:
new_users_group = UsersGroup()
for k, v in form_data.items():
setattr(new_users_group, k, v)
self.sa.add(new_users_group)
self.sa.commit()
except:
log.error(traceback.format_exc())
self.sa.rollback()
raise
def update(self, users_group_id, form_data):
try:
users_group = self.get(users_group_id, cache=False)
for k, v in form_data.items():
if k == 'users_group_members':
users_group.members = []
self.sa.flush()
members_list = []
if v:
for u_id in set(v):
members_list.append(UsersGroupMember(
users_group_id,
u_id))
setattr(users_group, 'members', members_list)
setattr(users_group, k, v)
self.sa.add(users_group)
self.sa.commit()
except:
log.error(traceback.format_exc())
self.sa.rollback()
raise
def delete(self, users_group_id):
try:
# check if this group is not assigned to repo
assigned_groups = UsersGroupRepoToPerm.query()\
.filter(UsersGroupRepoToPerm.users_group_id ==
users_group_id).all()
if assigned_groups:
raise UsersGroupsAssignedException('Group assigned to %s' %
assigned_groups)
users_group = self.get(users_group_id, cache=False)
self.sa.delete(users_group)
self.sa.commit()
except:
log.error(traceback.format_exc())
self.sa.rollback()
raise
|