##// END OF EJS Templates
branch-permissions: add flash info when redirected from branch permissions page to indicate required action
marcink -
r3438:abae8687 default
parent child Browse files
Show More
@@ -1,102 +1,107 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2011-2019 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import logging
22 22
23 23 from pyramid.httpexceptions import HTTPFound
24 24 from pyramid.view import view_config
25 25
26 26 from rhodecode import events
27 27 from rhodecode.apps._base import RepoAppView
28 28 from rhodecode.lib import helpers as h
29 29 from rhodecode.lib import audit_logger
30 30 from rhodecode.lib.auth import (
31 31 LoginRequired, HasRepoPermissionAnyDecorator, CSRFRequired)
32 32 from rhodecode.lib.utils2 import safe_int
33 33 from rhodecode.model.db import UserGroup
34 34 from rhodecode.model.forms import RepoPermsForm
35 35 from rhodecode.model.meta import Session
36 36 from rhodecode.model.repo import RepoModel
37 37
38 38 log = logging.getLogger(__name__)
39 39
40 40
41 41 class RepoSettingsPermissionsView(RepoAppView):
42 42
43 43 def load_default_context(self):
44 44 c = self._get_local_tmpl_context()
45 45 return c
46 46
47 47 @LoginRequired()
48 48 @HasRepoPermissionAnyDecorator('repository.admin')
49 49 @view_config(
50 50 route_name='edit_repo_perms', request_method='GET',
51 51 renderer='rhodecode:templates/admin/repos/repo_edit.mako')
52 52 def edit_permissions(self):
53 _ = self.request.translate
53 54 c = self.load_default_context()
54 55 c.active = 'permissions'
56 if self.request.GET.get('branch_permissions'):
57 h.flash(_('Explicitly add user or user group with write+ '
58 'permission to modify their branch permissions.'),
59 category='notice')
55 60 return self._get_template_context(c)
56 61
57 62 @LoginRequired()
58 63 @HasRepoPermissionAnyDecorator('repository.admin')
59 64 @CSRFRequired()
60 65 @view_config(
61 66 route_name='edit_repo_perms', request_method='POST',
62 67 renderer='rhodecode:templates/admin/repos/repo_edit.mako')
63 68 def edit_permissions_update(self):
64 69 _ = self.request.translate
65 70 c = self.load_default_context()
66 71 c.active = 'permissions'
67 72 data = self.request.POST
68 73 # store private flag outside of HTML to verify if we can modify
69 74 # default user permissions, prevents submission of FAKE post data
70 75 # into the form for private repos
71 76 data['repo_private'] = self.db_repo.private
72 77 form = RepoPermsForm(self.request.translate)().to_python(data)
73 78 changes = RepoModel().update_permissions(
74 79 self.db_repo_name, form['perm_additions'], form['perm_updates'],
75 80 form['perm_deletions'])
76 81
77 82 action_data = {
78 83 'added': changes['added'],
79 84 'updated': changes['updated'],
80 85 'deleted': changes['deleted'],
81 86 }
82 87 audit_logger.store_web(
83 88 'repo.edit.permissions', action_data=action_data,
84 89 user=self._rhodecode_user, repo=self.db_repo)
85 90
86 91 Session().commit()
87 92 h.flash(_('Repository permissions updated'), category='success')
88 93
89 94 affected_user_ids = []
90 95 for change in changes['added'] + changes['updated'] + changes['deleted']:
91 96 if change['type'] == 'user':
92 97 affected_user_ids.append(change['id'])
93 98 if change['type'] == 'user_group':
94 99 user_group = UserGroup.get(safe_int(change['id']))
95 100 if user_group:
96 101 group_members_ids = [x.user_id for x in user_group.members]
97 102 affected_user_ids.extend(group_members_ids)
98 103
99 104 events.trigger(events.UserPermissionsChange(affected_user_ids))
100 105
101 106 raise HTTPFound(
102 107 h.route_path('edit_repo_perms', repo_name=self.db_repo_name))
General Comments 0
You need to be logged in to leave comments. Login now