##// END OF EJS Templates
some docs updates on controller
marcink -
r853:f67868ef beta
parent child Browse files
Show More
@@ -1,53 +1,53
1 1 # -*- coding: utf-8 -*-
2 2 """
3 package.rhodecode.controllers.admin.admin
4 ~~~~~~~~~~~~~~
3 rhodecode.controllers.admin.admin
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 6 Controller for Admin panel of Rhodecode
7 7
8 8 :created_on: Apr 7, 2010
9 9 :author: marcink
10 10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 11 :license: GPLv3, see COPYING for more details.
12 12 """
13 13 # This program is free software; you can redistribute it and/or
14 14 # modify it under the terms of the GNU General Public License
15 15 # as published by the Free Software Foundation; version 2
16 16 # of the License or (at your opinion) any later version of the license.
17 17 #
18 18 # This program is distributed in the hope that it will be useful,
19 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 21 # GNU General Public License for more details.
22 22 #
23 23 # You should have received a copy of the GNU General Public License
24 24 # along with this program; if not, write to the Free Software
25 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 26 # MA 02110-1301, USA.
27 27
28 28 import logging
29 29 from pylons import request, tmpl_context as c
30 30 from rhodecode.lib.base import BaseController, render
31 31 from rhodecode.model.db import UserLog
32 32 from webhelpers.paginate import Page
33 33 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
34 34
35 35 log = logging.getLogger(__name__)
36 36
37 37 class AdminController(BaseController):
38 38
39 39 @LoginRequired()
40 40 def __before__(self):
41 41 super(AdminController, self).__before__()
42 42
43 43 @HasPermissionAllDecorator('hg.admin')
44 44 def index(self):
45 45
46 46 users_log = self.sa.query(UserLog).order_by(UserLog.action_date.desc())
47 47 p = int(request.params.get('page', 1))
48 48 c.users_log = Page(users_log, page=p, items_per_page=10)
49 49 c.log_data = render('admin/admin_log.html')
50 50 if request.params.get('partial'):
51 51 return c.log_data
52 52 return render('admin/admin.html')
53 53
@@ -1,170 +1,171
1 1 # -*- coding: utf-8 -*-
2 2 """
3 package.rhodecode.controllers.admin.permissions
4 ~~~~~~~~~~~~~~
3 rhodecode.controllers.admin.permissions
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5 6 permissions controller for Rhodecode
6 7
7 8 :created_on: Apr 27, 2010
8 9 :author: marcink
9 10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
10 11 :license: GPLv3, see COPYING for more details.
11 12 """
12 13 # This program is free software; you can redistribute it and/or
13 14 # modify it under the terms of the GNU General Public License
14 15 # as published by the Free Software Foundation; version 2
15 16 # of the License or (at your opinion) any later version of the license.
16 17 #
17 18 # This program is distributed in the hope that it will be useful,
18 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 21 # GNU General Public License for more details.
21 22 #
22 23 # You should have received a copy of the GNU General Public License
23 24 # along with this program; if not, write to the Free Software
24 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 26 # MA 02110-1301, USA.
26 27
27 28 from formencode import htmlfill
28 29 from pylons import request, session, tmpl_context as c, url
29 30 from pylons.controllers.util import abort, redirect
30 31 from pylons.i18n.translation import _
31 32 from rhodecode.lib import helpers as h
32 33 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
33 34 from rhodecode.lib.auth_ldap import LdapImportError
34 35 from rhodecode.lib.base import BaseController, render
35 36 from rhodecode.model.forms import LdapSettingsForm, DefaultPermissionsForm
36 37 from rhodecode.model.permission import PermissionModel
37 38 from rhodecode.model.settings import SettingsModel
38 39 from rhodecode.model.user import UserModel
39 40 import formencode
40 41 import logging
41 42 import traceback
42 43
43 44 log = logging.getLogger(__name__)
44 45
45 46 class PermissionsController(BaseController):
46 47 """REST Controller styled on the Atom Publishing Protocol"""
47 48 # To properly map this controller, ensure your config/routing.py
48 49 # file has a resource setup:
49 50 # map.resource('permission', 'permissions')
50 51
51 52 @LoginRequired()
52 53 @HasPermissionAllDecorator('hg.admin')
53 54 def __before__(self):
54 55 c.admin_user = session.get('admin_user')
55 56 c.admin_username = session.get('admin_username')
56 57 super(PermissionsController, self).__before__()
57 58
58 59 self.perms_choices = [('repository.none', _('None'),),
59 60 ('repository.read', _('Read'),),
60 61 ('repository.write', _('Write'),),
61 62 ('repository.admin', _('Admin'),)]
62 63 self.register_choices = [
63 64 ('hg.register.none',
64 65 _('disabled')),
65 66 ('hg.register.manual_activate',
66 67 _('allowed with manual account activation')),
67 68 ('hg.register.auto_activate',
68 69 _('allowed with automatic account activation')), ]
69 70
70 71 self.create_choices = [('hg.create.none', _('Disabled')),
71 72 ('hg.create.repository', _('Enabled'))]
72 73
73 74
74 75 def index(self, format='html'):
75 76 """GET /permissions: All items in the collection"""
76 77 # url('permissions')
77 78
78 79 def create(self):
79 80 """POST /permissions: Create a new item"""
80 81 # url('permissions')
81 82
82 83 def new(self, format='html'):
83 84 """GET /permissions/new: Form to create a new item"""
84 85 # url('new_permission')
85 86
86 87 def update(self, id):
87 88 """PUT /permissions/id: Update an existing item"""
88 89 # Forms posted to this method should contain a hidden field:
89 90 # <input type="hidden" name="_method" value="PUT" />
90 91 # Or using helpers:
91 92 # h.form(url('permission', id=ID),
92 93 # method='put')
93 94 # url('permission', id=ID)
94 95
95 96 permission_model = PermissionModel()
96 97
97 98 _form = DefaultPermissionsForm([x[0] for x in self.perms_choices],
98 99 [x[0] for x in self.register_choices],
99 100 [x[0] for x in self.create_choices])()
100 101
101 102 try:
102 103 form_result = _form.to_python(dict(request.POST))
103 104 form_result.update({'perm_user_name':id})
104 105 permission_model.update(form_result)
105 106 h.flash(_('Default permissions updated successfully'),
106 107 category='success')
107 108
108 109 except formencode.Invalid, errors:
109 110 c.perms_choices = self.perms_choices
110 111 c.register_choices = self.register_choices
111 112 c.create_choices = self.create_choices
112 113 defaults = errors.value
113 114
114 115 return htmlfill.render(
115 116 render('admin/permissions/permissions.html'),
116 117 defaults=defaults,
117 118 errors=errors.error_dict or {},
118 119 prefix_error=False,
119 120 encoding="UTF-8")
120 121 except Exception:
121 122 log.error(traceback.format_exc())
122 123 h.flash(_('error occured during update of permissions'),
123 124 category='error')
124 125
125 126 return redirect(url('edit_permission', id=id))
126 127
127 128
128 129
129 130 def delete(self, id):
130 131 """DELETE /permissions/id: Delete an existing item"""
131 132 # Forms posted to this method should contain a hidden field:
132 133 # <input type="hidden" name="_method" value="DELETE" />
133 134 # Or using helpers:
134 135 # h.form(url('permission', id=ID),
135 136 # method='delete')
136 137 # url('permission', id=ID)
137 138
138 139 def show(self, id, format='html'):
139 140 """GET /permissions/id: Show a specific item"""
140 141 # url('permission', id=ID)
141 142
142 143 def edit(self, id, format='html'):
143 144 """GET /permissions/id/edit: Form to edit an existing item"""
144 145 #url('edit_permission', id=ID)
145 146 c.perms_choices = self.perms_choices
146 147 c.register_choices = self.register_choices
147 148 c.create_choices = self.create_choices
148 149
149 150 if id == 'default':
150 151 default_user = UserModel().get_by_username('default')
151 152 defaults = {'_method':'put',
152 153 'anonymous':default_user.active}
153 154
154 155 for p in default_user.user_perms:
155 156 if p.permission.permission_name.startswith('repository.'):
156 157 defaults['default_perm'] = p.permission.permission_name
157 158
158 159 if p.permission.permission_name.startswith('hg.register.'):
159 160 defaults['default_register'] = p.permission.permission_name
160 161
161 162 if p.permission.permission_name.startswith('hg.create.'):
162 163 defaults['default_create'] = p.permission.permission_name
163 164
164 165 return htmlfill.render(
165 166 render('admin/permissions/permissions.html'),
166 167 defaults=defaults,
167 168 encoding="UTF-8",
168 169 force_defaults=True,)
169 170 else:
170 171 return redirect(url('admin_home'))
@@ -1,167 +1,172
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # users controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.controllers.admin.users
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 Users crud controller for pylons
7
8 :created_on: Apr 4, 2010
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
6 13 # This program is free software; you can redistribute it and/or
7 14 # modify it under the terms of the GNU General Public License
8 15 # as published by the Free Software Foundation; version 2
9 16 # of the License or (at your opinion) any later version of the license.
10 17 #
11 18 # This program is distributed in the hope that it will be useful,
12 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 21 # GNU General Public License for more details.
15 22 #
16 23 # You should have received a copy of the GNU General Public License
17 24 # along with this program; if not, write to the Free Software
18 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 26 # MA 02110-1301, USA.
20 """
21 Created on April 4, 2010
22 users controller for pylons
23 @author: marcink
24 """
27
28 import logging
29 import traceback
30 import formencode
25 31
26 32 from formencode import htmlfill
27 33 from pylons import request, session, tmpl_context as c, url
28 34 from pylons.controllers.util import abort, redirect
29 35 from pylons.i18n.translation import _
36
30 37 from rhodecode.lib.exceptions import *
31 38 from rhodecode.lib import helpers as h
32 39 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
33 40 from rhodecode.lib.base import BaseController, render
41
34 42 from rhodecode.model.db import User
35 43 from rhodecode.model.forms import UserForm
36 44 from rhodecode.model.user import UserModel
37 import formencode
38 import logging
39 import traceback
40 45
41 46 log = logging.getLogger(__name__)
42 47
43 48 class UsersController(BaseController):
44 49 """REST Controller styled on the Atom Publishing Protocol"""
45 50 # To properly map this controller, ensure your config/routing.py
46 51 # file has a resource setup:
47 52 # map.resource('user', 'users')
48 53
49 54 @LoginRequired()
50 55 @HasPermissionAllDecorator('hg.admin')
51 56 def __before__(self):
52 57 c.admin_user = session.get('admin_user')
53 58 c.admin_username = session.get('admin_username')
54 59 super(UsersController, self).__before__()
55 60
56 61
57 62 def index(self, format='html'):
58 63 """GET /users: All items in the collection"""
59 64 # url('users')
60 65
61 66 c.users_list = self.sa.query(User).all()
62 67 return render('admin/users/users.html')
63 68
64 69 def create(self):
65 70 """POST /users: Create a new item"""
66 71 # url('users')
67 72
68 73 user_model = UserModel()
69 74 login_form = UserForm()()
70 75 try:
71 76 form_result = login_form.to_python(dict(request.POST))
72 77 user_model.create(form_result)
73 78 h.flash(_('created user %s') % form_result['username'],
74 79 category='success')
75 80 #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa)
76 81 except formencode.Invalid, errors:
77 82 return htmlfill.render(
78 83 render('admin/users/user_add.html'),
79 84 defaults=errors.value,
80 85 errors=errors.error_dict or {},
81 86 prefix_error=False,
82 87 encoding="UTF-8")
83 88 except Exception:
84 89 log.error(traceback.format_exc())
85 90 h.flash(_('error occured during creation of user %s') \
86 91 % request.POST.get('username'), category='error')
87 92 return redirect(url('users'))
88 93
89 94 def new(self, format='html'):
90 95 """GET /users/new: Form to create a new item"""
91 96 # url('new_user')
92 97 return render('admin/users/user_add.html')
93 98
94 99 def update(self, id):
95 100 """PUT /users/id: Update an existing item"""
96 101 # Forms posted to this method should contain a hidden field:
97 102 # <input type="hidden" name="_method" value="PUT" />
98 103 # Or using helpers:
99 104 # h.form(url('user', id=ID),
100 105 # method='put')
101 106 # url('user', id=ID)
102 107 user_model = UserModel()
103 108 c.user = user_model.get(id)
104 109
105 110 _form = UserForm(edit=True, old_data={'user_id':id,
106 111 'email':c.user.email})()
107 112 form_result = {}
108 113 try:
109 114 form_result = _form.to_python(dict(request.POST))
110 115 user_model.update(id, form_result)
111 116 h.flash(_('User updated succesfully'), category='success')
112 117
113 118 except formencode.Invalid, errors:
114 119 return htmlfill.render(
115 120 render('admin/users/user_edit.html'),
116 121 defaults=errors.value,
117 122 errors=errors.error_dict or {},
118 123 prefix_error=False,
119 124 encoding="UTF-8")
120 125 except Exception:
121 126 log.error(traceback.format_exc())
122 h.flash(_('error occured during update of user %s') \
127 h.flash(_('error occurred during update of user %s') \
123 128 % form_result.get('username'), category='error')
124 129
125 130 return redirect(url('users'))
126 131
127 132 def delete(self, id):
128 133 """DELETE /users/id: Delete an existing item"""
129 134 # Forms posted to this method should contain a hidden field:
130 135 # <input type="hidden" name="_method" value="DELETE" />
131 136 # Or using helpers:
132 137 # h.form(url('user', id=ID),
133 138 # method='delete')
134 139 # url('user', id=ID)
135 140 user_model = UserModel()
136 141 try:
137 142 user_model.delete(id)
138 143 h.flash(_('sucessfully deleted user'), category='success')
139 144 except (UserOwnsReposException, DefaultUserException), e:
140 145 h.flash(str(e), category='warning')
141 146 except Exception:
142 147 h.flash(_('An error occured during deletion of user'),
143 148 category='error')
144 149 return redirect(url('users'))
145 150
146 151 def show(self, id, format='html'):
147 152 """GET /users/id: Show a specific item"""
148 153 # url('user', id=ID)
149 154
150 155
151 156 def edit(self, id, format='html'):
152 157 """GET /users/id/edit: Form to edit an existing item"""
153 158 # url('edit_user', id=ID)
154 159 c.user = self.sa.query(User).get(id)
155 160 if not c.user:
156 161 return redirect(url('users'))
157 162 if c.user.username == 'default':
158 163 h.flash(_("You can't edit this user"), category='warning')
159 164 return redirect(url('users'))
160 165
161 166 defaults = c.user.get_dict()
162 167 return htmlfill.render(
163 168 render('admin/users/user_edit.html'),
164 169 defaults=defaults,
165 170 encoding="UTF-8",
166 171 force_defaults=False
167 172 )
General Comments 0
You need to be logged in to leave comments. Login now