##// END OF EJS Templates
routes python 2.5 compatible...
marcink -
r371:5cd6616b default
parent child Browse files
Show More
@@ -0,0 +1,79 b''
1 ## -*- coding: utf-8 -*-
2 <%inherit file="/base/base.html"/>
3
4 <%def name="title()">
5 ${_('User administration')}
6 </%def>
7
8 <%def name="breadcrumbs_links()">
9 ${_('My Account')}
10 </%def>
11
12 <%def name="page_nav()">
13 ${self.menu('admin')}
14 </%def>
15
16 <%def name="main()">
17 <div class="box">
18 <!-- box / title -->
19 <div class="title">
20 ${self.breadcrumbs()}
21 </div>
22 <!-- end box / title -->
23 ${h.form(url('admin_settings_my_account_update'),method='put')}
24 <div class="form">
25 <!-- fields -->
26 <div class="fields">
27 <div class="field">
28 <div class="label">
29 <label for="username">${_('Username')}:</label>
30 </div>
31 <div class="input">
32 ${h.text('username')}
33 </div>
34 </div>
35
36 <div class="field">
37 <div class="label">
38 <label for="new_password">${_('New password')}:</label>
39 </div>
40 <div class="input">
41 ${h.password('new_password')}
42 </div>
43 </div>
44
45 <div class="field">
46 <div class="label">
47 <label for="name">${_('Name')}:</label>
48 </div>
49 <div class="input">
50 ${h.text('name')}
51 </div>
52 </div>
53
54 <div class="field">
55 <div class="label">
56 <label for="lastname">${_('Lastname')}:</label>
57 </div>
58 <div class="input">
59 ${h.text('lastname')}
60 </div>
61 </div>
62
63 <div class="field">
64 <div class="label">
65 <label for="email">${_('Email')}:</label>
66 </div>
67 <div class="input">
68 ${h.text('email')}
69 </div>
70 </div>
71
72 <div class="buttons">
73 ${h.submit('save','save',class_="ui-button ui-widget ui-state-default ui-corner-all")}
74 </div>
75 </div>
76 </div>
77 ${h.end_form()}
78 </div>
79 </%def> No newline at end of file
@@ -4,6 +4,7 b' The more specific and detailed routes sh'
4 4 may take precedent over the more generic routes. For more information
5 5 refer to the routes manual at http://routes.groovie.org/docs/
6 6 """
7 from __future__ import with_statement
7 8 from routes import Mapper
8 9 from pylons_app.lib.utils import check_repo_fast as cr
9 10
@@ -31,7 +32,7 b' def make_map(config):'
31 32 repo_name = match_dict.get('repo_name')
32 33 return not cr(repo_name, config['base_path'])
33 34
34 #REST routes
35 #REST REPO MAP
35 36 with map.submapper(path_prefix='/_admin', controller='admin/repos') as m:
36 37 m.connect("repos", "/repos",
37 38 action="create", conditions=dict(method=["POST"]))
@@ -69,7 +70,36 b' def make_map(config):'
69 70
70 71 map.resource('user', 'users', controller='admin/users', path_prefix='/_admin')
71 72 map.resource('permission', 'permissions', controller='admin/permissions', path_prefix='/_admin')
72 map.resource('setting', 'settings', controller='admin/settings', path_prefix='/_admin', name_prefix='admin_')
73
74 #map.resource('setting', 'settings', controller='admin/settings', path_prefix='/_admin', name_prefix='admin_')
75 #REST SETTINGS MAP
76 with map.submapper(path_prefix='/_admin', controller='admin/settings') as m:
77 m.connect("admin_settings", "/settings",
78 action="create", conditions=dict(method=["POST"]))
79 m.connect("admin_settings", "/settings",
80 action="index", conditions=dict(method=["GET"]))
81 m.connect("admin_formatted_settings", "/settings.{format}",
82 action="index", conditions=dict(method=["GET"]))
83 m.connect("admin_new_setting", "/settings/new",
84 action="new", conditions=dict(method=["GET"]))
85 m.connect("admin_formatted_new_setting", "/settings/new.{format}",
86 action="new", conditions=dict(method=["GET"]))
87 m.connect("/settings/{setting_id}",
88 action="update", conditions=dict(method=["PUT"]))
89 m.connect("/settings/{setting_id}",
90 action="delete", conditions=dict(method=["DELETE"]))
91 m.connect("admin_edit_setting", "/settings/{setting_id}/edit",
92 action="edit", conditions=dict(method=["GET"]))
93 m.connect("admin_formatted_edit_setting", "/settings/{setting_id}.{format}/edit",
94 action="edit", conditions=dict(method=["GET"]))
95 m.connect("admin_setting", "/settings/{setting_id}",
96 action="show", conditions=dict(method=["GET"]))
97 m.connect("admin_formatted_setting", "/settings/{setting_id}.{format}",
98 action="show", conditions=dict(method=["GET"]))
99 m.connect("admin_settings_my_account", "/my_account",
100 action="my_account", conditions=dict(method=["GET"]))
101 m.connect("admin_settings_my_account_update", "/my_account_update",
102 action="my_account_update", conditions=dict(method=["PUT"]))
73 103
74 104 #ADMIN
75 105 with map.submapper(path_prefix='/_admin', controller='admin/admin') as m:
@@ -2,6 +2,7 b''
2 2 # encoding: utf-8
3 3 # repos controller for pylons
4 4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
5 6 # This program is free software; you can redistribute it and/or
6 7 # modify it under the terms of the GNU General Public License
7 8 # as published by the Free Software Foundation; version 2
@@ -52,12 +52,13 b' class SettingsController(BaseController)'
52 52
53 53
54 54 @LoginRequired()
55 #@HasPermissionAllDecorator('hg.admin')
56 55 def __before__(self):
57 56 c.admin_user = session.get('admin_user')
58 57 c.admin_username = session.get('admin_username')
59 58 super(SettingsController, self).__before__()
60
59
60
61 @HasPermissionAllDecorator('hg.admin')
61 62 def index(self, format='html'):
62 63 """GET /admin/settings: All items in the collection"""
63 64 # url('admin_settings')
@@ -71,23 +72,26 b' class SettingsController(BaseController)'
71 72 force_defaults=False
72 73 )
73 74
75 @HasPermissionAllDecorator('hg.admin')
74 76 def create(self):
75 77 """POST /admin/settings: Create a new item"""
76 78 # url('admin_settings')
77
79
80 @HasPermissionAllDecorator('hg.admin')
78 81 def new(self, format='html'):
79 82 """GET /admin/settings/new: Form to create a new item"""
80 83 # url('admin_new_setting')
81
82 def update(self, id):
83 """PUT /admin/settings/id: Update an existing item"""
84
85 @HasPermissionAllDecorator('hg.admin')
86 def update(self, setting_id):
87 """PUT /admin/settings/setting_id: Update an existing item"""
84 88 # Forms posted to this method should contain a hidden field:
85 89 # <input type="hidden" name="_method" value="PUT" />
86 90 # Or using helpers:
87 # h.form(url('admin_setting', id=ID),
91 # h.form(url('admin_setting', setting_id=ID),
88 92 # method='put')
89 # url('admin_setting', id=ID)
90 if id == 'mapping':
93 # url('admin_setting', setting_id=ID)
94 if setting_id == 'mapping':
91 95 rm_obsolete = request.POST.get('destroy', False)
92 96 log.debug('Rescanning directories with destroy=%s', rm_obsolete)
93 97
@@ -96,7 +100,7 b' class SettingsController(BaseController)'
96 100 invalidate_cache('cached_repo_list')
97 101 h.flash(_('Repositories sucessfully rescanned'), category='success')
98 102
99 if id == 'global':
103 if setting_id == 'global':
100 104
101 105 application_form = ApplicationSettingsForm()()
102 106 try:
@@ -132,20 +136,77 b' class SettingsController(BaseController)'
132 136 encoding="UTF-8")
133 137
134 138 return redirect(url('admin_settings'))
135
136 def delete(self, id):
137 """DELETE /admin/settings/id: Delete an existing item"""
139
140 @HasPermissionAllDecorator('hg.admin')
141 def delete(self, setting_id):
142 """DELETE /admin/settings/setting_id: Delete an existing item"""
138 143 # Forms posted to this method should contain a hidden field:
139 144 # <input type="hidden" name="_method" value="DELETE" />
140 145 # Or using helpers:
141 # h.form(url('admin_setting', id=ID),
146 # h.form(url('admin_setting', setting_id=ID),
142 147 # method='delete')
143 # url('admin_setting', id=ID)
148 # url('admin_setting', setting_id=ID)
149
150 @HasPermissionAllDecorator('hg.admin')
151 def show(self, setting_id, format='html'):
152 """GET /admin/settings/setting_id: Show a specific item"""
153 # url('admin_setting', setting_id=ID)
154
155 @HasPermissionAllDecorator('hg.admin')
156 def edit(self, setting_id, format='html'):
157 """GET /admin/settings/setting_id/edit: Form to edit an existing item"""
158 # url('admin_edit_setting', setting_id=ID)
159
160
161 def my_account(self):
162 """
163 GET /_admin/my_account Displays info about my account
164 """
165 # url('admin_settings_my_account')
166 c.user = self.sa.query(User).get(c.hg_app_user.user_id)
167 if c.user.username == 'default':
168 h.flash(_("You can't edit this user since it's"
169 " crucial for entire application"), category='warning')
170 return redirect(url('users'))
171
172 defaults = c.user.__dict__
173 return htmlfill.render(
174 render('admin/users/user_edit_my_account.html'),
175 defaults=defaults,
176 encoding="UTF-8",
177 force_defaults=False
178 )
144 179
145 def show(self, id, format='html'):
146 """GET /admin/settings/id: Show a specific item"""
147 # url('admin_setting', id=ID)
180 def my_account_update(self):
181 """PUT /_admin/my_account_update: Update an existing item"""
182 # Forms posted to this method should contain a hidden field:
183 # <input type="hidden" name="_method" value="PUT" />
184 # Or using helpers:
185 # h.form(url('admin_settings_my_account_update'),
186 # method='put')
187 # url('admin_settings_my_account_update', id=ID)
188 user_model = UserModel()
189 uid = c.hg_app_user.user_id
190 _form = UserForm(edit=True, old_data={'user_id':uid})()
191 form_result = {}
192 try:
193 form_result = _form.to_python(dict(request.POST))
194 user_model.update_my_account(uid, form_result)
195 h.flash(_('Your account was updated succesfully'), category='success')
196
197 except formencode.Invalid as errors:
198 #c.user = self.sa.query(User).get(c.hg_app_user.user_id)
199 return htmlfill.render(
200 render('admin/users/user_edit_my_account.html'),
201 defaults=errors.value,
202 errors=errors.error_dict or {},
203 prefix_error=False,
204 encoding="UTF-8")
205 except Exception:
206 log.error(traceback.format_exc())
207 h.flash(_('error occured during update of user %s') \
208 % form_result.get('username'), category='error')
209
210 return redirect(url('my_account'))
211
148 212
149 def edit(self, id, format='html'):
150 """GET /admin/settings/id/edit: Form to edit an existing item"""
151 # url('admin_edit_setting', id=ID)
@@ -17,6 +17,12 b''
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 19 # MA 02110-1301, USA.
20 """
21 Created on April 4, 2010
22 users controller for pylons
23 @author: marcink
24 """
25
20 26 from formencode import htmlfill
21 27 from pylons import request, session, tmpl_context as c, url
22 28 from pylons.controllers.util import abort, redirect
@@ -30,11 +36,7 b' from pylons_app.model.user_model import '
30 36 import formencode
31 37 import logging
32 38 import traceback
33 """
34 Created on April 4, 2010
35 users controller for pylons
36 @author: marcink
37 """
39
38 40
39 41 log = logging.getLogger(__name__)
40 42
@@ -104,7 +104,23 b' def set_available_permissions(config):'
104 104
105 105 def set_base_path(config):
106 106 config['base_path'] = config['pylons.app_globals'].base_path
107
107
108 def fill_data(user):
109 """
110 Fills user data with those from database
111 @param user:
112 """
113 sa = meta.Session
114 dbuser = sa.query(User).get(user.user_id)
115
116 user.username = dbuser.username
117 user.is_admin = dbuser.admin
118 user.name = dbuser.name
119 user.lastname = dbuser.lastname
120
121 meta.Session.remove()
122 return user
123
108 124 def fill_perms(user):
109 125 """
110 126 Fills user permission attribute with permissions taken from database
@@ -113,6 +129,7 b' def fill_perms(user):'
113 129
114 130 sa = meta.Session
115 131 user.permissions['repositories'] = {}
132 user.permissions['global'] = set()
116 133
117 134 #first fetch default permissions
118 135 default_perms = sa.query(Repo2Perm, Repository, Permission)\
@@ -122,14 +139,14 b' def fill_perms(user):'
122 139 'default').one().user_id).all()
123 140
124 141 if user.is_admin:
125 user.permissions['global'] = set(['hg.admin'])
142 user.permissions['global'].add('hg.admin')
126 143 #admin have all rights full
127 144 for perm in default_perms:
128 145 p = 'repository.admin'
129 146 user.permissions['repositories'][perm.Repo2Perm.repository.repo_name] = p
130 147
131 148 else:
132 user.permissions['global'] = set()
149 user.permissions['global'].add('')
133 150 for perm in default_perms:
134 151 if perm.Repository.private:
135 152 #disable defaults for private repos,
@@ -164,8 +181,8 b' def get_user(session):'
164 181 @param session:
165 182 """
166 183 user = session.get('hg_app_user', AuthUser())
167
168 184 if user.is_authenticated:
185 user = fill_data(user)
169 186 user = fill_perms(user)
170 187 session['hg_app_user'] = user
171 188 session.save()
@@ -177,8 +177,9 b' class DbManage(object):'
177 177 ('repository.read', 'Repository read access'),
178 178 ('repository.write', 'Repository write access'),
179 179 ('repository.admin', 'Repository admin access'),
180 ('repository.create', 'Repository create'),
180 181 ('hg.admin', 'Hg Administrator'),
181 ]
182 ]
182 183
183 184 for p in perms:
184 185 new_perm = Permission()
@@ -68,9 +68,9 b' class UserModel(object):'
68 68 self.sa.rollback()
69 69 raise
70 70
71 def update(self, id, form_data):
71 def update(self, uid, form_data):
72 72 try:
73 new_user = self.sa.query(User).get(id)
73 new_user = self.sa.query(User).get(uid)
74 74 if new_user.username == 'default':
75 75 raise DefaultUserException(
76 76 _("You can't Edit this user since it's"
@@ -87,7 +87,28 b' class UserModel(object):'
87 87 log.error(e)
88 88 self.sa.rollback()
89 89 raise
90
90
91 def update_my_account(self, uid, form_data):
92 try:
93 new_user = self.sa.query(User).get(uid)
94 if new_user.username == 'default':
95 raise DefaultUserException(
96 _("You can't Edit this user since it's"
97 " crucial for entire application"))
98 for k, v in form_data.items():
99 if k == 'new_password' and v != '':
100 new_user.password = v
101 else:
102 if k not in ['admin', 'active']:
103 setattr(new_user, k, v)
104
105 self.sa.add(new_user)
106 self.sa.commit()
107 except Exception as e:
108 log.error(e)
109 self.sa.rollback()
110 raise
111
91 112 def delete(self, id):
92 113
93 114 try:
@@ -23,7 +23,7 b''
23 23 </div>
24 24 <!-- end box / title -->
25 25
26 ${h.form(url('admin_setting', id='mapping'),method='put')}
26 ${h.form(url('admin_setting', setting_id='mapping'),method='put')}
27 27 <div class="form">
28 28 <!-- fields -->
29 29 <h3>${_('Remap and rescan repositories')}</h3>
@@ -49,7 +49,7 b''
49 49 </div>
50 50 ${h.end_form()}
51 51
52 ${h.form(url('admin_setting', id='global'),method='put')}
52 ${h.form(url('admin_setting', setting_id='global'),method='put')}
53 53 <div class="form">
54 54 <!-- fields -->
55 55 <h3>${_('Global application settings')}</h3>
@@ -17,7 +17,7 b''
17 17 <!-- user -->
18 18 <ul id="logged-user">
19 19 <li class="first">
20 ${h.link_to('%s %s (%s)'%(c.hg_app_user.name,c.hg_app_user.lastname,c.hg_app_user.username),h.url('edit_user', id=c.hg_app_user.user_id))}
20 ${h.link_to('%s %s (%s)'%(c.hg_app_user.name,c.hg_app_user.lastname,c.hg_app_user.username),h.url('admin_settings_my_account'))}
21 21 </li>
22 22 <li class="last highlight">${h.link_to(u'Logout',h.url('logout_home'))}</li>
23 23 </ul>
@@ -27,6 +27,13 b''
27 27 <!-- box / title -->
28 28 <div class="title">
29 29 <h5>${_('Dashboard')}</h5>
30 ##%if h.HasPermissionAll('repository.create')():
31 <ul class="links">
32 <li>
33 <span>${h.link_to(u'ADD NEW REPO',h.url('new_repo'),class_="add_icon")}</span>
34 </li>
35 </ul>
36 ##%endif
30 37 </div>
31 38 <!-- end box / title -->
32 39 <div class="table">
General Comments 0
You need to be logged in to leave comments. Login now