annotate pylons_app/controllers/admin/repos.py @ 417:3ed2d46a2ca7

permission refactoring, Implemented views for default permissions, fixes #23 user registration is controlled by permission system. Implemented manual registration option websetup fills default permissions
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 21 Aug 2010 16:34:37 +0200
parents f5c1eec9f376
children 48be953851fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
1 #!/usr/bin/env python
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
2 # encoding: utf-8
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
3 # repos controller for pylons
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 365
diff changeset
5 #
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
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: 248
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: 248
diff changeset
8 # as published by the Free Software Foundation; version 2
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
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: 248
diff changeset
10 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
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: 248
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: 248
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
14 # GNU General Public License for more details.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
15 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
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: 248
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: 248
diff changeset
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
19 # MA 02110-1301, USA.
365
ec7b76d4bda4 Added initial query skipp when seting up the app.
Marcin Kuzminski <marcin@python-works.com>
parents: 357
diff changeset
20 """
ec7b76d4bda4 Added initial query skipp when seting up the app.
Marcin Kuzminski <marcin@python-works.com>
parents: 357
diff changeset
21 Created on April 7, 2010
ec7b76d4bda4 Added initial query skipp when seting up the app.
Marcin Kuzminski <marcin@python-works.com>
parents: 357
diff changeset
22 admin controller for pylons
ec7b76d4bda4 Added initial query skipp when seting up the app.
Marcin Kuzminski <marcin@python-works.com>
parents: 357
diff changeset
23 @author: marcink
ec7b76d4bda4 Added initial query skipp when seting up the app.
Marcin Kuzminski <marcin@python-works.com>
parents: 357
diff changeset
24 """
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 299
diff changeset
25 from formencode import htmlfill
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
26 from operator import itemgetter
376
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
27 from paste.httpexceptions import HTTPInternalServerError
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 299
diff changeset
28 from pylons import request, response, session, tmpl_context as c, url
215
70f645fa97cc Moved repo creation to admin/repos, as part of crud controller. Now repo creation is based on a form, which can be auto filled with data from 404 page. Fixed the error controller to properly give the repo name.
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
29 from pylons.controllers.util import abort, redirect
248
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 247
diff changeset
30 from pylons.i18n.translation import _
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 247
diff changeset
31 from pylons_app.lib import helpers as h
380
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
32 from pylons_app.lib.auth import LoginRequired, HasPermissionAllDecorator, \
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
33 HasPermissionAnyDecorator
215
70f645fa97cc Moved repo creation to admin/repos, as part of crud controller. Now repo creation is based on a form, which can be auto filled with data from 404 page. Fixed the error controller to properly give the repo name.
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
34 from pylons_app.lib.base import BaseController, render
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
35 from pylons_app.lib.utils import invalidate_cache
376
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
36 from pylons_app.model.db import User
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 299
diff changeset
37 from pylons_app.model.forms import RepoForm
246
ca80f8c00562 Fixed bug in repos, added dependencies and bumped version
Marcin Kuzminski <marcin@python-works.com>
parents: 235
diff changeset
38 from pylons_app.model.hg_model import HgModel
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 299
diff changeset
39 from pylons_app.model.repo_model import RepoModel
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
40 import formencode
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
41 import logging
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
42 import traceback
365
ec7b76d4bda4 Added initial query skipp when seting up the app.
Marcin Kuzminski <marcin@python-works.com>
parents: 357
diff changeset
43
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
44 log = logging.getLogger(__name__)
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
45
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
46 class ReposController(BaseController):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
47 """REST Controller styled on the Atom Publishing Protocol"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
48 # To properly map this controller, ensure your config/routing.py
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
49 # file has a resource setup:
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
50 # map.resource('repo', 'repos')
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 299
diff changeset
51
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 220
diff changeset
52 @LoginRequired()
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 399
diff changeset
53 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
54 def __before__(self):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
55 c.admin_user = session.get('admin_user')
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
56 c.admin_username = session.get('admin_username')
191
b68b2246e5a6 Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
57 super(ReposController, self).__before__()
380
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
58
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
59 @HasPermissionAllDecorator('hg.admin')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
60 def index(self, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
61 """GET /repos: All items in the collection"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
62 # url('repos')
246
ca80f8c00562 Fixed bug in repos, added dependencies and bumped version
Marcin Kuzminski <marcin@python-works.com>
parents: 235
diff changeset
63 cached_repo_list = HgModel().get_repos()
247
51434007e21d proper sorting fix
Marcin Kuzminski <marcin@python-works.com>
parents: 246
diff changeset
64 c.repos_list = sorted(cached_repo_list, key=itemgetter('name_sort'))
127
20dc7a5eb748 Html changes and cleanups, made folders for html templates, implemented tags and branches pages
Marcin Kuzminski <marcin@python-works.com>
parents: 101
diff changeset
65 return render('admin/repos/repos.html')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
66
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 399
diff changeset
67 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
68 def create(self):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
69 """POST /repos: Create a new item"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
70 # url('repos')
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
71 repo_model = RepoModel()
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
72 _form = RepoForm()()
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
73 form_result = {}
215
70f645fa97cc Moved repo creation to admin/repos, as part of crud controller. Now repo creation is based on a form, which can be auto filled with data from 404 page. Fixed the error controller to properly give the repo name.
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
74 try:
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
75 form_result = _form.to_python(dict(request.POST))
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
76 repo_model.create(form_result, c.hg_app_user)
215
70f645fa97cc Moved repo creation to admin/repos, as part of crud controller. Now repo creation is based on a form, which can be auto filled with data from 404 page. Fixed the error controller to properly give the repo name.
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
77 invalidate_cache('cached_repo_list')
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
78 h.flash(_('created repository %s') % form_result['repo_name'],
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
79 category='success')
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
80
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
81 except formencode.Invalid as errors:
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
82 c.new_repo = errors.value['repo_name']
380
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
83
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
84 if request.POST.get('user_created'):
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
85 r = render('admin/repos/repo_add_create_repository.html')
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
86 else:
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
87 r = render('admin/repos/repo_add.html')
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
88
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
89 return htmlfill.render(
380
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
90 r,
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
91 defaults=errors.value,
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
92 errors=errors.error_dict or {},
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
93 prefix_error=False,
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
94 encoding="UTF-8")
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
95
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
96 except Exception:
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
97 log.error(traceback.format_exc())
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
98 msg = _('error occured during creation of repository %s') \
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
99 % form_result.get('repo_name')
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
100 h.flash(msg, category='error')
380
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
101 if request.POST.get('user_created'):
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
102 return redirect(url('hg_home'))
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
103 return redirect(url('repos'))
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
104
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
105 @HasPermissionAllDecorator('hg.admin')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
106 def new(self, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
107 """GET /repos/new: Form to create a new item"""
215
70f645fa97cc Moved repo creation to admin/repos, as part of crud controller. Now repo creation is based on a form, which can be auto filled with data from 404 page. Fixed the error controller to properly give the repo name.
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
108 new_repo = request.GET.get('repo', '')
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
109 c.new_repo = h.repo_name_slug(new_repo)
215
70f645fa97cc Moved repo creation to admin/repos, as part of crud controller. Now repo creation is based on a form, which can be auto filled with data from 404 page. Fixed the error controller to properly give the repo name.
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
110
70f645fa97cc Moved repo creation to admin/repos, as part of crud controller. Now repo creation is based on a form, which can be auto filled with data from 404 page. Fixed the error controller to properly give the repo name.
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
111 return render('admin/repos/repo_add.html')
380
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
112
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
113 @HasPermissionAllDecorator('hg.admin')
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
114 def update(self, repo_name):
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
115 """PUT /repos/repo_name: Update an existing item"""
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
116 # Forms posted to this method should contain a hidden field:
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
117 # <input type="hidden" name="_method" value="PUT" />
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
118 # Or using helpers:
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
119 # h.form(url('repo', repo_name=ID),
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
120 # method='put')
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
121 # url('repo', repo_name=ID)
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
122 repo_model = RepoModel()
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
123 changed_name = repo_name
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
124 _form = RepoForm(edit=True, old_data={'repo_name':repo_name})()
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
125
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
126 try:
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
127 form_result = _form.to_python(dict(request.POST))
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
128 repo_model.update(repo_name, form_result)
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
129 invalidate_cache('cached_repo_list')
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 299
diff changeset
130 h.flash(_('Repository %s updated succesfully' % repo_name),
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 299
diff changeset
131 category='success')
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
132 changed_name = form_result['repo_name']
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
133 except formencode.Invalid as errors:
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
134 c.repo_info = repo_model.get(repo_name)
298
15e96b5a2685 autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents: 296
diff changeset
135 c.users_array = repo_model.get_users_js()
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 266
diff changeset
136 errors.value.update({'user':c.repo_info.user.username})
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
137 return htmlfill.render(
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
138 render('admin/repos/repo_edit.html'),
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
139 defaults=errors.value,
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
140 errors=errors.error_dict or {},
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
141 prefix_error=False,
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
142 encoding="UTF-8")
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
143
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
144 except Exception:
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
145 log.error(traceback.format_exc())
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
146 h.flash(_('error occured during update of repository %s') \
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
147 % repo_name, category='error')
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
148
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
149 return redirect(url('edit_repo', repo_name=changed_name))
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
150
380
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
151 @HasPermissionAllDecorator('hg.admin')
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
152 def delete(self, repo_name):
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
153 """DELETE /repos/repo_name: Delete an existing item"""
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
154 # Forms posted to this method should contain a hidden field:
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
155 # <input type="hidden" name="_method" value="DELETE" />
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
156 # Or using helpers:
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
157 # h.form(url('repo', repo_name=ID),
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
158 # method='delete')
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
159 # url('repo', repo_name=ID)
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
160
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
161 repo_model = RepoModel()
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
162 repo = repo_model.get(repo_name)
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
163 if not repo:
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
164 h.flash(_('%s repository is not mapped to db perhaps'
266
32d6c955218c added check for repo created outside of hg app
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
165 ' it was moved or renamed from the filesystem'
32d6c955218c added check for repo created outside of hg app
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
166 ' please run the application again'
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 299
diff changeset
167 ' in order to rescan repositories') % repo_name,
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 299
diff changeset
168 category='error')
140
b5e59e2b5cfe moved cache invalidating to utils, as seperate function. Implemented invalidating in
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
169
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
170 return redirect(url('repos'))
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
171 try:
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
172 repo_model.delete(repo)
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
173 invalidate_cache('cached_repo_list')
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
174 h.flash(_('deleted repository %s') % repo_name, category='success')
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
175 except Exception:
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
176 h.flash(_('An error occured during deletion of %s') % repo_name,
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
177 category='error')
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
178
58
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents: 52
diff changeset
179 return redirect(url('repos'))
380
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
180
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
181 @HasPermissionAllDecorator('hg.admin')
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
182 def delete_perm_user(self, repo_name):
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
183 """
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
184 DELETE an existing repository permission user
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
185 @param repo_name:
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
186 """
220
e6c802a8dede repo edit
Marcin Kuzminski <marcin@python-works.com>
parents: 215
diff changeset
187
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
188 try:
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
189 repo_model = RepoModel()
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
190 repo_model.delete_perm_user(request.POST, repo_name)
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
191 except Exception as e:
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
192 h.flash(_('An error occured during deletion of repository user'),
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
193 category='error')
365
ec7b76d4bda4 Added initial query skipp when seting up the app.
Marcin Kuzminski <marcin@python-works.com>
parents: 357
diff changeset
194 raise HTTPInternalServerError()
380
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
195
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
196 @HasPermissionAllDecorator('hg.admin')
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
197 def show(self, repo_name, format='html'):
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
198 """GET /repos/repo_name: Show a specific item"""
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
199 # url('repo', repo_name=ID)
380
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
200
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
201 @HasPermissionAllDecorator('hg.admin')
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
202 def edit(self, repo_name, format='html'):
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
203 """GET /repos/repo_name/edit: Form to edit an existing item"""
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
204 # url('edit_repo', repo_name=ID)
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
205 repo_model = RepoModel()
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
206 c.repo_info = repo = repo_model.get(repo_name)
266
32d6c955218c added check for repo created outside of hg app
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
207 if not repo:
32d6c955218c added check for repo created outside of hg app
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
208 h.flash(_('%s repository is not mapped to db perhaps'
32d6c955218c added check for repo created outside of hg app
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
209 ' it was created or renamed from the filesystem'
32d6c955218c added check for repo created outside of hg app
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
210 ' please run the application again'
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 299
diff changeset
211 ' in order to rescan repositories') % repo_name,
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 299
diff changeset
212 category='error')
266
32d6c955218c added check for repo created outside of hg app
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
213
32d6c955218c added check for repo created outside of hg app
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
214 return redirect(url('repos'))
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
215 defaults = c.repo_info.__dict__
376
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
216 if c.repo_info.user:
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
217 defaults.update({'user':c.repo_info.user.username})
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
218 else:
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
219 replacement_user = self.sa.query(User)\
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
220 .filter(User.admin == True).first().username
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
221 defaults.update({'user':replacement_user})
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
222
298
15e96b5a2685 autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents: 296
diff changeset
223 c.users_array = repo_model.get_users_js()
15e96b5a2685 autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents: 296
diff changeset
224
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 380
diff changeset
225 for p in c.repo_info.repo_to_perm:
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 266
diff changeset
226 defaults.update({'perm_%s' % p.user.username:
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 266
diff changeset
227 p.permission.permission_name})
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
228
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
229 return htmlfill.render(
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
230 render('admin/repos/repo_edit.html'),
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
231 defaults=defaults,
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
232 encoding="UTF-8",
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
233 force_defaults=False
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
234 )