annotate rhodecode/controllers/admin/repos.py @ 916:be73a4d29672 demo

merged default with demo
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 18 Dec 2010 15:07:16 +0100
parents d6205f6e6756 634596f81cfd
children fcf8788886ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
881
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
1 # -*- coding: utf-8 -*-
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
2 """
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
3 rhodecode.controllers.admin.repos
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
5
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
6 Admin controller for RhodeCode
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
7
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
8 :created_on: Apr 7, 2010
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
9 :author: marcink
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
11 :license: GPLv3, see COPYING for more details.
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
12 """
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
13 # 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
14 # 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
15 # as published by the Free Software Foundation; version 2
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
16 # 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
17 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
18 # 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
19 # 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
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
21 # GNU General Public License for more details.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
22 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
23 # 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
24 # 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
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
26 # MA 02110-1301, USA.
881
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
27
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
28 import logging
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
29 import traceback
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
30 import formencode
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
31 from operator import itemgetter
331
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 312
diff changeset
32 from formencode import htmlfill
881
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
33
408
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 401
diff changeset
34 from paste.httpexceptions import HTTPInternalServerError
331
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 312
diff changeset
35 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
36 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
37 from pylons.i18n.translation import _
881
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
38
596
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 585
diff changeset
39 from rhodecode.lib import helpers as h
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 585
diff changeset
40 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
41 HasPermissionAnyDecorator
596
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 585
diff changeset
42 from rhodecode.lib.base import BaseController, render
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 585
diff changeset
43 from rhodecode.lib.utils import invalidate_cache, action_logger
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 585
diff changeset
44 from rhodecode.model.db import User
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 585
diff changeset
45 from rhodecode.model.forms import RepoForm
748
7486da5f0628 Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents: 720
diff changeset
46 from rhodecode.model.scm import ScmModel
684
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
47 from rhodecode.model.repo import RepoModel
881
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
48
391
ec7b76d4bda4 Added initial query skipp when seting up the app.
Marcin Kuzminski <marcin@python-works.com>
parents: 383
diff changeset
49
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
50 log = logging.getLogger(__name__)
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
51
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
52 class ReposController(BaseController):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
53 """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
54 # 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
55 # file has a resource setup:
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
56 # map.resource('repo', 'repos')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
57
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 220
diff changeset
58 @LoginRequired()
453
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 432
diff changeset
59 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
60 def __before__(self):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
61 c.admin_user = session.get('admin_user')
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
62 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
63 super(ReposController, self).__before__()
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
64
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
65 @HasPermissionAllDecorator('hg.admin')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
66 def index(self, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
67 """GET /repos: All items in the collection"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
68 # url('repos')
748
7486da5f0628 Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents: 720
diff changeset
69 cached_repo_list = ScmModel().get_repos()
247
51434007e21d proper sorting fix
Marcin Kuzminski <marcin@python-works.com>
parents: 246
diff changeset
70 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
71 return render('admin/repos/repos.html')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
72
453
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 432
diff changeset
73 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
74 def create(self):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
75 """POST /repos: Create a new item"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
76 # 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
77 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
78 _form = RepoForm()()
383
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 382
diff changeset
79 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
80 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
81 form_result = _form.to_python(dict(request.POST))
597
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 596
diff changeset
82 repo_model.create(form_result, c.rhodecode_user)
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
83 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
84 category='success')
585
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 453
diff changeset
85
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 453
diff changeset
86 if request.POST.get('user_created'):
612
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
87 action_logger(self.rhodecode_user, 'user_created_repo',
585
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 453
diff changeset
88 form_result['repo_name'], '', self.sa)
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 453
diff changeset
89 else:
612
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
90 action_logger(self.rhodecode_user, 'admin_created_repo',
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
91 form_result['repo_name'], '', self.sa)
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
92
612
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
93 except formencode.Invalid, errors:
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
94 c.new_repo = errors.value['repo_name']
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
95
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
96 if request.POST.get('user_created'):
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
97 r = render('admin/repos/repo_add_create_repository.html')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
98 else:
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
99 r = render('admin/repos/repo_add.html')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
100
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
101 return htmlfill.render(
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
102 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
103 defaults=errors.value,
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
104 errors=errors.error_dict or {},
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
105 prefix_error=False,
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
106 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
107
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
108 except Exception:
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
109 log.error(traceback.format_exc())
383
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 382
diff changeset
110 msg = _('error occured during creation of repository %s') \
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 382
diff changeset
111 % form_result.get('repo_name')
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
112 h.flash(msg, category='error')
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
113 if request.POST.get('user_created'):
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
114 return redirect(url('home'))
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
115 return redirect(url('repos'))
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
116
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
117 @HasPermissionAllDecorator('hg.admin')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
118 def new(self, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
119 """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
120 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
121 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
122
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
123 return render('admin/repos/repo_add.html')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
124
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
125 @HasPermissionAllDecorator('hg.admin')
312
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: 311
diff changeset
126 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: 311
diff changeset
127 """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
128 # 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
129 # <input type="hidden" name="_method" value="PUT" />
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
130 # Or using helpers:
312
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: 311
diff changeset
131 # 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
132 # method='put')
312
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: 311
diff changeset
133 # 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
134 repo_model = RepoModel()
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
135 changed_name = repo_name
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
136 _form = RepoForm(edit=True, old_data={'repo_name':repo_name})()
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
137
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
138 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
139 form_result = _form.to_python(dict(request.POST))
312
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: 311
diff changeset
140 repo_model.update(repo_name, form_result)
720
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 715
diff changeset
141 invalidate_cache('get_repo_cached_%s' % repo_name)
749
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 748
diff changeset
142 h.flash(_('Repository %s updated successfully' % repo_name),
331
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 312
diff changeset
143 category='success')
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
144 changed_name = form_result['repo_name']
715
df61378032f3 #48 rewrote action logger, translated action logger messages, added some extra messages. Linked and showed pushed revisions in logs
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
145 action_logger(self.rhodecode_user, 'admin_updated_repo',
df61378032f3 #48 rewrote action logger, translated action logger messages, added some extra messages. Linked and showed pushed revisions in logs
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
146 changed_name, '', self.sa)
df61378032f3 #48 rewrote action logger, translated action logger messages, added some extra messages. Linked and showed pushed revisions in logs
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
147
612
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
148 except formencode.Invalid, errors:
792
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 768
diff changeset
149 c.repo_info = repo_model.get_by_repo_name(repo_name)
877
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
150 if c.repo_info.stats:
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
151 last_rev = c.repo_info.stats.stat_on_revision
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
152 else:
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
153 last_rev = 0
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
154 c.stats_revision = last_rev
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
155 r = ScmModel().get(repo_name)
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
156 c.repo_last_rev = r.revisions[-1] if r.revisions else 0
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
157
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
158 if last_rev == 0:
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
159 c.stats_percentage = 0
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
160 else:
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
161 c.stats_percentage = '%.2f' % ((float((last_rev)) /
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
162 c.repo_last_rev) * 100)
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
163
311
15e96b5a2685 autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents: 309
diff changeset
164 c.users_array = repo_model.get_users_js()
309
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 266
diff changeset
165 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
166 return htmlfill.render(
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
167 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
168 defaults=errors.value,
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
169 errors=errors.error_dict or {},
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
170 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
171 encoding="UTF-8")
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
172
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
173 except Exception:
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
174 log.error(traceback.format_exc())
749
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 748
diff changeset
175 h.flash(_('error occurred during update of repository %s') \
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
176 % repo_name, category='error')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
177
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
178 return redirect(url('edit_repo', repo_name=changed_name))
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
179
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
180 @HasPermissionAllDecorator('hg.admin')
312
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: 311
diff changeset
181 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: 311
diff changeset
182 """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
183 # 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
184 # <input type="hidden" name="_method" value="DELETE" />
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
185 # Or using helpers:
312
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: 311
diff changeset
186 # 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
187 # method='delete')
312
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: 311
diff changeset
188 # url('repo', repo_name=ID)
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
189
335
27ef9dd22ca2 fixed demo msg
Marcin Kuzminski <marcin@python-works.com>
parents: 333
diff changeset
190 h.flash(_('deleted repository %s - disabled for demo :)')
27ef9dd22ca2 fixed demo msg
Marcin Kuzminski <marcin@python-works.com>
parents: 333
diff changeset
191 % repo_name, category='success')
271
a7608dbe47fc demo version protections
Marcin Kuzminski <marcin@python-works.com>
parents: 266
diff changeset
192 return redirect(url('repos'))
916
be73a4d29672 merged default with demo
Marcin Kuzminski <marcin@python-works.com>
parents: 677 889
diff changeset
193
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
194 repo_model = RepoModel()
792
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 768
diff changeset
195 repo = repo_model.get_by_repo_name(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
196 if not repo:
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
197 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
198 ' 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
199 ' please run the application again'
331
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 312
diff changeset
200 ' 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: 312
diff changeset
201 category='error')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
202
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
203 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
204 try:
612
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
205 action_logger(self.rhodecode_user, 'admin_deleted_repo',
585
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 453
diff changeset
206 repo_name, '', self.sa)
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
207 repo_model.delete(repo)
720
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 715
diff changeset
208 invalidate_cache('get_repo_cached_%s' % repo_name)
312
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: 311
diff changeset
209 h.flash(_('deleted repository %s') % repo_name, category='success')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
210
585
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 453
diff changeset
211 except Exception, e:
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 453
diff changeset
212 log.error(traceback.format_exc())
312
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: 311
diff changeset
213 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
214 category='error')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
215
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
216 return redirect(url('repos'))
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
217
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
218 @HasPermissionAllDecorator('hg.admin')
312
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: 311
diff changeset
219 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: 311
diff changeset
220 """
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: 311
diff changeset
221 DELETE an existing repository permission user
657
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 612
diff changeset
222 :param repo_name:
312
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: 311
diff changeset
223 """
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
224
312
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: 311
diff changeset
225 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: 311
diff changeset
226 repo_model = RepoModel()
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
227 repo_model.delete_perm_user(request.POST, repo_name)
612
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
228 except Exception, e:
312
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: 311
diff changeset
229 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: 311
diff changeset
230 category='error')
391
ec7b76d4bda4 Added initial query skipp when seting up the app.
Marcin Kuzminski <marcin@python-works.com>
parents: 383
diff changeset
231 raise HTTPInternalServerError()
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
232
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
233 @HasPermissionAllDecorator('hg.admin')
765
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
234 def repo_stats(self, repo_name):
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
235 """
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
236 DELETE an existing repository statistics
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
237 :param repo_name:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
238 """
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
239
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
240 try:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
241 repo_model = RepoModel()
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
242 repo_model.delete_stats(repo_name)
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
243 except Exception, e:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
244 h.flash(_('An error occured during deletion of repository stats'),
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
245 category='error')
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
246 return redirect(url('edit_repo', repo_name=repo_name))
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
247
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
248 @HasPermissionAllDecorator('hg.admin')
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
249 def repo_cache(self, repo_name):
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
250 """
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
251 INVALIDATE exisitings repository cache
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
252 :param repo_name:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
253 """
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
254
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
255 try:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
256 ScmModel().mark_for_invalidation(repo_name)
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
257 except Exception, e:
768
cda88b3eb09c fixed error for empty revisions on admin repo edit
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
258 h.flash(_('An error occurred during cache invalidation'),
765
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
259 category='error')
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
260 return redirect(url('edit_repo', repo_name=repo_name))
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
261
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
262 @HasPermissionAllDecorator('hg.admin')
312
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: 311
diff changeset
263 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: 311
diff changeset
264 """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: 311
diff changeset
265 # url('repo', repo_name=ID)
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
266
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
267 @HasPermissionAllDecorator('hg.admin')
312
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: 311
diff changeset
268 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: 311
diff changeset
269 """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: 311
diff changeset
270 # 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
271 repo_model = RepoModel()
888
165a97509a15 fixed small issue with caching, call to ScmModel().get needs to be before queries for new objects of Repository
Marcin Kuzminski <marcin@python-works.com>
parents: 885
diff changeset
272 r = ScmModel().get(repo_name)
877
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
273 c.repo_info = repo_model.get_by_repo_name(repo_name)
888
165a97509a15 fixed small issue with caching, call to ScmModel().get needs to be before queries for new objects of Repository
Marcin Kuzminski <marcin@python-works.com>
parents: 885
diff changeset
274
165a97509a15 fixed small issue with caching, call to ScmModel().get needs to be before queries for new objects of Repository
Marcin Kuzminski <marcin@python-works.com>
parents: 885
diff changeset
275 if c.repo_info is None:
165a97509a15 fixed small issue with caching, call to ScmModel().get needs to be before queries for new objects of Repository
Marcin Kuzminski <marcin@python-works.com>
parents: 885
diff changeset
276 h.flash(_('%s repository is not mapped to db perhaps'
165a97509a15 fixed small issue with caching, call to ScmModel().get needs to be before queries for new objects of Repository
Marcin Kuzminski <marcin@python-works.com>
parents: 885
diff changeset
277 ' it was created or renamed from the filesystem'
165a97509a15 fixed small issue with caching, call to ScmModel().get needs to be before queries for new objects of Repository
Marcin Kuzminski <marcin@python-works.com>
parents: 885
diff changeset
278 ' please run the application again'
165a97509a15 fixed small issue with caching, call to ScmModel().get needs to be before queries for new objects of Repository
Marcin Kuzminski <marcin@python-works.com>
parents: 885
diff changeset
279 ' in order to rescan repositories') % repo_name,
165a97509a15 fixed small issue with caching, call to ScmModel().get needs to be before queries for new objects of Repository
Marcin Kuzminski <marcin@python-works.com>
parents: 885
diff changeset
280 category='error')
165a97509a15 fixed small issue with caching, call to ScmModel().get needs to be before queries for new objects of Repository
Marcin Kuzminski <marcin@python-works.com>
parents: 885
diff changeset
281
165a97509a15 fixed small issue with caching, call to ScmModel().get needs to be before queries for new objects of Repository
Marcin Kuzminski <marcin@python-works.com>
parents: 885
diff changeset
282 return redirect(url('repos'))
885
9caca00de2b0 fixes #87, stupid __dict__ call on sqlalchemy session followed by update() for this dict object rewrote an object to string.
Marcin Kuzminski <marcin@python-works.com>
parents: 881
diff changeset
283
877
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
284 if c.repo_info.stats:
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
285 last_rev = c.repo_info.stats.stat_on_revision
765
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
286 else:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
287 last_rev = 0
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
288 c.stats_revision = last_rev
885
9caca00de2b0 fixes #87, stupid __dict__ call on sqlalchemy session followed by update() for this dict object rewrote an object to string.
Marcin Kuzminski <marcin@python-works.com>
parents: 881
diff changeset
289
768
cda88b3eb09c fixed error for empty revisions on admin repo edit
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
290 c.repo_last_rev = r.revisions[-1] if r.revisions else 0
cda88b3eb09c fixed error for empty revisions on admin repo edit
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
291
765
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
292 if last_rev == 0:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
293 c.stats_percentage = 0
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
294 else:
877
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
295 c.stats_percentage = '%.2f' % ((float((last_rev)) /
2b5f0e7678d4 bugfix when form had errors, it was crashing
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
296 c.repo_last_rev) * 100)
765
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
297
889
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 888
diff changeset
298 defaults = c.repo_info.get_dict()
408
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 401
diff changeset
299 if c.repo_info.user:
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 401
diff changeset
300 defaults.update({'user':c.repo_info.user.username})
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 401
diff changeset
301 else:
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 401
diff changeset
302 replacement_user = self.sa.query(User)\
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 401
diff changeset
303 .filter(User.admin == True).first().username
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 401
diff changeset
304 defaults.update({'user':replacement_user})
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
305
311
15e96b5a2685 autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents: 309
diff changeset
306 c.users_array = repo_model.get_users_js()
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
307
432
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 412
diff changeset
308 for p in c.repo_info.repo_to_perm:
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
309 defaults.update({'perm_%s' % p.user.username:
309
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 266
diff changeset
310 p.permission.permission_name})
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
311
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
312 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
313 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
314 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
315 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
316 force_defaults=False
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
317 )