annotate rhodecode/controllers/admin/repos.py @ 2819:dd240b2b7a12 beta tip

Added optional flag to make_ui to not clean sqlalchemy Session. Don't clear sqlalchemy session when using make_ui in admin repo form
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 15 Aug 2012 18:25:38 +0200
parents aa89767753a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
881
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
1 # -*- coding: utf-8 -*-
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
2 """
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
3 rhodecode.controllers.admin.repos
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1280
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1235
diff changeset
5
2070
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1954
diff changeset
6 Repositories controller for RhodeCode
1280
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1235
diff changeset
7
881
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
8 :created_on: Apr 7, 2010
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
9 :author: marcink
1909
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1903
diff changeset
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
881
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
11 :license: GPLv3, see COPYING for more details.
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
12 """
1283
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1280
diff changeset
13 # This program is free software: you can redistribute it and/or modify
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1280
diff changeset
14 # 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: 1280
diff changeset
15 # the Free Software Foundation, either version 3 of the License, or
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1280
diff changeset
16 # (at your option) any later version.
1280
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1235
diff changeset
17 #
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
18 # This program is distributed in the hope that it will be useful,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
21 # GNU General Public License for more details.
1280
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1235
diff changeset
22 #
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
23 # You should have received a copy of the GNU General Public License
1283
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1280
diff changeset
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
881
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
25
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
26 import logging
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
27 import traceback
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
28 import formencode
331
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 312
diff changeset
29 from formencode import htmlfill
881
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
30
2342
87e9718ab4a2 Use webob exception as often as possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2240
diff changeset
31 from webob.exc import HTTPInternalServerError
1807
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
32 from pylons import request, session, tmpl_context as c, url
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
33 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
34 from pylons.i18n.translation import _
1807
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
35 from sqlalchemy.exc import IntegrityError
881
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
36
2766
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
37 import rhodecode
596
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 585
diff changeset
38 from rhodecode.lib import helpers as h
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 585
diff changeset
39 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \
1913
7531c69ebdfc fixes issue when owner of a repo couldn't revoke permissions for users and groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1909
diff changeset
40 HasPermissionAnyDecorator, HasRepoPermissionAllDecorator
596
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 585
diff changeset
41 from rhodecode.lib.base import BaseController, render
1085
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1078
diff changeset
42 from rhodecode.lib.utils import invalidate_cache, action_logger, repo_name_slug
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
43 from rhodecode.lib.helpers import get_token
1807
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
44 from rhodecode.model.meta import Session
1717
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1678
diff changeset
45 from rhodecode.model.db import User, Repository, UserFollowing, RepoGroup
596
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 585
diff changeset
46 from rhodecode.model.forms import RepoForm
748
7486da5f0628 Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents: 720
diff changeset
47 from rhodecode.model.scm import ScmModel
684
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
48 from rhodecode.model.repo import RepoModel
2766
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
49 from rhodecode.lib.compat import json
881
ceb9f419b7fe some extra fixes added docs string
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
50
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
51 log = logging.getLogger(__name__)
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
52
1322
5f2fbab7c429 PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 1283
diff changeset
53
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
54 class ReposController(BaseController):
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
55 """
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
56 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
57 # 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
58 # file has a resource setup:
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
59 # map.resource('repo', 'repos')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
60
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 220
diff changeset
61 @LoginRequired()
453
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 432
diff changeset
62 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
63 def __before__(self):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
64 c.admin_user = session.get('admin_user')
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
65 c.admin_username = session.get('admin_username')
191
b68b2246e5a6 Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
66 super(ReposController, self).__before__()
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
67
1233
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1190
diff changeset
68 def __load_defaults(self):
1717
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1678
diff changeset
69 c.repo_groups = RepoGroup.groups_choices()
1630
fbc762ae3496 unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents: 1622
diff changeset
70 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
1807
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
71
1233
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1190
diff changeset
72 repo_model = RepoModel()
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1190
diff changeset
73 c.users_array = repo_model.get_users_js()
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1190
diff changeset
74 c.users_groups_array = repo_model.get_users_groups_js()
2562
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2561
diff changeset
75 choices, c.landing_revs = ScmModel().get_repo_landing_revs()
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2561
diff changeset
76 c.landing_revs_choices = choices
1233
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1190
diff changeset
77
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1190
diff changeset
78 def __load_data(self, repo_name=None):
1181
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
79 """
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
80 Load defaults settings for edit, and update
1280
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1235
diff changeset
81
1181
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
82 :param repo_name:
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
83 """
1233
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1190
diff changeset
84 self.__load_defaults()
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1190
diff changeset
85
1610
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1446
diff changeset
86 c.repo_info = db_repo = Repository.get_by_repo_name(repo_name)
1644
4d841e565237 added validation of params on settings table
Marcin Kuzminski <marcin@python-works.com>
parents: 1630
diff changeset
87 repo = db_repo.scm_instance
1181
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
88
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
89 if c.repo_info is None:
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
90 h.flash(_('%s repository is not mapped to db perhaps'
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
91 ' it was created or renamed from the filesystem'
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
92 ' please run the application again'
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
93 ' in order to rescan repositories') % repo_name,
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
94 category='error')
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
95
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
96 return redirect(url('repos'))
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
97
2562
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2561
diff changeset
98 choices, c.landing_revs = ScmModel().get_repo_landing_revs(c.repo_info)
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2561
diff changeset
99 c.landing_revs_choices = choices
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2561
diff changeset
100
1610
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1446
diff changeset
101 c.default_user_id = User.get_by_username('default').user_id
1678
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
102 c.in_public_journal = UserFollowing.query()\
1181
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
103 .filter(UserFollowing.user_id == c.default_user_id)\
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
104 .filter(UserFollowing.follows_repository == c.repo_info).scalar()
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
105
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
106 if c.repo_info.stats:
1892
1635a21485d6 - fixed issue with missing commits on some repos commands
Marcin Kuzminski <marcin@python-works.com>
parents: 1840
diff changeset
107 # this is on what revision we ended up so we add +1 for count
1635a21485d6 - fixed issue with missing commits on some repos commands
Marcin Kuzminski <marcin@python-works.com>
parents: 1840
diff changeset
108 last_rev = c.repo_info.stats.stat_on_revision + 1
1181
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
109 else:
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
110 last_rev = 0
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
111 c.stats_revision = last_rev
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
112
1892
1635a21485d6 - fixed issue with missing commits on some repos commands
Marcin Kuzminski <marcin@python-works.com>
parents: 1840
diff changeset
113 c.repo_last_rev = repo.count() if repo.revisions else 0
1181
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
114
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
115 if last_rev == 0 or c.repo_last_rev == 0:
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
116 c.stats_percentage = 0
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
117 else:
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
118 c.stats_percentage = '%.2f' % ((float((last_rev)) /
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
119 c.repo_last_rev) * 100)
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
120
1678
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
121 defaults = RepoModel()._get_defaults(repo_name)
1903
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1892
diff changeset
122
1840
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
123 c.repos_list = [('', _('--REMOVE FORK--'))]
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
124 c.repos_list += [(x.repo_id, x.repo_name) for x in
2731
d2901d906ef3 Fixed issue #501 error on setting set_as_fork to same repo
Marcin Kuzminski <marcin@python-works.com>
parents: 2705
diff changeset
125 Repository.query().order_by(Repository.repo_name).all()
d2901d906ef3 Fixed issue #501 error on setting set_as_fork to same repo
Marcin Kuzminski <marcin@python-works.com>
parents: 2705
diff changeset
126 if x.repo_id != c.repo_info.repo_id]
2561
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2477
diff changeset
127
2731
d2901d906ef3 Fixed issue #501 error on setting set_as_fork to same repo
Marcin Kuzminski <marcin@python-works.com>
parents: 2705
diff changeset
128 defaults['id_fork_of'] = db_repo.fork.repo_id if db_repo.fork else ''
1181
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
129 return defaults
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
130
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
131 @HasPermissionAllDecorator('hg.admin')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
132 def index(self, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
133 """GET /repos: All items in the collection"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
134 # url('repos')
1424
eef7a1b953e8 Admin view will see repos_groups in main list
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
135
2766
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
136 c.repos_list = Repository.query()\
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
137 .order_by(Repository.repo_name)\
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
138 .all()
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
139
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
140 repos_data = []
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
141 total_records = len(c.repos_list)
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
142
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
143 _tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
144 template = _tmpl_lookup.get_template('data_table/_dt_elements.html')
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
145
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
146 quick_menu = lambda repo_name: (template.get_def("quick_menu")
2776
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2766
diff changeset
147 .render(repo_name, _=_, h=h, c=c))
2766
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
148 repo_lnk = lambda name, rtype, private, fork_of: (
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
149 template.get_def("repo_name")
2776
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2766
diff changeset
150 .render(name, rtype, private, fork_of, short_name=False,
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2766
diff changeset
151 admin=True, _=_, h=h, c=c))
2766
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
152
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
153 repo_actions = lambda repo_name: (template.get_def("repo_actions")
2776
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2766
diff changeset
154 .render(repo_name, _=_, h=h, c=c))
2766
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
155
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
156 for repo in c.repos_list:
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
157 repos_data.append({
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
158 "menu": quick_menu(repo.repo_name),
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
159 "raw_name": repo.repo_name,
2776
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2766
diff changeset
160 "name": repo_lnk(repo.repo_name, repo.repo_type,
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2766
diff changeset
161 repo.private, repo.fork),
2766
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
162 "desc": repo.description,
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
163 "owner": repo.user.username,
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
164 "action": repo_actions(repo.repo_name),
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
165 })
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
166
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
167 c.data = json.dumps({
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
168 "totalRecords": total_records,
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
169 "startIndex": 0,
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
170 "sort": "name",
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
171 "dir": "asc",
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
172 "records": repos_data
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
173 })
c525d7e641a6 rewrote admin repos page.
Marcin Kuzminski <marcin@python-works.com>
parents: 2764
diff changeset
174
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
175 return render('admin/repos/repos.html')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
176
453
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 432
diff changeset
177 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
178 def create(self):
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
179 """
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
180 POST /repos: Create a new item"""
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
181 # url('repos')
1807
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
182
1233
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1190
diff changeset
183 self.__load_defaults()
383
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 382
diff changeset
184 form_result = {}
215
70f645fa97cc Moved repo creation to admin/repos, as part of crud controller. Now repo creation is based on a form, which can be auto filled with data from 404 page. Fixed the error controller to properly give the repo name.
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
185 try:
2562
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2561
diff changeset
186 form_result = RepoForm(repo_groups=c.repo_groups_choices,
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2561
diff changeset
187 landing_revs=c.landing_revs_choices)()\
1233
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1190
diff changeset
188 .to_python(dict(request.POST))
2762
98532710ad14 redirect to summary page after repo was created
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
189 new_repo = RepoModel().create(form_result,
98532710ad14 redirect to summary page after repo was created
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
190 self.rhodecode_user.user_id)
1181
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
191 if form_result['clone_uri']:
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
192 h.flash(_('created repository %s from %s') \
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
193 % (form_result['repo_name'], form_result['clone_uri']),
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
194 category='success')
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
195 else:
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
196 h.flash(_('created repository %s') % form_result['repo_name'],
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
197 category='success')
585
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 453
diff changeset
198
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 453
diff changeset
199 if request.POST.get('user_created'):
1807
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
200 # created by regular non admin user
612
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
201 action_logger(self.rhodecode_user, 'user_created_repo',
2477
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2240
diff changeset
202 form_result['repo_name_full'], self.ip_addr,
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2240
diff changeset
203 self.sa)
585
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 453
diff changeset
204 else:
612
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
205 action_logger(self.rhodecode_user, 'admin_created_repo',
2477
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2240
diff changeset
206 form_result['repo_name_full'], self.ip_addr,
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2240
diff changeset
207 self.sa)
2764
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
208 Session().commit()
612
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
209 except formencode.Invalid, errors:
1181
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
210
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
211 c.new_repo = errors.value['repo_name']
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
212
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
213 if request.POST.get('user_created'):
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
214 r = render('admin/repos/repo_add_create_repository.html')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
215 else:
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
216 r = render('admin/repos/repo_add.html')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
217
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
218 return htmlfill.render(
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
219 r,
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
220 defaults=errors.value,
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
221 errors=errors.error_dict or {},
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
222 prefix_error=False,
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
223 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
224
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
225 except Exception:
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
226 log.error(traceback.format_exc())
919
5f7731e3ab4d fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents: 889
diff changeset
227 msg = _('error occurred during creation of repository %s') \
383
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 382
diff changeset
228 % form_result.get('repo_name')
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
229 h.flash(msg, category='error')
2809
aa89767753a9 fix redirection on repo create failures
Marcin Kuzminski <marcin@python-works.com>
parents: 2776
diff changeset
230 return redirect(url('repos'))
2762
98532710ad14 redirect to summary page after repo was created
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
231 #redirect to our new repo !
98532710ad14 redirect to summary page after repo was created
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
232 return redirect(url('summary_home', repo_name=new_repo.repo_name))
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
233
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
234 @HasPermissionAllDecorator('hg.admin')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
235 def new(self, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
236 """GET /repos/new: Form to create a new item"""
215
70f645fa97cc Moved repo creation to admin/repos, as part of crud controller. Now repo creation is based on a form, which can be auto filled with data from 404 page. Fixed the error controller to properly give the repo name.
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
237 new_repo = request.GET.get('repo', '')
1085
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1078
diff changeset
238 c.new_repo = repo_name_slug(new_repo)
1233
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1190
diff changeset
239 self.__load_defaults()
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
240 return render('admin/repos/repo_add.html')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
241
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
242 @HasPermissionAllDecorator('hg.admin')
312
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
243 def update(self, repo_name):
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
244 """
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
245 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
246 # 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
247 # <input type="hidden" name="_method" value="PUT" />
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
248 # Or using helpers:
312
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
249 # h.form(url('repo', repo_name=ID),
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
250 # method='put')
312
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
251 # url('repo', repo_name=ID)
1233
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1190
diff changeset
252 self.__load_defaults()
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
253 repo_model = RepoModel()
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
254 changed_name = repo_name
2705
370ed7829168 Readme renderer now uses landing_rev parameter to render the readme based on
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
255 #override the choices with extracted revisions !
370ed7829168 Readme renderer now uses landing_rev parameter to render the readme based on
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
256 choices, c.landing_revs = ScmModel().get_repo_landing_revs(repo_name)
370ed7829168 Readme renderer now uses landing_rev parameter to render the readme based on
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
257 c.landing_revs_choices = choices
370ed7829168 Readme renderer now uses landing_rev parameter to render the readme based on
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
258
1322
5f2fbab7c429 PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 1283
diff changeset
259 _form = RepoForm(edit=True, old_data={'repo_name': repo_name},
2562
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2561
diff changeset
260 repo_groups=c.repo_groups_choices,
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2561
diff changeset
261 landing_revs=c.landing_revs_choices)()
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
262 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
263 form_result = _form.to_python(dict(request.POST))
1622
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1610
diff changeset
264 repo = repo_model.update(repo_name, form_result)
720
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 715
diff changeset
265 invalidate_cache('get_repo_cached_%s' % repo_name)
2672
94ae02ca5f00 i18n improve
Takumi IINO <trot.thunder@gmail.com>
parents: 2626
diff changeset
266 h.flash(_('Repository %s updated successfully') % repo_name,
331
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 312
diff changeset
267 category='success')
1622
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1610
diff changeset
268 changed_name = repo.repo_name
715
df61378032f3 #48 rewrote action logger, translated action logger messages, added some extra messages. Linked and showed pushed revisions in logs
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
269 action_logger(self.rhodecode_user, 'admin_updated_repo',
2477
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2240
diff changeset
270 changed_name, self.ip_addr, self.sa)
2764
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
271 Session().commit()
612
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
272 except formencode.Invalid, errors:
1181
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
273 defaults = self.__load_data(repo_name)
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
274 defaults.update(errors.value)
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
275 return htmlfill.render(
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
276 render('admin/repos/repo_edit.html'),
1181
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
277 defaults=defaults,
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
278 errors=errors.error_dict or {},
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
279 prefix_error=False,
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
280 encoding="UTF-8")
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
281
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
282 except Exception:
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
283 log.error(traceback.format_exc())
749
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 748
diff changeset
284 h.flash(_('error occurred during update of repository %s') \
382
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
285 % repo_name, category='error')
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 339
diff changeset
286 return redirect(url('edit_repo', repo_name=changed_name))
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
287
412
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 408
diff changeset
288 @HasPermissionAllDecorator('hg.admin')
312
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
289 def delete(self, repo_name):
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
290 """
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
291 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
292 # 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
293 # <input type="hidden" name="_method" value="DELETE" />
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
294 # Or using helpers:
312
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
295 # h.form(url('repo', repo_name=ID),
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
296 # method='delete')
312
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
297 # url('repo', repo_name=ID)
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
298
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
299 repo_model = RepoModel()
792
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 768
diff changeset
300 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
301 if not repo:
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
302 h.flash(_('%s repository is not mapped to db perhaps'
266
32d6c955218c added check for repo created outside of hg app
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
303 ' it was moved or renamed from the filesystem'
32d6c955218c added check for repo created outside of hg app
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
304 ' please run the application again'
331
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 312
diff changeset
305 ' in order to rescan repositories') % repo_name,
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 312
diff changeset
306 category='error')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
307
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
308 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
309 try:
612
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
310 action_logger(self.rhodecode_user, 'admin_deleted_repo',
2477
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2240
diff changeset
311 repo_name, self.ip_addr, self.sa)
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
312 repo_model.delete(repo)
720
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 715
diff changeset
313 invalidate_cache('get_repo_cached_%s' % repo_name)
312
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
314 h.flash(_('deleted repository %s') % repo_name, category='success')
2764
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
315 Session().commit()
1441
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1425
diff changeset
316 except IntegrityError, e:
1837
f28dc032adf0 Added handling of ignore whitespace flag in changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 1834
diff changeset
317 if e.message.find('repositories_fork_id_fkey') != -1:
1441
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1425
diff changeset
318 log.error(traceback.format_exc())
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1425
diff changeset
319 h.flash(_('Cannot delete %s it still contains attached '
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1425
diff changeset
320 'forks') % repo_name,
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1425
diff changeset
321 category='warning')
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1425
diff changeset
322 else:
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1425
diff changeset
323 log.error(traceback.format_exc())
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1425
diff changeset
324 h.flash(_('An error occurred during '
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1425
diff changeset
325 'deletion of %s') % repo_name,
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1425
diff changeset
326 category='error')
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1425
diff changeset
327
585
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 453
diff changeset
328 except Exception, e:
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 453
diff changeset
329 log.error(traceback.format_exc())
919
5f7731e3ab4d fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents: 889
diff changeset
330 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
331 category='error')
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
332
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
333 return redirect(url('repos'))
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
334
1954
682057a38cd3 white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1913
diff changeset
335 @HasRepoPermissionAllDecorator('repository.admin')
312
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
336 def delete_perm_user(self, repo_name):
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
337 """
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
338 DELETE an existing repository permission user
1280
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1235
diff changeset
339
657
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 612
diff changeset
340 :param repo_name:
312
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
341 """
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
342 try:
2070
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1954
diff changeset
343 RepoModel().revoke_user_permission(repo=repo_name,
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1954
diff changeset
344 user=request.POST['user_id'])
2764
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
345 Session().commit()
2070
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1954
diff changeset
346 except Exception:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1954
diff changeset
347 log.error(traceback.format_exc())
919
5f7731e3ab4d fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents: 889
diff changeset
348 h.flash(_('An error occurred during deletion of repository user'),
312
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
349 category='error')
391
ec7b76d4bda4 Added initial query skipp when seting up the app.
Marcin Kuzminski <marcin@python-works.com>
parents: 383
diff changeset
350 raise HTTPInternalServerError()
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
351
1913
7531c69ebdfc fixes issue when owner of a repo couldn't revoke permissions for users and groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1909
diff changeset
352 @HasRepoPermissionAllDecorator('repository.admin')
1078
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
353 def delete_perm_users_group(self, repo_name):
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
354 """
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
355 DELETE an existing repository permission users group
1280
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1235
diff changeset
356
1078
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
357 :param repo_name:
765
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
358 """
2070
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1954
diff changeset
359
1078
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
360 try:
2070
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1954
diff changeset
361 RepoModel().revoke_users_group_permission(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1954
diff changeset
362 repo=repo_name, group_name=request.POST['users_group_id']
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1954
diff changeset
363 )
2764
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
364 Session().commit()
2070
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1954
diff changeset
365 except Exception:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1954
diff changeset
366 log.error(traceback.format_exc())
1078
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
367 h.flash(_('An error occurred during deletion of repository'
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
368 ' users groups'),
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
369 category='error')
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
370 raise HTTPInternalServerError()
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
371
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
372 @HasPermissionAllDecorator('hg.admin')
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
373 def repo_stats(self, repo_name):
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
374 """
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
375 DELETE an existing repository statistics
1280
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1235
diff changeset
376
765
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
377 :param repo_name:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
378 """
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
379
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
380 try:
2070
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1954
diff changeset
381 RepoModel().delete_stats(repo_name)
2764
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
382 Session().commit()
765
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
383 except Exception, e:
919
5f7731e3ab4d fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents: 889
diff changeset
384 h.flash(_('An error occurred during deletion of repository stats'),
765
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
385 category='error')
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
386 return redirect(url('edit_repo', repo_name=repo_name))
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
387
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
388 @HasPermissionAllDecorator('hg.admin')
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
389 def repo_cache(self, repo_name):
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
390 """
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
391 INVALIDATE existing repository cache
1280
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1235
diff changeset
392
765
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
393 :param repo_name:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
394 """
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
395
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
396 try:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
397 ScmModel().mark_for_invalidation(repo_name)
2764
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
398 Session().commit()
765
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
399 except Exception, e:
768
cda88b3eb09c fixed error for empty revisions on admin repo edit
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
400 h.flash(_('An error occurred during cache invalidation'),
765
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
401 category='error')
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
402 return redirect(url('edit_repo', repo_name=repo_name))
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
403
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 749
diff changeset
404 @HasPermissionAllDecorator('hg.admin')
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
405 def repo_public_journal(self, repo_name):
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
406 """
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
407 Set's this repository to be visible in public journal,
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
408 in other words assing default user to follow this repo
1280
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1235
diff changeset
409
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
410 :param repo_name:
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
411 """
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
412
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
413 cur_token = request.POST.get('auth_token')
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
414 token = get_token()
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
415 if cur_token == token:
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
416 try:
1610
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1446
diff changeset
417 repo_id = Repository.get_by_repo_name(repo_name).repo_id
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1446
diff changeset
418 user_id = User.get_by_username('default').user_id
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
419 self.scm_model.toggle_following_repo(repo_id, user_id)
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
420 h.flash(_('Updated repository visibility in public journal'),
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
421 category='success')
2764
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
422 Session().commit()
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
423 except:
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
424 h.flash(_('An error occurred during setting this'
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
425 ' repository in public journal'),
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
426 category='error')
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
427
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
428 else:
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
429 h.flash(_('Token mismatch'), category='error')
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
430 return redirect(url('edit_repo', repo_name=repo_name))
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
431
1183
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1181
diff changeset
432 @HasPermissionAllDecorator('hg.admin')
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1181
diff changeset
433 def repo_pull(self, repo_name):
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1181
diff changeset
434 """
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1181
diff changeset
435 Runs task to update given repository with remote changes,
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1181
diff changeset
436 ie. make pull on remote location
1280
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1235
diff changeset
437
1183
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1181
diff changeset
438 :param repo_name:
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1181
diff changeset
439 """
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1181
diff changeset
440 try:
1190
f3f847712f87 replaced all global calls to template context (rhodecode_user), into instance attributes
Marcin Kuzminski <marcin@python-works.com>
parents: 1183
diff changeset
441 ScmModel().pull_changes(repo_name, self.rhodecode_user.username)
1183
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1181
diff changeset
442 h.flash(_('Pulled from remote location'), category='success')
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1181
diff changeset
443 except Exception, e:
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1181
diff changeset
444 h.flash(_('An error occurred during pull from remote location'),
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1181
diff changeset
445 category='error')
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
446
1183
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1181
diff changeset
447 return redirect(url('edit_repo', repo_name=repo_name))
1154
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
448
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1151
diff changeset
449 @HasPermissionAllDecorator('hg.admin')
1840
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
450 def repo_as_fork(self, repo_name):
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
451 """
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
452 Mark given repository as a fork of another
1903
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1892
diff changeset
453
1840
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
454 :param repo_name:
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
455 """
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
456 try:
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
457 fork_id = request.POST.get('id_fork_of')
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
458 repo = ScmModel().mark_as_fork(repo_name, fork_id,
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
459 self.rhodecode_user.username)
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
460 fork = repo.fork.repo_name if repo.fork else _('Nothing')
2731
d2901d906ef3 Fixed issue #501 error on setting set_as_fork to same repo
Marcin Kuzminski <marcin@python-works.com>
parents: 2705
diff changeset
461 Session().commit()
d2901d906ef3 Fixed issue #501 error on setting set_as_fork to same repo
Marcin Kuzminski <marcin@python-works.com>
parents: 2705
diff changeset
462 h.flash(_('Marked repo %s as fork of %s') % (repo_name, fork),
1840
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
463 category='success')
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
464 except Exception, e:
2731
d2901d906ef3 Fixed issue #501 error on setting set_as_fork to same repo
Marcin Kuzminski <marcin@python-works.com>
parents: 2705
diff changeset
465 log.error(traceback.format_exc())
1840
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
466 h.flash(_('An error occurred during this operation'),
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
467 category='error')
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
468
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
469 return redirect(url('edit_repo', repo_name=repo_name))
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
470
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1837
diff changeset
471 @HasPermissionAllDecorator('hg.admin')
312
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
472 def show(self, repo_name, format='html'):
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
473 """GET /repos/repo_name: Show a specific item"""
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
474 # url('repo', repo_name=ID)
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
475
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
476 @HasPermissionAllDecorator('hg.admin')
312
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
477 def edit(self, repo_name, format='html'):
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
478 """GET /repos/repo_name/edit: Form to edit an existing item"""
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 311
diff changeset
479 # url('edit_repo', repo_name=ID)
1181
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
480 defaults = self.__load_data(repo_name)
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
481
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
482 return htmlfill.render(
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
483 render('admin/repos/repo_edit.html'),
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
484 defaults=defaults,
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
485 encoding="UTF-8",
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
486 force_defaults=False
691
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 684
diff changeset
487 )