annotate rhodecode/controllers/admin/permissions.py @ 760:fb7a3b291e64 beta

Cleaned up scm model codes,Admin/admin permissions controller codes
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 25 Nov 2010 22:55:10 +0100
parents 9e9f1b919c0c
children 4bdcc08b04c4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
760
fb7a3b291e64 Cleaned up scm model codes,Admin/admin permissions controller codes
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
1 # -*- coding: utf-8 -*-
fb7a3b291e64 Cleaned up scm model codes,Admin/admin permissions controller codes
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
2 """
fb7a3b291e64 Cleaned up scm model codes,Admin/admin permissions controller codes
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
3 package.rhodecode.controllers.admin.permissions
fb7a3b291e64 Cleaned up scm model codes,Admin/admin permissions controller codes
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
4 ~~~~~~~~~~~~~~
fb7a3b291e64 Cleaned up scm model codes,Admin/admin permissions controller codes
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
5 permissions controller for Rhodecode
fb7a3b291e64 Cleaned up scm model codes,Admin/admin permissions controller codes
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
6
fb7a3b291e64 Cleaned up scm model codes,Admin/admin permissions controller codes
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
7 :created_on: Apr 27, 2010
fb7a3b291e64 Cleaned up scm model codes,Admin/admin permissions controller codes
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
8 :author: marcink
fb7a3b291e64 Cleaned up scm model codes,Admin/admin permissions controller codes
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
9 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
fb7a3b291e64 Cleaned up scm model codes,Admin/admin permissions controller codes
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
10 :license: GPLv3, see COPYING for more details.
fb7a3b291e64 Cleaned up scm model codes,Admin/admin permissions controller codes
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
11 """
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 230
diff changeset
12 # 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
13 # 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
14 # as published by the Free Software Foundation; version 2
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 230
diff changeset
15 # 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
16 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 230
diff changeset
17 # 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
18 # 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
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 230
diff changeset
20 # GNU General Public License for more details.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 230
diff changeset
21 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 230
diff changeset
22 # 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
23 # 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
24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 230
diff changeset
25 # MA 02110-1301, USA.
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
26
305
61be6dcd49a0 protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
27 from formencode import htmlfill
61be6dcd49a0 protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
28 from pylons import request, session, tmpl_context as c, url
61be6dcd49a0 protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
29 from pylons.controllers.util import abort, redirect
61be6dcd49a0 protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
30 from pylons.i18n.translation import _
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 418
diff changeset
31 from rhodecode.lib import helpers as h
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 418
diff changeset
32 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
33 from rhodecode.lib.auth_ldap import LdapImportError
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 418
diff changeset
34 from rhodecode.lib.base import BaseController, render
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
35 from rhodecode.model.forms import LdapSettingsForm, DefaultPermissionsForm
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
36 from rhodecode.model.permission import PermissionModel
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
37 from rhodecode.model.settings import SettingsModel
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
38 from rhodecode.model.user import UserModel
305
61be6dcd49a0 protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
39 import formencode
230
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 import logging
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
41 import traceback
230
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 log = logging.getLogger(__name__)
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 class PermissionsController(BaseController):
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 """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
47 # 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
48 # file has a resource setup:
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 # map.resource('permission', 'permissions')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
50
305
61be6dcd49a0 protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
51 @LoginRequired()
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
52 @HasPermissionAllDecorator('hg.admin')
305
61be6dcd49a0 protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
53 def __before__(self):
61be6dcd49a0 protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
54 c.admin_user = session.get('admin_user')
61be6dcd49a0 protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
55 c.admin_username = session.get('admin_username')
61be6dcd49a0 protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
56 super(PermissionsController, self).__before__()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
57
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
58 self.perms_choices = [('repository.none', _('None'),),
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
59 ('repository.read', _('Read'),),
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
60 ('repository.write', _('Write'),),
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
61 ('repository.admin', _('Admin'),)]
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
62 self.register_choices = [
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 664
diff changeset
63 ('hg.register.none',
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 664
diff changeset
64 _('disabled')),
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
65 ('hg.register.manual_activate',
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 664
diff changeset
66 _('allowed with manual account activation')),
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
67 ('hg.register.auto_activate',
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 664
diff changeset
68 _('allowed with automatic account activation')), ]
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
69
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
70 self.create_choices = [('hg.create.none', _('Disabled')),
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
71 ('hg.create.repository', _('Enabled'))]
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
72
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
73
230
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 def index(self, format='html'):
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 """GET /permissions: All items in the collection"""
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 create(self):
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 """POST /permissions: Create a new item"""
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 # url('permissions')
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 new(self, format='html'):
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 """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
84 # url('new_permission')
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86 def update(self, id):
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 """PUT /permissions/id: Update an existing item"""
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 # 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
89 # <input type="hidden" name="_method" value="PUT" />
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 # Or using helpers:
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 # h.form(url('permission', id=ID),
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 # method='put')
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93 # url('permission', id=ID)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
94
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
95 permission_model = PermissionModel()
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 _form = DefaultPermissionsForm([x[0] for x in self.perms_choices],
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
98 [x[0] for x in self.register_choices],
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
99 [x[0] for x in self.create_choices])()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
100
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
101 try:
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
102 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
103 form_result.update({'perm_user_name':id})
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
104 permission_model.update(form_result)
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
105 h.flash(_('Default permissions updated successfully'),
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
106 category='success')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
107
564
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
108 except formencode.Invalid, errors:
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
109 c.perms_choices = self.perms_choices
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
110 c.register_choices = self.register_choices
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
111 c.create_choices = self.create_choices
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
112 defaults = errors.value
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
113 defaults.update(SettingsModel().get_ldap_settings())
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
114
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
115 return htmlfill.render(
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
116 render('admin/permissions/permissions.html'),
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
117 defaults=defaults,
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
118 errors=errors.error_dict or {},
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
119 prefix_error=False,
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
120 encoding="UTF-8")
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
121 except Exception:
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
122 log.error(traceback.format_exc())
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
123 h.flash(_('error occured during update of permissions'),
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
124 category='error')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
125
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
126 return redirect(url('edit_permission', id=id))
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
127
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
128
230
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
129
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
130 def delete(self, id):
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
131 """DELETE /permissions/id: Delete an existing item"""
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
132 # 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
133 # <input type="hidden" name="_method" value="DELETE" />
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
134 # Or using helpers:
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135 # h.form(url('permission', id=ID),
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136 # method='delete')
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 # url('permission', id=ID)
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
139 def show(self, id, format='html'):
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
140 """GET /permissions/id: Show a specific item"""
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
141 # url('permission', id=ID)
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
142
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
143 def edit(self, id, format='html'):
d982ed8e32d8 Admin templating updates, added rest permission controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
144 """GET /permissions/id/edit: Form to edit an existing item"""
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
145 #url('edit_permission', id=ID)
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
146 c.perms_choices = self.perms_choices
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
147 c.register_choices = self.register_choices
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
148 c.create_choices = self.create_choices
629
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 id == 'default':
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 664
diff changeset
151 default_user = UserModel().get_by_username('default')
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 664
diff changeset
152 defaults = {'_method':'put',
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 664
diff changeset
153 'anonymous':default_user.active}
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
154 defaults.update(SettingsModel().get_ldap_settings())
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 664
diff changeset
155 for p in default_user.user_perms:
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
156 if p.permission.permission_name.startswith('repository.'):
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
157 defaults['default_perm'] = p.permission.permission_name
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
158
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
159 if p.permission.permission_name.startswith('hg.register.'):
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
160 defaults['default_register'] = p.permission.permission_name
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
161
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
162 if p.permission.permission_name.startswith('hg.create.'):
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
163 defaults['default_create'] = p.permission.permission_name
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
164
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
165 return htmlfill.render(
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
166 render('admin/permissions/permissions.html'),
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
167 defaults=defaults,
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
168 encoding="UTF-8",
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
169 force_defaults=True,)
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
170 else:
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
171 return redirect(url('admin_home'))
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
172
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
173
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
174 def ldap(self, id_user='default'):
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
175 """
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
176 POST ldap create and store ldap settings
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
177 """
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
178
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
179 settings_model = SettingsModel()
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
180 _form = LdapSettingsForm()()
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
181
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
182 try:
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
183 form_result = _form.to_python(dict(request.POST))
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
184 try:
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
185
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
186 for k, v in form_result.items():
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
187 if k.startswith('ldap_'):
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
188 setting = settings_model.get(k)
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
189 setting.app_settings_value = v
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
190 self.sa.add(setting)
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
191
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
192 self.sa.commit()
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
193 h.flash(_('Ldap settings updated successfully'),
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
194 category='success')
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
195 except:
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
196 raise
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
197 except LdapImportError:
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
198 h.flash(_('Unable to activate ldap. The "ldap-python" library '
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
199 'is missing.'),
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
200 category='warning')
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
201
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
202 except formencode.Invalid, errors:
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
203 c.perms_choices = self.perms_choices
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
204 c.register_choices = self.register_choices
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
205 c.create_choices = self.create_choices
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
206
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
207 return htmlfill.render(
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
208 render('admin/permissions/permissions.html'),
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
209 defaults=errors.value,
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
210 errors=errors.error_dict or {},
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
211 prefix_error=False,
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
212 encoding="UTF-8")
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
213 except Exception:
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
214 log.error(traceback.format_exc())
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
215 h.flash(_('error occured during update of ldap settings'),
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
216 category='error')
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
217
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
218 return redirect(url('edit_permission', id=id_user))