Mercurial > kallithea
annotate rhodecode/controllers/admin/permissions.py @ 661:673de12e6bf6 beta
added option to enable/disable of logger hooks from admin panel.
some docs/setup updates
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 06 Nov 2010 00:37:21 +0100 |
parents | 7e536d1af60d |
children | 50d9b1afaca7 |
rev | line source |
---|---|
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
1 #!/usr/bin/env python |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
2 # encoding: utf-8 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
3 # permissions controller for pylons |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
5 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
6 # This program is free software; you can redistribute it and/or |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
7 # modify it under the terms of the GNU General Public License |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
8 # as published by the Free Software Foundation; version 2 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
9 # of the License or (at your opinion) any later version of the license. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
10 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
14 # GNU General Public License for more details. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
15 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
16 # You should have received a copy of the GNU General Public License |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
17 # along with this program; if not, write to the Free Software |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
19 # MA 02110-1301, USA. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
20 """ |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
21 Created on April 27, 2010 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
22 permissions controller for pylons |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
23 @author: marcink |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
230
diff
changeset
|
24 """ |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
25 |
305
61be6dcd49a0
protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
26 from formencode import htmlfill |
61be6dcd49a0
protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
27 from pylons import request, session, tmpl_context as c, url |
61be6dcd49a0
protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
28 from pylons.controllers.util import abort, redirect |
61be6dcd49a0
protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
29 from pylons.i18n.translation import _ |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
418
diff
changeset
|
30 from rhodecode.lib import helpers as h |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
418
diff
changeset
|
31 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
418
diff
changeset
|
32 from rhodecode.lib.base import BaseController, render |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
418
diff
changeset
|
33 from rhodecode.model.forms import UserForm, DefaultPermissionsForm |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
418
diff
changeset
|
34 from rhodecode.model.permission_model import PermissionModel |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
35 from rhodecode.model.user import UserModel |
305
61be6dcd49a0
protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
36 import formencode |
230
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 import logging |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
38 import traceback |
230
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 log = logging.getLogger(__name__) |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 class PermissionsController(BaseController): |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 """REST Controller styled on the Atom Publishing Protocol""" |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 # To properly map this controller, ensure your config/routing.py |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 # file has a resource setup: |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 # map.resource('permission', 'permissions') |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
47 |
305
61be6dcd49a0
protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
48 @LoginRequired() |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
49 @HasPermissionAllDecorator('hg.admin') |
305
61be6dcd49a0
protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
50 def __before__(self): |
61be6dcd49a0
protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
51 c.admin_user = session.get('admin_user') |
61be6dcd49a0
protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
52 c.admin_username = session.get('admin_username') |
61be6dcd49a0
protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
53 super(PermissionsController, self).__before__() |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
54 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
55 self.perms_choices = [('repository.none', _('None'),), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
56 ('repository.read', _('Read'),), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
57 ('repository.write', _('Write'),), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
58 ('repository.admin', _('Admin'),)] |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
59 self.register_choices = [ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
60 ('hg.register.none', 'disabled'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
61 ('hg.register.manual_activate', |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
62 _('allowed with manual account activation')), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
63 ('hg.register.auto_activate', |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
64 _('allowed with automatic account activation')), ] |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
65 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
66 self.create_choices = [('hg.create.none', _('Disabled')), |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
67 ('hg.create.repository', _('Enabled'))] |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
68 |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
69 |
230
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 def index(self, format='html'): |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 """GET /permissions: All items in the collection""" |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 # url('permissions') |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 def create(self): |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 """POST /permissions: Create a new item""" |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 # url('permissions') |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 def new(self, format='html'): |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 """GET /permissions/new: Form to create a new item""" |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 # url('new_permission') |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 def update(self, id): |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 """PUT /permissions/id: Update an existing item""" |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 # Forms posted to this method should contain a hidden field: |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 # <input type="hidden" name="_method" value="PUT" /> |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 # Or using helpers: |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 # h.form(url('permission', id=ID), |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 # method='put') |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 # url('permission', id=ID) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
90 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
91 permission_model = PermissionModel() |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
92 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
93 _form = DefaultPermissionsForm([x[0] for x in self.perms_choices], |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
94 [x[0] for x in self.register_choices], |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
95 [x[0] for x in self.create_choices])() |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
96 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
97 try: |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
98 form_result = _form.to_python(dict(request.POST)) |
418
63c697d1a631
added logic for changin defualt permissions, and option to overwrite all defualt permissions on each repository
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
99 form_result.update({'perm_user_name':id}) |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
100 permission_model.update(form_result) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
101 h.flash(_('Default permissions updated succesfully'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
102 category='success') |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
103 |
564
ba7e24cd4786
refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
104 except formencode.Invalid, errors: |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
105 c.perms_choices = self.perms_choices |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
106 c.register_choices = self.register_choices |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
107 c.create_choices = self.create_choices |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
108 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
109 return htmlfill.render( |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
110 render('admin/permissions/permissions.html'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
111 defaults=errors.value, |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
112 errors=errors.error_dict or {}, |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
113 prefix_error=False, |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
114 encoding="UTF-8") |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
115 except Exception: |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
116 log.error(traceback.format_exc()) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
117 h.flash(_('error occured during update of permissions'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
118 category='error') |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
119 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
120 return redirect(url('edit_permission', id=id)) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
121 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
122 |
230
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
124 def delete(self, id): |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
125 """DELETE /permissions/id: Delete an existing item""" |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 # Forms posted to this method should contain a hidden field: |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
127 # <input type="hidden" name="_method" value="DELETE" /> |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
128 # Or using helpers: |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 # h.form(url('permission', id=ID), |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 # method='delete') |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
131 # url('permission', id=ID) |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
132 |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
133 def show(self, id, format='html'): |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
134 """GET /permissions/id: Show a specific item""" |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
135 # url('permission', id=ID) |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
136 |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
137 def edit(self, id, format='html'): |
d982ed8e32d8
Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
138 """GET /permissions/id/edit: Form to edit an existing item""" |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
139 #url('edit_permission', id=ID) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
140 c.perms_choices = self.perms_choices |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
141 c.register_choices = self.register_choices |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
142 c.create_choices = self.create_choices |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
143 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
144 if id == 'default': |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
145 defaults = {'_method':'put'} |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
146 for p in UserModel().get_default().user_perms: |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
147 if p.permission.permission_name.startswith('repository.'): |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
148 defaults['default_perm'] = p.permission.permission_name |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
149 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
150 if p.permission.permission_name.startswith('hg.register.'): |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
151 defaults['default_register'] = p.permission.permission_name |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
152 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
153 if p.permission.permission_name.startswith('hg.create.'): |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
154 defaults['default_create'] = p.permission.permission_name |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
155 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
156 return htmlfill.render( |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
157 render('admin/permissions/permissions.html'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
158 defaults=defaults, |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
159 encoding="UTF-8", |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
160 force_defaults=True,) |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
161 else: |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
162 return redirect(url('admin_home')) |