annotate rhodecode/controllers/admin/repos_groups.py @ 2831:0959096b2c02 beta

Wraps group listing with permissions check so they don't get displayed
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 12 Sep 2012 12:54:46 +0200
parents c0cc8f8a71b0
children 68e95f5ae3a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1824
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
1 # -*- coding: utf-8 -*-
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
2 """
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
3 rhodecode.controllers.admin.repos_groups
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
5
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
6 Repositories groups controller for RhodeCode
1824
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
7
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
8 :created_on: Mar 23, 2010
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
9 :author: marcink
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
11 :license: GPLv3, see COPYING for more details.
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
12 """
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
13 # This program is free software: you can redistribute it and/or modify
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
14 # it under the terms of the GNU General Public License as published by
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
15 # the Free Software Foundation, either version 3 of the License, or
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
16 # (at your option) any later version.
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
17 #
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
18 # This program is distributed in the hope that it will be useful,
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
21 # GNU General Public License for more details.
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
22 #
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
23 # You should have received a copy of the GNU General Public License
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
25
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 import logging
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
27 import traceback
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
28 import formencode
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
29
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
30 from formencode import htmlfill
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
32 from pylons import request, tmpl_context as c, url
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
33 from pylons.controllers.util import redirect
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
34 from pylons.i18n.translation import _
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35
1543
ada6926c374f Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
36 from sqlalchemy.exc import IntegrityError
ada6926c374f Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
37
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
38 from rhodecode.lib import helpers as h
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
39 from rhodecode.lib.auth import LoginRequired, HasPermissionAnyDecorator,\
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
40 HasReposGroupPermissionAnyDecorator
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 from rhodecode.lib.base import BaseController, render
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1547
diff changeset
42 from rhodecode.model.db import RepoGroup
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
43 from rhodecode.model.repos_group import ReposGroupModel
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
44 from rhodecode.model.forms import ReposGroupForm
1734
48d4fcf04a29 another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
45 from rhodecode.model.meta import Session
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
46 from rhodecode.model.repo import RepoModel
2497
5a8c19c4dbe1 Fixed bug in repos group discovery, when inner folder of bare git repos were detected as a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2496
diff changeset
47 from webob.exc import HTTPInternalServerError, HTTPNotFound
2820
c0cc8f8a71b0 Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents: 2749
diff changeset
48 from rhodecode.lib.utils2 import str2bool
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 log = logging.getLogger(__name__)
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51
1245
5f2fbab7c429 PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 1193
diff changeset
52
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 class ReposGroupsController(BaseController):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 """REST Controller styled on the Atom Publishing Protocol"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 # To properly map this controller, ensure your config/routing.py
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 # file has a resource setup:
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 # map.resource('repos_group', 'repos_groups')
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58
1347
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
59 @LoginRequired()
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
60 def __before__(self):
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
61 super(ReposGroupsController, self).__before__()
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
62
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
63 def __load_defaults(self):
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1547
diff changeset
64 c.repo_groups = RepoGroup.groups_choices()
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
65 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
66
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
67 repo_model = RepoModel()
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
68 c.users_array = repo_model.get_users_js()
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
69 c.users_groups_array = repo_model.get_users_groups_js()
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
70
1347
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
71 def __load_data(self, group_id):
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
72 """
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
73 Load defaults settings for edit, and update
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
74
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
75 :param group_id:
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
76 """
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
77 self.__load_defaults()
2496
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2055
diff changeset
78 repo_group = RepoGroup.get_or_404(group_id)
1349
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1347
diff changeset
79 data = repo_group.get_dict()
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1482
diff changeset
80 data['group_name'] = repo_group.name
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1482
diff changeset
81
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
82 # fill repository users
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
83 for p in repo_group.repo_group_to_perm:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
84 data.update({'u_perm_%s' % p.user.username:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
85 p.permission.permission_name})
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
86
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
87 # fill repository groups
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
88 for p in repo_group.users_group_to_perm:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
89 data.update({'g_perm_%s' % p.users_group.users_group_name:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
90 p.permission.permission_name})
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
91
1349
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1347
diff changeset
92 return data
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
93
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
94 @HasPermissionAnyDecorator('hg.admin')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 def index(self, format='html'):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 """GET /repos_groups: All items in the collection"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 # url('repos_groups')
1898
a7dfe823933a added validation to repo groups to check for conflicting repository name fixes #337
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
98 sk = lambda g: g.parents[0].group_name if g.parents else g.group_name
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1547
diff changeset
99 c.groups = sorted(RepoGroup.query().all(), key=sk)
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
100 return render('admin/repos_groups/repos_groups_show.html')
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
101
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
102 @HasPermissionAnyDecorator('hg.admin')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 def create(self):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 """POST /repos_groups: Create a new item"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105 # url('repos_groups')
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
106 self.__load_defaults()
1898
a7dfe823933a added validation to repo groups to check for conflicting repository name fixes #337
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
107 repos_group_form = ReposGroupForm(available_groups =
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
108 c.repo_groups_choices)()
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
109 try:
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
110 form_result = repos_group_form.to_python(dict(request.POST))
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
111 ReposGroupModel().create(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
112 group_name=form_result['group_name'],
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
113 group_description=form_result['group_description'],
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
114 parent=form_result['group_parent_id']
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
115 )
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2631
diff changeset
116 Session().commit()
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
117 h.flash(_('created repos group %s') \
1347
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
118 % form_result['group_name'], category='success')
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
119 #TODO: in futureaction_logger(, '', '', '', self.sa)
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
120 except formencode.Invalid, errors:
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
121
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
122 return htmlfill.render(
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
123 render('admin/repos_groups/repos_groups_add.html'),
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
124 defaults=errors.value,
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
125 errors=errors.error_dict or {},
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
126 prefix_error=False,
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
127 encoding="UTF-8")
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
128 except Exception:
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
129 log.error(traceback.format_exc())
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
130 h.flash(_('error occurred during creation of repos group %s') \
1347
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
131 % request.POST.get('group_name'), category='error')
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
132
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
133 return redirect(url('repos_groups'))
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
134
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
135 @HasPermissionAnyDecorator('hg.admin')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136 def new(self, format='html'):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 """GET /repos_groups/new: Form to create a new item"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138 # url('new_repos_group')
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
139 self.__load_defaults()
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
140 return render('admin/repos_groups/repos_groups_add.html')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
141
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
142 @HasPermissionAnyDecorator('hg.admin')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
143 def update(self, id):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
144 """PUT /repos_groups/id: Update an existing item"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
145 # Forms posted to this method should contain a hidden field:
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
146 # <input type="hidden" name="_method" value="PUT" />
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
147 # Or using helpers:
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
148 # h.form(url('repos_group', id=ID),
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
149 # method='put')
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150 # url('repos_group', id=ID)
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
151
1347
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
152 self.__load_defaults()
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1547
diff changeset
153 c.repos_group = RepoGroup.get(id)
1347
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
154
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
155 repos_group_form = ReposGroupForm(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
156 edit=True,
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
157 old_data=c.repos_group.get_dict(),
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
158 available_groups=c.repo_groups_choices
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
159 )()
1347
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
160 try:
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
161 form_result = repos_group_form.to_python(dict(request.POST))
1734
48d4fcf04a29 another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
162 ReposGroupModel().update(id, form_result)
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2631
diff changeset
163 Session().commit()
1347
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
164 h.flash(_('updated repos group %s') \
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
165 % form_result['group_name'], category='success')
2820
c0cc8f8a71b0 Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents: 2749
diff changeset
166 #TODO: in future action_logger(, '', '', '', self.sa)
1347
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
167 except formencode.Invalid, errors:
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
168
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
169 return htmlfill.render(
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
170 render('admin/repos_groups/repos_groups_edit.html'),
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
171 defaults=errors.value,
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
172 errors=errors.error_dict or {},
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
173 prefix_error=False,
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
174 encoding="UTF-8")
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
175 except Exception:
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
176 log.error(traceback.format_exc())
1349
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1347
diff changeset
177 h.flash(_('error occurred during update of repos group %s') \
1347
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
178 % request.POST.get('group_name'), category='error')
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
179
2749
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
180 return redirect(url('edit_repos_group', id=id))
1347
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
181
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
182 @HasPermissionAnyDecorator('hg.admin')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
183 def delete(self, id):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
184 """DELETE /repos_groups/id: Delete an existing item"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
185 # Forms posted to this method should contain a hidden field:
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
186 # <input type="hidden" name="_method" value="DELETE" />
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
187 # Or using helpers:
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
188 # h.form(url('repos_group', id=ID),
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
189 # method='delete')
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
190 # url('repos_group', id=ID)
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
191
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1547
diff changeset
192 gr = RepoGroup.get(id)
1346
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
193 repos = gr.repositories.all()
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
194 if repos:
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
195 h.flash(_('This group contains %s repositores and cannot be '
2570
94ae02ca5f00 i18n improve
Takumi IINO <trot.thunder@gmail.com>
parents: 2497
diff changeset
196 'deleted') % len(repos),
1346
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
197 category='error')
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
198 return redirect(url('repos_groups'))
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
199
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
200 try:
1734
48d4fcf04a29 another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
201 ReposGroupModel().delete(id)
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2631
diff changeset
202 Session().commit()
2749
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
203 h.flash(_('removed repos group %s') % gr.group_name,
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
204 category='success')
1482
a39c0e5fca89 removed obsolete sort code
Marcin Kuzminski <marcin@python-works.com>
parents: 1394
diff changeset
205 #TODO: in future action_logger(, '', '', '', self.sa)
1543
ada6926c374f Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
206 except IntegrityError, e:
2749
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
207 if str(e.message).find('groups_group_parent_id_fkey') != -1:
1543
ada6926c374f Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
208 log.error(traceback.format_exc())
ada6926c374f Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
209 h.flash(_('Cannot delete this group it still contains '
ada6926c374f Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
210 'subgroups'),
ada6926c374f Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
211 category='warning')
ada6926c374f Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
212 else:
ada6926c374f Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
213 log.error(traceback.format_exc())
ada6926c374f Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
214 h.flash(_('error occurred during deletion of repos '
2570
94ae02ca5f00 i18n improve
Takumi IINO <trot.thunder@gmail.com>
parents: 2497
diff changeset
215 'group %s') % gr.group_name, category='error')
1543
ada6926c374f Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
216
1346
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
217 except Exception:
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
218 log.error(traceback.format_exc())
1543
ada6926c374f Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
219 h.flash(_('error occurred during deletion of repos '
2570
94ae02ca5f00 i18n improve
Takumi IINO <trot.thunder@gmail.com>
parents: 2497
diff changeset
220 'group %s') % gr.group_name, category='error')
1346
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
221
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
222 return redirect(url('repos_groups'))
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
223
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
224 @HasReposGroupPermissionAnyDecorator('group.admin')
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
225 def delete_repos_group_user_perm(self, group_name):
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
226 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
227 DELETE an existing repositories group permission user
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
228
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
229 :param group_name:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
230 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
231 try:
2820
c0cc8f8a71b0 Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents: 2749
diff changeset
232 recursive = str2bool(request.POST.get('recursive', False))
c0cc8f8a71b0 Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents: 2749
diff changeset
233 ReposGroupModel().delete_permission(
c0cc8f8a71b0 Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents: 2749
diff changeset
234 repos_group=group_name, obj=request.POST['user_id'],
c0cc8f8a71b0 Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents: 2749
diff changeset
235 obj_type='user', recursive=recursive
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
236 )
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2631
diff changeset
237 Session().commit()
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
238 except Exception:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
239 log.error(traceback.format_exc())
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
240 h.flash(_('An error occurred during deletion of group user'),
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
241 category='error')
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
242 raise HTTPInternalServerError()
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
243
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
244 @HasReposGroupPermissionAnyDecorator('group.admin')
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
245 def delete_repos_group_users_group_perm(self, group_name):
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
246 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
247 DELETE an existing repositories group permission users group
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
248
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
249 :param group_name:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
250 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
251
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
252 try:
2820
c0cc8f8a71b0 Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents: 2749
diff changeset
253 recursive = str2bool(request.POST.get('recursive', False))
c0cc8f8a71b0 Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents: 2749
diff changeset
254 ReposGroupModel().delete_permission(
c0cc8f8a71b0 Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents: 2749
diff changeset
255 repos_group=group_name, obj=request.POST['users_group_id'],
c0cc8f8a71b0 Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents: 2749
diff changeset
256 obj_type='users_group', recursive=recursive
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
257 )
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2631
diff changeset
258 Session().commit()
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
259 except Exception:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
260 log.error(traceback.format_exc())
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
261 h.flash(_('An error occurred during deletion of group'
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
262 ' users groups'),
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
263 category='error')
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
264 raise HTTPInternalServerError()
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
265
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1482
diff changeset
266 def show_by_name(self, group_name):
2055
c8a8684efc74 fixed issue #370
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
267 """
c8a8684efc74 fixed issue #370
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
268 This is a proxy that does a lookup group_name -> id, and shows
c8a8684efc74 fixed issue #370
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
269 the group by id view instead
c8a8684efc74 fixed issue #370
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
270 """
c8a8684efc74 fixed issue #370
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
271 group_name = group_name.rstrip('/')
2497
5a8c19c4dbe1 Fixed bug in repos group discovery, when inner folder of bare git repos were detected as a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2496
diff changeset
272 id_ = RepoGroup.get_by_group_name(group_name)
5a8c19c4dbe1 Fixed bug in repos group discovery, when inner folder of bare git repos were detected as a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2496
diff changeset
273 if id_:
5a8c19c4dbe1 Fixed bug in repos group discovery, when inner folder of bare git repos were detected as a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2496
diff changeset
274 return self.show(id_.group_id)
5a8c19c4dbe1 Fixed bug in repos group discovery, when inner folder of bare git repos were detected as a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2496
diff changeset
275 raise HTTPNotFound
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1482
diff changeset
276
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
277 @HasReposGroupPermissionAnyDecorator('group.read', 'group.write',
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1961
diff changeset
278 'group.admin')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
279 def show(self, id, format='html'):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
280 """GET /repos_groups/id: Show a specific item"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
281 # url('repos_group', id=ID)
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
282
2496
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2055
diff changeset
283 c.group = RepoGroup.get_or_404(id)
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
284
2496
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2055
diff changeset
285 c.group_repos = c.group.repositories.all()
1193
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
286
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
287 #overwrite our cached list with current filter
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
288 gr_filter = c.group_repos
1193
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
289 c.cached_repo_list = self.scm_model.get_repos(all_repos=gr_filter)
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
290
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
291 c.repos_list = c.cached_repo_list
1193
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
292
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
293 c.repo_cnt = 0
1343
a04fe5986109 #47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
294
2831
0959096b2c02 Wraps group listing with permissions check so they don't get displayed
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
295 groups = RepoGroup.query().order_by(RepoGroup.group_name)\
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1547
diff changeset
296 .filter(RepoGroup.group_parent_id == id).all()
2831
0959096b2c02 Wraps group listing with permissions check so they don't get displayed
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
297 c.groups = self.scm_model.get_repos_groups(groups)
1193
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
298 return render('admin/repos_groups/repos_groups.html')
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
299
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
300 @HasPermissionAnyDecorator('hg.admin')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
301 def edit(self, id, format='html'):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
302 """GET /repos_groups/id/edit: Form to edit an existing item"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
303 # url('edit_repos_group', id=ID)
1349
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1347
diff changeset
304
2631
f597cfb492f9 Added quick links for editing permissions for users from permission overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
305 c.repos_group = ReposGroupModel()._get_repos_group(id)
f597cfb492f9 Added quick links for editing permissions for users from permission overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
306 defaults = self.__load_data(c.repos_group.group_id)
1347
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
307
1349
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1347
diff changeset
308 # we need to exclude this group from the group list for editing
2631
f597cfb492f9 Added quick links for editing permissions for users from permission overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
309 c.repo_groups = filter(lambda x: x[0] != c.repos_group.group_id,
f597cfb492f9 Added quick links for editing permissions for users from permission overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
310 c.repo_groups)
1349
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1347
diff changeset
311
1347
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
312 return htmlfill.render(
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
313 render('admin/repos_groups/repos_groups_edit.html'),
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
314 defaults=defaults,
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
315 encoding="UTF-8",
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
316 force_defaults=False
43b8e161be3f #47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
317 )