annotate kallithea/controllers/admin/repos.py @ 5405:aaa2478f9d60

spelling: don't abbreviate "repository"
author Søren Løvborg <sorenl@unity3d.com>
date Fri, 14 Aug 2015 17:07:49 +0200
parents 7d0727d11104
children f6fcfc84f30c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
824
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 821
diff changeset
1 # -*- coding: utf-8 -*-
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
2 # This program is free software: you can redistribute it and/or modify
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
3 # it under the terms of the GNU General Public License as published by
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
5 # (at your option) any later version.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1161
diff changeset
6 #
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
7 # 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
8 # 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
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
10 # GNU General Public License for more details.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1161
diff changeset
11 #
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
12 # You should have received a copy of the GNU General Public License
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
14 """
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
15 kallithea.controllers.admin.repos
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
17
4212
24c0d584ba86 General renaming to Kallithea
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4211
diff changeset
18 Repositories controller for Kallithea
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
19
4211
1948ede028ef RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4208
diff changeset
20 This file was forked by the Kallithea project in July 2014.
1948ede028ef RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4208
diff changeset
21 Original author and date, and relevant copyright and licensing information is below:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
22 :created_on: Apr 7, 2010
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
23 :author: marcink
4211
1948ede028ef RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4208
diff changeset
24 :copyright: (c) 2013 RhodeCode GmbH, and others.
4208
ad38f9f93b3b Correct licensing information in individual files.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4203
diff changeset
25 :license: GPLv3, see LICENSE.md for more details.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
26 """
824
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 821
diff changeset
27
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 821
diff changeset
28 import logging
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 821
diff changeset
29 import traceback
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 821
diff changeset
30 import formencode
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
31 from formencode import htmlfill
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
32 from webob.exc import HTTPInternalServerError, HTTPForbidden, HTTPNotFound
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
33 from pylons import request, tmpl_context as c, url
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
34 from pylons.controllers.util import redirect
248
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 247
diff changeset
35 from pylons.i18n.translation import _
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
36 from sqlalchemy.sql.expression import func
824
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 821
diff changeset
37
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
38 from kallithea.lib import helpers as h
5397
7d0727d11104 cleanup: remove unused imports
Mads Kiilerich <madski@unity3d.com>
parents: 5374
diff changeset
39 from kallithea.lib.auth import LoginRequired, \
7d0727d11104 cleanup: remove unused imports
Mads Kiilerich <madski@unity3d.com>
parents: 5374
diff changeset
40 HasRepoPermissionAllDecorator, NotAnonymous, HasPermissionAny, \
7d0727d11104 cleanup: remove unused imports
Mads Kiilerich <madski@unity3d.com>
parents: 5374
diff changeset
41 HasRepoPermissionAnyDecorator
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
42 from kallithea.lib.base import BaseRepoController, render
5397
7d0727d11104 cleanup: remove unused imports
Mads Kiilerich <madski@unity3d.com>
parents: 5374
diff changeset
43 from kallithea.lib.utils import action_logger, jsonify
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
44 from kallithea.lib.vcs import RepositoryError
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
45 from kallithea.model.meta import Session
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
46 from kallithea.model.db import User, Repository, UserFollowing, RepoGroup,\
4203
9daad8c50b37 Rename database classes (but not table names)
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4197
diff changeset
47 Setting, RepositoryField
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
48 from kallithea.model.forms import RepoForm, RepoFieldForm, RepoPermsForm
5289
28db71c6349e scm: introduce AvailableRepoGroupChoices
Mads Kiilerich <madski@unity3d.com>
parents: 5288
diff changeset
49 from kallithea.model.scm import ScmModel, AvailableRepoGroupChoices, RepoList
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
50 from kallithea.model.repo import RepoModel
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
51 from kallithea.lib.compat import json
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
52 from kallithea.lib.exceptions import AttachedForksError
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
53 from kallithea.lib.utils2 import safe_int
824
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 821
diff changeset
54
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
55 log = logging.getLogger(__name__)
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
56
1245
5f2fbab7c429 PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
57
3288
6cdf2cd9d9d8 repo edit: it is a repo thing more than an admin thing - show it that way in ui and url
Mads Kiilerich <madski@unity3d.com>
parents: 3245
diff changeset
58 class ReposController(BaseRepoController):
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
59 """
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
60 REST Controller styled on the Atom Publishing Protocol"""
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
61 # 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
62 # file has a resource setup:
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
63 # map.resource('repo', 'repos')
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
64
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 220
diff changeset
65 @LoginRequired()
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
66 def __before__(self):
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
67 super(ReposController, self).__before__()
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
68
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
69 def _load_repo(self, repo_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
70 repo_obj = Repository.get_by_repo_name(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
71
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
72 if repo_obj is None:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
73 h.not_mapped_error(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
74 return redirect(url('repos'))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
75
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
76 return repo_obj
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
77
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
78 def __load_defaults(self, repo=None):
5288
cb362e3439dd repos: refactor repo group handling - extract generic functionality that can be used consistently
Mads Kiilerich <madski@unity3d.com>
parents: 5285
diff changeset
79 top_perms = ['hg.create.repository']
cb362e3439dd repos: refactor repo group handling - extract generic functionality that can be used consistently
Mads Kiilerich <madski@unity3d.com>
parents: 5285
diff changeset
80 repo_group_perms = ['group.admin']
cb362e3439dd repos: refactor repo group handling - extract generic functionality that can be used consistently
Mads Kiilerich <madski@unity3d.com>
parents: 5285
diff changeset
81 if HasPermissionAny('hg.create.write_on_repogroup.true')():
cb362e3439dd repos: refactor repo group handling - extract generic functionality that can be used consistently
Mads Kiilerich <madski@unity3d.com>
parents: 5285
diff changeset
82 repo_group_perms.append('group.write')
cb362e3439dd repos: refactor repo group handling - extract generic functionality that can be used consistently
Mads Kiilerich <madski@unity3d.com>
parents: 5285
diff changeset
83 extras = [] if repo is None else [repo.group]
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
84
5289
28db71c6349e scm: introduce AvailableRepoGroupChoices
Mads Kiilerich <madski@unity3d.com>
parents: 5288
diff changeset
85 c.repo_groups = AvailableRepoGroupChoices(top_perms, repo_group_perms, extras)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
86
5288
cb362e3439dd repos: refactor repo group handling - extract generic functionality that can be used consistently
Mads Kiilerich <madski@unity3d.com>
parents: 5285
diff changeset
87 c.landing_revs_choices, c.landing_revs = ScmModel().get_repo_landing_revs(repo)
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1121
diff changeset
88
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1121
diff changeset
89 def __load_data(self, repo_name=None):
1112
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1106
diff changeset
90 """
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1106
diff changeset
91 Load defaults settings for edit, and update
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1161
diff changeset
92
1112
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1106
diff changeset
93 :param repo_name:
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1106
diff changeset
94 """
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
95 c.repo_info = self._load_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
96 self.__load_defaults(c.repo_info)
1112
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1106
diff changeset
97
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1561
diff changeset
98 defaults = RepoModel()._get_defaults(repo_name)
5285
fdf6df128d89 remote: simplify clone_uri UI
Mads Kiilerich <madski@unity3d.com>
parents: 5281
diff changeset
99 defaults['clone_uri'] = c.repo_info.clone_uri_hidden # don't show password
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1807
diff changeset
100
1112
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1106
diff changeset
101 return defaults
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1106
diff changeset
102
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
103 def index(self, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
104 """GET /repos: All items in the collection"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
105 # url('repos')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
106 _list = Repository.query()\
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
107 .order_by(func.lower(Repository.repo_name))\
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
108 .all()
1344
eef7a1b953e8 Admin view will see repos_groups in main list
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
109
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
110 c.repos_list = RepoList(_list, perm_set=['repository.admin'])
3154
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3110
diff changeset
111 repos_data = RepoModel().get_repos_as_dict(repos_list=c.repos_list,
3245
8f3cc21d83e6 fixes issue #739 Delete/Edit repositories should only point to admin links if the user is an super admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 3239
diff changeset
112 admin=True,
8f3cc21d83e6 fixes issue #739 Delete/Edit repositories should only point to admin links if the user is an super admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 3239
diff changeset
113 super_user_actions=True)
3154
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3110
diff changeset
114 #json used to render the grid
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3110
diff changeset
115 c.data = json.dumps(repos_data)
2664
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
116
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
117 return render('admin/repos/repos.html')
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
118
3333
069884383cc7 Implemented #738 Giving a user WRITE+ permissions on folder should not allow repo creation in root folder.
Marcin Kuzminski <marcin@python-works.com>
parents: 3315
diff changeset
119 @NotAnonymous()
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
120 def create(self):
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
121 """
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
122 POST /repos: Create a new item"""
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
123 # url('repos')
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
124
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1121
diff changeset
125 self.__load_defaults()
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
126 form_result = {}
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
127 task_id = None
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
128 try:
5271
f43dc1913984 auth: various minor cleanup
Mads Kiilerich <madski@unity3d.com>
parents: 5270
diff changeset
129 # CanWriteGroup validators checks permissions of this POST
5294
cd655fbd79ce repogroups: compute repo group id lists on demand where they are needed
Mads Kiilerich <madski@unity3d.com>
parents: 5289
diff changeset
130 form_result = RepoForm(repo_groups=c.repo_groups,
2460
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
131 landing_revs=c.landing_revs_choices)()\
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1121
diff changeset
132 .to_python(dict(request.POST))
3333
069884383cc7 Implemented #738 Giving a user WRITE+ permissions on folder should not allow repo creation in root folder.
Marcin Kuzminski <marcin@python-works.com>
parents: 3315
diff changeset
133
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
134 # create is done sometimes async on celery, db transaction
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
135 # management is handled there.
4197
d208416c84c6 Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
136 task = RepoModel().create(form_result, self.authuser.user_id)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
137 from celery.result import BaseAsyncResult
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
138 if isinstance(task, BaseAsyncResult):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
139 task_id = task.task_id
5374
d69aa464f373 cleanup: consistently use 'except ... as ...:'
Mads Kiilerich <madski@unity3d.com>
parents: 5307
diff changeset
140 except formencode.Invalid as errors:
5271
f43dc1913984 auth: various minor cleanup
Mads Kiilerich <madski@unity3d.com>
parents: 5270
diff changeset
141 log.info(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
142 return htmlfill.render(
3333
069884383cc7 Implemented #738 Giving a user WRITE+ permissions on folder should not allow repo creation in root folder.
Marcin Kuzminski <marcin@python-works.com>
parents: 3315
diff changeset
143 render('admin/repos/repo_add.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
144 defaults=errors.value,
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
145 errors=errors.error_dict or {},
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
146 prefix_error=False,
4941
c04c2734e32f controllers: consistently use formfill.render with force_defaults=False
Mads Kiilerich <madski@unity3d.com>
parents: 4917
diff changeset
147 force_defaults=False,
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
148 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
149
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 except Exception:
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
151 log.error(traceback.format_exc())
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
152 msg = (_('Error creating repository %s')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
153 % form_result.get('repo_name'))
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
154 h.flash(msg, category='error')
3333
069884383cc7 Implemented #738 Giving a user WRITE+ permissions on folder should not allow repo creation in root folder.
Marcin Kuzminski <marcin@python-works.com>
parents: 3315
diff changeset
155 return redirect(url('home'))
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
156
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
157 return redirect(h.url('repo_creating_home',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
158 repo_name=form_result['repo_name_full'],
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
159 task_id=task_id))
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
160
3629
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
161 @NotAnonymous()
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
162 def create_repository(self):
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
163 """GET /_admin/create_repository: Form to create a new item"""
5288
cb362e3439dd repos: refactor repo group handling - extract generic functionality that can be used consistently
Mads Kiilerich <madski@unity3d.com>
parents: 5285
diff changeset
164 self.__load_defaults()
cb362e3439dd repos: refactor repo group handling - extract generic functionality that can be used consistently
Mads Kiilerich <madski@unity3d.com>
parents: 5285
diff changeset
165 if not c.repo_groups:
cb362e3439dd repos: refactor repo group handling - extract generic functionality that can be used consistently
Mads Kiilerich <madski@unity3d.com>
parents: 5285
diff changeset
166 raise HTTPForbidden
3629
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
167 parent_group = request.GET.get('parent_group')
3233
11b005b2d5e8 use the GET parent_group param to pre-fill the group choice
Marcin Kuzminski <marcin@python-works.com>
parents: 3154
diff changeset
168
3089
4cc9bb83ecb4 Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents: 3056
diff changeset
169 ## apply the defaults from defaults page
4203
9daad8c50b37 Rename database classes (but not table names)
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4197
diff changeset
170 defaults = Setting.get_default_repo_settings(strip_prefix=True)
3233
11b005b2d5e8 use the GET parent_group param to pre-fill the group choice
Marcin Kuzminski <marcin@python-works.com>
parents: 3154
diff changeset
171 if parent_group:
5288
cb362e3439dd repos: refactor repo group handling - extract generic functionality that can be used consistently
Mads Kiilerich <madski@unity3d.com>
parents: 5285
diff changeset
172 prg = RepoGroup.get(parent_group)
cb362e3439dd repos: refactor repo group handling - extract generic functionality that can be used consistently
Mads Kiilerich <madski@unity3d.com>
parents: 5285
diff changeset
173 if prg is None or not any(rgc[0] == prg.group_id
cb362e3439dd repos: refactor repo group handling - extract generic functionality that can be used consistently
Mads Kiilerich <madski@unity3d.com>
parents: 5285
diff changeset
174 for rgc in c.repo_groups):
cb362e3439dd repos: refactor repo group handling - extract generic functionality that can be used consistently
Mads Kiilerich <madski@unity3d.com>
parents: 5285
diff changeset
175 raise HTTPForbidden
3233
11b005b2d5e8 use the GET parent_group param to pre-fill the group choice
Marcin Kuzminski <marcin@python-works.com>
parents: 3154
diff changeset
176 defaults.update({'repo_group': parent_group})
11b005b2d5e8 use the GET parent_group param to pre-fill the group choice
Marcin Kuzminski <marcin@python-works.com>
parents: 3154
diff changeset
177
3089
4cc9bb83ecb4 Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents: 3056
diff changeset
178 return htmlfill.render(
4cc9bb83ecb4 Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents: 3056
diff changeset
179 render('admin/repos/repo_add.html'),
4cc9bb83ecb4 Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents: 3056
diff changeset
180 defaults=defaults,
4cc9bb83ecb4 Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents: 3056
diff changeset
181 errors={},
4cc9bb83ecb4 Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents: 3056
diff changeset
182 prefix_error=False,
4941
c04c2734e32f controllers: consistently use formfill.render with force_defaults=False
Mads Kiilerich <madski@unity3d.com>
parents: 4917
diff changeset
183 encoding="UTF-8",
c04c2734e32f controllers: consistently use formfill.render with force_defaults=False
Mads Kiilerich <madski@unity3d.com>
parents: 4917
diff changeset
184 force_defaults=False)
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
185
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
186 @LoginRequired()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
187 @NotAnonymous()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
188 def repo_creating(self, repo_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
189 c.repo = repo_name
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
190 c.task_id = request.GET.get('task_id')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
191 if not c.repo:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
192 raise HTTPNotFound()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
193 return render('admin/repos/repo_creating.html')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
194
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
195 @LoginRequired()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
196 @NotAnonymous()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
197 @jsonify
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
198 def repo_check(self, repo_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
199 c.repo = repo_name
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
200 task_id = request.GET.get('task_id')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
201
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
202 if task_id and task_id not in ['None']:
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
203 from kallithea import CELERY_ON
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
204 from celery.result import AsyncResult
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
205 if CELERY_ON:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
206 task = AsyncResult(task_id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
207 if task.failed():
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
208 raise HTTPInternalServerError(task.traceback)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
209
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
210 repo = Repository.get_by_repo_name(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
211 if repo and repo.repo_state == Repository.STATE_CREATED:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
212 if repo.clone_uri:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
213 h.flash(_('Created repository %s from %s')
5285
fdf6df128d89 remote: simplify clone_uri UI
Mads Kiilerich <madski@unity3d.com>
parents: 5281
diff changeset
214 % (repo.repo_name, repo.clone_uri_hidden), category='success')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
215 else:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
216 repo_url = h.link_to(repo.repo_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
217 h.url('summary_home',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
218 repo_name=repo.repo_name))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
219 fork = repo.fork
5306
63bed817308c cleanup: check for None object identity in cases where that is what the 'contract' says
Mads Kiilerich <madski@unity3d.com>
parents: 5294
diff changeset
220 if fork is not None:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
221 fork_name = fork.repo_name
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
222 h.flash(h.literal(_('Forked repository %s as %s')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
223 % (fork_name, repo_url)), category='success')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
224 else:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
225 h.flash(h.literal(_('Created repository %s') % repo_url),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
226 category='success')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
227 return {'result': True}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
228 return {'result': False}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
229
3629
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
230 @HasRepoPermissionAllDecorator('repository.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
231 def update(self, repo_name):
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
232 """
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
233 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
234 # 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
235 # <input type="hidden" name="_method" value="PUT" />
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
236 # Or using helpers:
5307
ab5c4d84f99c repos: fix abuse of dead 'repo' routing
Mads Kiilerich <madski@unity3d.com>
parents: 5306
diff changeset
237 # h.form(url('put_repo', repo_name=ID),
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
238 # method='put')
5307
ab5c4d84f99c repos: fix abuse of dead 'repo' routing
Mads Kiilerich <madski@unity3d.com>
parents: 5306
diff changeset
239 # url('put_repo', repo_name=ID)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
240 c.repo_info = self._load_repo(repo_name)
5288
cb362e3439dd repos: refactor repo group handling - extract generic functionality that can be used consistently
Mads Kiilerich <madski@unity3d.com>
parents: 5285
diff changeset
241 self.__load_defaults(c.repo_info)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
242 c.active = 'settings'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
243 c.repo_fields = RepositoryField.query()\
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
244 .filter(RepositoryField.repository == c.repo_info).all()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
245
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
246 repo_model = RepoModel()
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
247 changed_name = repo_name
3524
af96fb19b53a Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents: 3410
diff changeset
248 repo = Repository.get_by_repo_name(repo_name)
3863
794e6eaad4aa fix required repo_type param on repo edit form
Marcin Kuzminski <marcin@python-works.com>
parents: 3826
diff changeset
249 old_data = {
794e6eaad4aa fix required repo_type param on repo edit form
Marcin Kuzminski <marcin@python-works.com>
parents: 3826
diff changeset
250 'repo_name': repo_name,
794e6eaad4aa fix required repo_type param on repo edit form
Marcin Kuzminski <marcin@python-works.com>
parents: 3826
diff changeset
251 'repo_group': repo.group.get_dict() if repo.group else {},
794e6eaad4aa fix required repo_type param on repo edit form
Marcin Kuzminski <marcin@python-works.com>
parents: 3826
diff changeset
252 'repo_type': repo.repo_type,
794e6eaad4aa fix required repo_type param on repo edit form
Marcin Kuzminski <marcin@python-works.com>
parents: 3826
diff changeset
253 }
794e6eaad4aa fix required repo_type param on repo edit form
Marcin Kuzminski <marcin@python-works.com>
parents: 3826
diff changeset
254 _form = RepoForm(edit=True, old_data=old_data,
5294
cd655fbd79ce repogroups: compute repo group id lists on demand where they are needed
Mads Kiilerich <madski@unity3d.com>
parents: 5289
diff changeset
255 repo_groups=c.repo_groups,
2460
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
256 landing_revs=c.landing_revs_choices)()
3863
794e6eaad4aa fix required repo_type param on repo edit form
Marcin Kuzminski <marcin@python-works.com>
parents: 3826
diff changeset
257
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
258 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
259 form_result = _form.to_python(dict(request.POST))
3089
4cc9bb83ecb4 Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents: 3056
diff changeset
260 repo = repo_model.update(repo_name, **form_result)
3693
6843cabe9925 removed duplicated logic of how we invalidate caches for repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3668
diff changeset
261 ScmModel().mark_for_invalidation(repo_name)
2570
94ae02ca5f00 i18n improve
Takumi IINO <trot.thunder@gmail.com>
parents: 2524
diff changeset
262 h.flash(_('Repository %s updated successfully') % repo_name,
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
263 category='success')
1539
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
264 changed_name = repo.repo_name
4197
d208416c84c6 Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
265 action_logger(self.authuser, 'admin_updated_repo',
2375
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2142
diff changeset
266 changed_name, self.ip_addr, self.sa)
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2660
diff changeset
267 Session().commit()
5374
d69aa464f373 cleanup: consistently use 'except ... as ...:'
Mads Kiilerich <madski@unity3d.com>
parents: 5307
diff changeset
268 except formencode.Invalid as errors:
5271
f43dc1913984 auth: various minor cleanup
Mads Kiilerich <madski@unity3d.com>
parents: 5270
diff changeset
269 log.info(errors)
1112
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1106
diff changeset
270 defaults = self.__load_data(repo_name)
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1106
diff changeset
271 defaults.update(errors.value)
5269
14e2291a8f0b repos: fix missing users_array on form validation errors after 790f01320369
Mads Kiilerich <madski@unity3d.com>
parents: 5243
diff changeset
272 c.users_array = repo_model.get_users_js()
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
273 return htmlfill.render(
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
274 render('admin/repos/repo_edit.html'),
1112
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1106
diff changeset
275 defaults=defaults,
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
276 errors=errors.error_dict or {},
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
277 prefix_error=False,
4941
c04c2734e32f controllers: consistently use formfill.render with force_defaults=False
Mads Kiilerich <madski@unity3d.com>
parents: 4917
diff changeset
278 encoding="UTF-8",
c04c2734e32f controllers: consistently use formfill.render with force_defaults=False
Mads Kiilerich <madski@unity3d.com>
parents: 4917
diff changeset
279 force_defaults=False)
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
280
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
281 except Exception:
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
282 log.error(traceback.format_exc())
3565
a8f2d78d14ea consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents: 3547
diff changeset
283 h.flash(_('Error occurred during update of repository %s') \
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
284 % repo_name, category='error')
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 323
diff changeset
285 return redirect(url('edit_repo', repo_name=changed_name))
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
286
3629
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
287 @HasRepoPermissionAllDecorator('repository.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
288 def delete(self, repo_name):
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
289 """
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
290 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
291 # 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
292 # <input type="hidden" name="_method" value="DELETE" />
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
293 # Or using helpers:
5307
ab5c4d84f99c repos: fix abuse of dead 'repo' routing
Mads Kiilerich <madski@unity3d.com>
parents: 5306
diff changeset
294 # h.form(url('delete_repo', repo_name=ID),
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
295 # method='delete')
5307
ab5c4d84f99c repos: fix abuse of dead 'repo' routing
Mads Kiilerich <madski@unity3d.com>
parents: 5306
diff changeset
296 # url('delete_repo', repo_name=ID)
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
297
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
298 repo_model = RepoModel()
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 711
diff changeset
299 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
300 if not repo:
3110
144128efc6ab - #683 fixed difference between messages about not mapped repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3089
diff changeset
301 h.not_mapped_error(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
302 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
303 try:
3391
f282c81ff532 implemented #689 Deleting Repositories with Forks Should Be Easier
Marcin Kuzminski <marcin@python-works.com>
parents: 3372
diff changeset
304 _forks = repo.forks.count()
3641
b44979649915 recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
305 handle_forks = None
3391
f282c81ff532 implemented #689 Deleting Repositories with Forks Should Be Easier
Marcin Kuzminski <marcin@python-works.com>
parents: 3372
diff changeset
306 if _forks and request.POST.get('forks'):
f282c81ff532 implemented #689 Deleting Repositories with Forks Should Be Easier
Marcin Kuzminski <marcin@python-works.com>
parents: 3372
diff changeset
307 do = request.POST['forks']
f282c81ff532 implemented #689 Deleting Repositories with Forks Should Be Easier
Marcin Kuzminski <marcin@python-works.com>
parents: 3372
diff changeset
308 if do == 'detach_forks':
3641
b44979649915 recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
309 handle_forks = 'detach'
3565
a8f2d78d14ea consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents: 3547
diff changeset
310 h.flash(_('Detached %s forks') % _forks, category='success')
3391
f282c81ff532 implemented #689 Deleting Repositories with Forks Should Be Easier
Marcin Kuzminski <marcin@python-works.com>
parents: 3372
diff changeset
311 elif do == 'delete_forks':
3641
b44979649915 recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
312 handle_forks = 'delete'
3565
a8f2d78d14ea consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents: 3547
diff changeset
313 h.flash(_('Deleted %s forks') % _forks, category='success')
3641
b44979649915 recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
314 repo_model.delete(repo, forks=handle_forks)
4197
d208416c84c6 Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
315 action_logger(self.authuser, 'admin_deleted_repo',
3641
b44979649915 recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
316 repo_name, self.ip_addr, self.sa)
3693
6843cabe9925 removed duplicated logic of how we invalidate caches for repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3668
diff changeset
317 ScmModel().mark_for_invalidation(repo_name)
3565
a8f2d78d14ea consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents: 3547
diff changeset
318 h.flash(_('Deleted repository %s') % repo_name, category='success')
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2660
diff changeset
319 Session().commit()
3641
b44979649915 recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
320 except AttachedForksError:
b44979649915 recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
321 h.flash(_('Cannot delete %s it still contains attached forks')
b44979649915 recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
322 % repo_name, category='warning')
1361
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
323
3641
b44979649915 recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
324 except Exception:
537
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
325 log.error(traceback.format_exc())
860
5f7731e3ab4d fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
326 h.flash(_('An error occurred 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
327 category='error')
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
328
4307
ee43e19c18b7 repos: after removing a repo show its group
Mads Kiilerich <madski@unity3d.com>
parents: 4212
diff changeset
329 if repo.group:
ee43e19c18b7 repos: after removing a repo show its group
Mads Kiilerich <madski@unity3d.com>
parents: 4212
diff changeset
330 return redirect(url('repos_group_home', group_name=repo.group.group_name))
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
331 return redirect(url('repos'))
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
332
1869
682057a38cd3 white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1828
diff changeset
333 @HasRepoPermissionAllDecorator('repository.admin')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
334 def edit(self, repo_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
335 """GET /repo_name/settings: Form to edit an existing item"""
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
336 # url('edit_repo', repo_name=ID)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
337 defaults = self.__load_data(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
338 c.repo_fields = RepositoryField.query()\
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
339 .filter(RepositoryField.repository == c.repo_info).all()
5243
790f01320369 autocomplete: fix completion of repository owner
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 4990
diff changeset
340 repo_model = RepoModel()
790f01320369 autocomplete: fix completion of repository owner
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 4990
diff changeset
341 c.users_array = repo_model.get_users_js()
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
342 c.active = 'settings'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
343 return htmlfill.render(
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
344 render('admin/repos/repo_edit.html'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
345 defaults=defaults,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
346 encoding="UTF-8",
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
347 force_defaults=False)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
348
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
349 @HasRepoPermissionAllDecorator('repository.admin')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
350 def edit_permissions(self, repo_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
351 """GET /repo_name/settings: Form to edit an existing item"""
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
352 # url('edit_repo', repo_name=ID)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
353 c.repo_info = self._load_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
354 repo_model = RepoModel()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
355 c.users_array = repo_model.get_users_js()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
356 c.user_groups_array = repo_model.get_user_groups_js()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
357 c.active = 'permissions'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
358 defaults = RepoModel()._get_defaults(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
359
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
360 return htmlfill.render(
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
361 render('admin/repos/repo_edit.html'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
362 defaults=defaults,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
363 encoding="UTF-8",
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
364 force_defaults=False)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
365
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
366 def edit_permissions_update(self, repo_name):
3628
c734686b3cf2 moved permission management into separate entity.
Marcin Kuzminski <marcin@python-works.com>
parents: 3565
diff changeset
367 form = RepoPermsForm()().to_python(request.POST)
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
368 RepoModel()._update_permissions(repo_name, form['perms_new'],
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
369 form['perms_updates'])
3628
c734686b3cf2 moved permission management into separate entity.
Marcin Kuzminski <marcin@python-works.com>
parents: 3565
diff changeset
370 #TODO: implement this
4197
d208416c84c6 Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
371 #action_logger(self.authuser, 'admin_changed_repo_permissions',
3628
c734686b3cf2 moved permission management into separate entity.
Marcin Kuzminski <marcin@python-works.com>
parents: 3565
diff changeset
372 # repo_name, self.ip_addr, self.sa)
c734686b3cf2 moved permission management into separate entity.
Marcin Kuzminski <marcin@python-works.com>
parents: 3565
diff changeset
373 Session().commit()
3654
ec6354949623 Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents: 3641
diff changeset
374 h.flash(_('Repository permissions updated'), category='success')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
375 return redirect(url('edit_repo_perms', repo_name=repo_name))
3628
c734686b3cf2 moved permission management into separate entity.
Marcin Kuzminski <marcin@python-works.com>
parents: 3565
diff changeset
376
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
377 def edit_permissions_revoke(self, repo_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
378 try:
3715
25dbbdae3ed9 consistent handling of grant/revoke of permissions widgets
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
379 obj_type = request.POST.get('obj_type')
25dbbdae3ed9 consistent handling of grant/revoke of permissions widgets
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
380 obj_id = None
25dbbdae3ed9 consistent handling of grant/revoke of permissions widgets
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
381 if obj_type == 'user':
25dbbdae3ed9 consistent handling of grant/revoke of permissions widgets
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
382 obj_id = safe_int(request.POST.get('user_id'))
25dbbdae3ed9 consistent handling of grant/revoke of permissions widgets
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
383 elif obj_type == 'user_group':
25dbbdae3ed9 consistent handling of grant/revoke of permissions widgets
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
384 obj_id = safe_int(request.POST.get('user_group_id'))
25dbbdae3ed9 consistent handling of grant/revoke of permissions widgets
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
385
25dbbdae3ed9 consistent handling of grant/revoke of permissions widgets
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
386 if obj_type == 'user':
25dbbdae3ed9 consistent handling of grant/revoke of permissions widgets
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
387 RepoModel().revoke_user_permission(repo=repo_name, user=obj_id)
25dbbdae3ed9 consistent handling of grant/revoke of permissions widgets
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
388 elif obj_type == 'user_group':
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
389 RepoModel().revoke_user_group_permission(
3715
25dbbdae3ed9 consistent handling of grant/revoke of permissions widgets
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
390 repo=repo_name, group_name=obj_id
25dbbdae3ed9 consistent handling of grant/revoke of permissions widgets
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
391 )
3628
c734686b3cf2 moved permission management into separate entity.
Marcin Kuzminski <marcin@python-works.com>
parents: 3565
diff changeset
392 #TODO: implement this
4197
d208416c84c6 Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
393 #action_logger(self.authuser, 'admin_revoked_repo_permissions',
3628
c734686b3cf2 moved permission management into separate entity.
Marcin Kuzminski <marcin@python-works.com>
parents: 3565
diff changeset
394 # repo_name, self.ip_addr, self.sa)
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2660
diff changeset
395 Session().commit()
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1869
diff changeset
396 except Exception:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1869
diff changeset
397 log.error(traceback.format_exc())
3715
25dbbdae3ed9 consistent handling of grant/revoke of permissions widgets
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
398 h.flash(_('An error occurred during revoking of permission'),
1015
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1012
diff changeset
399 category='error')
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1012
diff changeset
400 raise HTTPInternalServerError()
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1012
diff changeset
401
3629
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
402 @HasRepoPermissionAllDecorator('repository.admin')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
403 def edit_fields(self, repo_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
404 """GET /repo_name/settings: Form to edit an existing item"""
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
405 # url('edit_repo', repo_name=ID)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
406 c.repo_info = self._load_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
407 c.repo_fields = RepositoryField.query()\
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
408 .filter(RepositoryField.repository == c.repo_info).all()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
409 c.active = 'fields'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
410 if request.POST:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
411
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
412 return redirect(url('repo_edit_fields'))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
413 return render('admin/repos/repo_edit.html')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
414
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
415 @HasRepoPermissionAllDecorator('repository.admin')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
416 def create_repo_field(self, repo_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
417 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
418 form_result = RepoFieldForm()().to_python(dict(request.POST))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
419 new_field = RepositoryField()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
420 new_field.repository = Repository.get_by_repo_name(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
421 new_field.field_key = form_result['new_field_key']
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
422 new_field.field_type = form_result['new_field_type'] # python type
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
423 new_field.field_value = form_result['new_field_value'] # set initial blank value
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
424 new_field.field_desc = form_result['new_field_desc']
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
425 new_field.field_label = form_result['new_field_label']
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
426 Session().add(new_field)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
427 Session().commit()
5374
d69aa464f373 cleanup: consistently use 'except ... as ...:'
Mads Kiilerich <madski@unity3d.com>
parents: 5307
diff changeset
428 except Exception as e:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
429 log.error(traceback.format_exc())
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
430 msg = _('An error occurred during creation of field')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
431 if isinstance(e, formencode.Invalid):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
432 msg += ". " + e.msg
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
433 h.flash(msg, category='error')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
434 return redirect(url('edit_repo_fields', repo_name=repo_name))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
435
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
436 @HasRepoPermissionAllDecorator('repository.admin')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
437 def delete_repo_field(self, repo_name, field_id):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
438 field = RepositoryField.get_or_404(field_id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
439 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
440 Session().delete(field)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
441 Session().commit()
5374
d69aa464f373 cleanup: consistently use 'except ... as ...:'
Mads Kiilerich <madski@unity3d.com>
parents: 5307
diff changeset
442 except Exception as e:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
443 log.error(traceback.format_exc())
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
444 msg = _('An error occurred during removal of field')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
445 h.flash(msg, category='error')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
446 return redirect(url('edit_repo_fields', repo_name=repo_name))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
447
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
448 @HasRepoPermissionAllDecorator('repository.admin')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
449 def edit_advanced(self, repo_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
450 """GET /repo_name/settings: Form to edit an existing item"""
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
451 # url('edit_repo', repo_name=ID)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
452 c.repo_info = self._load_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
453 c.default_user_id = User.get_default_user().user_id
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
454 c.in_public_journal = UserFollowing.query()\
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
455 .filter(UserFollowing.user_id == c.default_user_id)\
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
456 .filter(UserFollowing.follows_repository == c.repo_info).scalar()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
457
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
458 _repos = Repository.query().order_by(Repository.repo_name).all()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
459 read_access_repos = RepoList(_repos)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
460 c.repos_list = [(None, _('-- Not a fork --'))]
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
461 c.repos_list += [(x.repo_id, x.repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
462 for x in read_access_repos
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
463 if x.repo_id != c.repo_info.repo_id]
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
464
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
465 defaults = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
466 'id_fork_of': c.repo_info.fork.repo_id if c.repo_info.fork else ''
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
467 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
468
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
469 c.active = 'advanced'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
470 if request.POST:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
471 return redirect(url('repo_edit_advanced'))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
472 return htmlfill.render(
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
473 render('admin/repos/repo_edit.html'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
474 defaults=defaults,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
475 encoding="UTF-8",
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
476 force_defaults=False)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
477
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
478 @HasRepoPermissionAllDecorator('repository.admin')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
479 def edit_advanced_journal(self, repo_name):
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
480 """
4917
0bc8975f5365 controllers: trivial typo fixes
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 4307
diff changeset
481 Sets this repository to be visible in public journal,
0bc8975f5365 controllers: trivial typo fixes
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 4307
diff changeset
482 in other words asking default user to follow this repo
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1161
diff changeset
483
708
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
484 :param repo_name:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
485 """
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
486
4990
959a9fa7d1a1 controllers: remove old auth_token checks - it was only partial CSRF protection
Mads Kiilerich <madski@unity3d.com>
parents: 4941
diff changeset
487 try:
959a9fa7d1a1 controllers: remove old auth_token checks - it was only partial CSRF protection
Mads Kiilerich <madski@unity3d.com>
parents: 4941
diff changeset
488 repo_id = Repository.get_by_repo_name(repo_name).repo_id
959a9fa7d1a1 controllers: remove old auth_token checks - it was only partial CSRF protection
Mads Kiilerich <madski@unity3d.com>
parents: 4941
diff changeset
489 user_id = User.get_default_user().user_id
959a9fa7d1a1 controllers: remove old auth_token checks - it was only partial CSRF protection
Mads Kiilerich <madski@unity3d.com>
parents: 4941
diff changeset
490 self.scm_model.toggle_following_repo(repo_id, user_id)
959a9fa7d1a1 controllers: remove old auth_token checks - it was only partial CSRF protection
Mads Kiilerich <madski@unity3d.com>
parents: 4941
diff changeset
491 h.flash(_('Updated repository visibility in public journal'),
959a9fa7d1a1 controllers: remove old auth_token checks - it was only partial CSRF protection
Mads Kiilerich <madski@unity3d.com>
parents: 4941
diff changeset
492 category='success')
959a9fa7d1a1 controllers: remove old auth_token checks - it was only partial CSRF protection
Mads Kiilerich <madski@unity3d.com>
parents: 4941
diff changeset
493 Session().commit()
959a9fa7d1a1 controllers: remove old auth_token checks - it was only partial CSRF protection
Mads Kiilerich <madski@unity3d.com>
parents: 4941
diff changeset
494 except Exception:
959a9fa7d1a1 controllers: remove old auth_token checks - it was only partial CSRF protection
Mads Kiilerich <madski@unity3d.com>
parents: 4941
diff changeset
495 h.flash(_('An error occurred during setting this'
959a9fa7d1a1 controllers: remove old auth_token checks - it was only partial CSRF protection
Mads Kiilerich <madski@unity3d.com>
parents: 4941
diff changeset
496 ' repository in public journal'),
959a9fa7d1a1 controllers: remove old auth_token checks - it was only partial CSRF protection
Mads Kiilerich <madski@unity3d.com>
parents: 4941
diff changeset
497 category='error')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
498 return redirect(url('edit_repo_advanced', repo_name=repo_name))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
499
708
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
500
3629
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
501 @HasRepoPermissionAllDecorator('repository.admin')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
502 def edit_advanced_fork(self, repo_name):
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
503 """
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
504 Mark given repository as a fork of another
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1161
diff changeset
505
708
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
506 :param repo_name:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
507 """
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
508 try:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
509 fork_id = request.POST.get('id_fork_of')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
510 repo = ScmModel().mark_as_fork(repo_name, fork_id,
4197
d208416c84c6 Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
511 self.authuser.username)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
512 fork = repo.fork.repo_name if repo.fork else _('Nothing')
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2660
diff changeset
513 Session().commit()
5405
aaa2478f9d60 spelling: don't abbreviate "repository"
Søren Løvborg <sorenl@unity3d.com>
parents: 5397
diff changeset
514 h.flash(_('Marked repository %s as fork of %s') % (repo_name, fork),
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
515 category='success')
5374
d69aa464f373 cleanup: consistently use 'except ... as ...:'
Mads Kiilerich <madski@unity3d.com>
parents: 5307
diff changeset
516 except RepositoryError as e:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
517 log.error(traceback.format_exc())
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
518 h.flash(str(e), category='error')
5374
d69aa464f373 cleanup: consistently use 'except ... as ...:'
Mads Kiilerich <madski@unity3d.com>
parents: 5307
diff changeset
519 except Exception as e:
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
520 log.error(traceback.format_exc())
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
521 h.flash(_('An error occurred during this operation'),
708
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
522 category='error')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
523
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
524 return redirect(url('edit_repo_advanced', repo_name=repo_name))
708
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
525
3629
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
526 @HasRepoPermissionAllDecorator('repository.admin')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
527 def edit_advanced_locking(self, repo_name):
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
528 """
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
529 Unlock repository when it is locked !
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
530
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
531 :param repo_name:
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
532 """
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
533 try:
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
534 repo = Repository.get_by_repo_name(repo_name)
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
535 if request.POST.get('set_lock'):
4197
d208416c84c6 Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
536 Repository.lock(repo, c.authuser.user_id)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
537 h.flash(_('Locked repository'), category='success')
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
538 elif request.POST.get('set_unlock'):
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
539 Repository.unlock(repo)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
540 h.flash(_('Unlocked repository'), category='success')
5374
d69aa464f373 cleanup: consistently use 'except ... as ...:'
Mads Kiilerich <madski@unity3d.com>
parents: 5307
diff changeset
541 except Exception as e:
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
542 log.error(traceback.format_exc())
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
543 h.flash(_('An error occurred during unlocking'),
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
544 category='error')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
545 return redirect(url('edit_repo_advanced', repo_name=repo_name))
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2707
diff changeset
546
3629
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
547 @HasRepoPermissionAnyDecorator('repository.write', 'repository.admin')
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
548 def toggle_locking(self, repo_name):
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
549 """
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
550 Toggle locking of repository by simple GET call to url
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
551
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
552 :param repo_name:
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
553 """
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
554
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
555 try:
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
556 repo = Repository.get_by_repo_name(repo_name)
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
557
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
558 if repo.enable_locking:
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
559 if repo.locked[0]:
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
560 Repository.unlock(repo)
3654
ec6354949623 Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents: 3641
diff changeset
561 action = _('Unlocked')
3629
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
562 else:
4197
d208416c84c6 Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
563 Repository.lock(repo, c.authuser.user_id)
3654
ec6354949623 Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents: 3641
diff changeset
564 action = _('Locked')
3629
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
565
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
566 h.flash(_('Repository has been %s') % action,
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
567 category='success')
5374
d69aa464f373 cleanup: consistently use 'except ... as ...:'
Mads Kiilerich <madski@unity3d.com>
parents: 5307
diff changeset
568 except Exception as e:
3629
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
569 log.error(traceback.format_exc())
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
570 h.flash(_('An error occurred during unlocking'),
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
571 category='error')
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
572 return redirect(url('summary_home', repo_name=repo_name))
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
573
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
574 @HasRepoPermissionAllDecorator('repository.admin')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
575 def edit_caches(self, repo_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
576 """GET /repo_name/settings: Form to edit an existing item"""
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
577 # url('edit_repo', repo_name=ID)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
578 c.repo_info = self._load_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
579 c.active = 'caches'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
580 if request.POST:
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
581 try:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
582 ScmModel().mark_for_invalidation(repo_name, delete=True)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
583 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
584 h.flash(_('Cache invalidation successful'),
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
585 category='success')
5374
d69aa464f373 cleanup: consistently use 'except ... as ...:'
Mads Kiilerich <madski@unity3d.com>
parents: 5307
diff changeset
586 except Exception as e:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
587 log.error(traceback.format_exc())
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
588 h.flash(_('An error occurred during cache invalidation'),
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
589 category='error')
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
590
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
591 return redirect(url('edit_repo_caches', repo_name=c.repo_name))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
592 return render('admin/repos/repo_edit.html')
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1082
diff changeset
593
3629
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
594 @HasRepoPermissionAllDecorator('repository.admin')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
595 def edit_remote(self, repo_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
596 """GET /repo_name/settings: Form to edit an existing item"""
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
597 # url('edit_repo', repo_name=ID)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
598 c.repo_info = self._load_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
599 c.active = 'remote'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
600 if request.POST:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
601 try:
4197
d208416c84c6 Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
602 ScmModel().pull_changes(repo_name, self.authuser.username)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
603 h.flash(_('Pulled from remote location'), category='success')
5374
d69aa464f373 cleanup: consistently use 'except ... as ...:'
Mads Kiilerich <madski@unity3d.com>
parents: 5307
diff changeset
604 except Exception as e:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
605 log.error(traceback.format_exc())
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
606 h.flash(_('An error occurred during pull from remote location'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
607 category='error')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
608 return redirect(url('edit_repo_remote', repo_name=c.repo_name))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
609 return render('admin/repos/repo_edit.html')
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
610
3629
802c94bdfc85 #749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents: 3628
diff changeset
611 @HasRepoPermissionAllDecorator('repository.admin')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
612 def edit_statistics(self, repo_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
613 """GET /repo_name/settings: Form to edit an existing item"""
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
614 # url('edit_repo', repo_name=ID)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
615 c.repo_info = self._load_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
616 repo = c.repo_info.scm_instance
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
617
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
618 if c.repo_info.stats:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
619 # this is on what revision we ended up so we add +1 for count
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
620 last_rev = c.repo_info.stats.stat_on_revision + 1
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
621 else:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
622 last_rev = 0
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
623 c.stats_revision = last_rev
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
624
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
625 c.repo_last_rev = repo.count() if repo.revisions else 0
3308
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3288
diff changeset
626
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
627 if last_rev == 0 or c.repo_last_rev == 0:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
628 c.stats_percentage = 0
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
629 else:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
630 c.stats_percentage = '%.2f' % ((float((last_rev)) / c.repo_last_rev) * 100)
3308
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3288
diff changeset
631
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
632 c.active = 'statistics'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
633 if request.POST:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
634 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
635 RepoModel().delete_stats(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
636 Session().commit()
5374
d69aa464f373 cleanup: consistently use 'except ... as ...:'
Mads Kiilerich <madski@unity3d.com>
parents: 5307
diff changeset
637 except Exception as e:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
638 log.error(traceback.format_exc())
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
639 h.flash(_('An error occurred during deletion of repository stats'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
640 category='error')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
641 return redirect(url('edit_repo_statistics', repo_name=c.repo_name))
3308
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3288
diff changeset
642
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
643 return render('admin/repos/repo_edit.html')