##// END OF EJS Templates
Implemented #379 defaults settings page for creation of repositories...
marcink -
r3056:6104dfd3 beta
parent child Browse files
Show More
@@ -0,0 +1,130 b''
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.controllers.admin.defaults
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 default settings controller for Rhodecode
7
8 :created_on: Apr 27, 2010
9 :author: marcink
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25
26 import logging
27 import traceback
28 import formencode
29 from formencode import htmlfill
30
31 from pylons import request, session, tmpl_context as c, url
32 from pylons.controllers.util import abort, redirect
33 from pylons.i18n.translation import _
34
35 from rhodecode.lib import helpers as h
36 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
37 from rhodecode.lib.base import BaseController, render
38 from rhodecode.model.forms import DefaultsForm
39 from rhodecode.model.meta import Session
40 from rhodecode import BACKENDS
41 from rhodecode.model.db import RhodeCodeSetting
42
43 log = logging.getLogger(__name__)
44
45
46 class DefaultsController(BaseController):
47 """REST Controller styled on the Atom Publishing Protocol"""
48 # To properly map this controller, ensure your config/routing.py
49 # file has a resource setup:
50 # map.resource('default', 'defaults')
51
52 @LoginRequired()
53 @HasPermissionAllDecorator('hg.admin')
54 def __before__(self):
55 super(DefaultsController, self).__before__()
56
57 def index(self, format='html'):
58 """GET /defaults: All items in the collection"""
59 # url('defaults')
60 c.backends = BACKENDS.keys()
61 defaults = RhodeCodeSetting.get_default_repo_settings()
62
63 return htmlfill.render(
64 render('admin/defaults/defaults.html'),
65 defaults=defaults,
66 encoding="UTF-8",
67 force_defaults=False
68 )
69
70 def create(self):
71 """POST /defaults: Create a new item"""
72 # url('defaults')
73
74 def new(self, format='html'):
75 """GET /defaults/new: Form to create a new item"""
76 # url('new_default')
77
78 def update(self, id):
79 """PUT /defaults/id: Update an existing item"""
80 # Forms posted to this method should contain a hidden field:
81 # <input type="hidden" name="_method" value="PUT" />
82 # Or using helpers:
83 # h.form(url('default', id=ID),
84 # method='put')
85 # url('default', id=ID)
86
87 _form = DefaultsForm()()
88
89 try:
90 form_result = _form.to_python(dict(request.POST))
91 for k, v in form_result.iteritems():
92 setting = RhodeCodeSetting.get_by_name_or_create(k)
93 setting.app_settings_value = v
94 Session().add(setting)
95 Session().commit()
96 h.flash(_('Default settings updated successfully'),
97 category='success')
98
99 except formencode.Invalid, errors:
100 defaults = errors.value
101
102 return htmlfill.render(
103 render('admin/defaults/defaults.html'),
104 defaults=defaults,
105 errors=errors.error_dict or {},
106 prefix_error=False,
107 encoding="UTF-8")
108 except Exception:
109 log.error(traceback.format_exc())
110 h.flash(_('error occurred during update of defaults'),
111 category='error')
112
113 return redirect(url('defaults'))
114
115 def delete(self, id):
116 """DELETE /defaults/id: Delete an existing item"""
117 # Forms posted to this method should contain a hidden field:
118 # <input type="hidden" name="_method" value="DELETE" />
119 # Or using helpers:
120 # h.form(url('default', id=ID),
121 # method='delete')
122 # url('default', id=ID)
123
124 def show(self, id, format='html'):
125 """GET /defaults/id: Show a specific item"""
126 # url('default', id=ID)
127
128 def edit(self, id, format='html'):
129 """GET /defaults/id/edit: Form to edit an existing item"""
130 # url('edit_default', id=ID)
@@ -0,0 +1,93 b''
1 ## -*- coding: utf-8 -*-
2 <%inherit file="/base/base.html"/>
3
4 <%def name="title()">
5 ${_('Repositories defaults')} - ${c.rhodecode_name}
6 </%def>
7
8 <%def name="breadcrumbs_links()">
9 ${h.link_to(_('Admin'),h.url('admin_home'))}
10 &raquo;
11 ${_('Defaults')}
12 </%def>
13
14 <%def name="page_nav()">
15 ${self.menu('admin')}
16 </%def>
17
18 <%def name="main()">
19 <div class="box">
20 <!-- box / title -->
21 <div class="title">
22 ${self.breadcrumbs()}
23 </div>
24
25 <h3>${_('Repositories defaults')}</h3>
26
27 ${h.form(url('default', id='defaults'),method='put')}
28 <div class="form">
29 <!-- fields -->
30
31 <div class="fields">
32
33 <div class="field">
34 <div class="label">
35 <label for="default_repo_type">${_('Type')}:</label>
36 </div>
37 <div class="input">
38 ${h.select('default_repo_type','hg',c.backends,class_="medium")}
39 </div>
40 </div>
41
42 <div class="field">
43 <div class="label label-checkbox">
44 <label for="default_repo_private">${_('Private repository')}:</label>
45 </div>
46 <div class="checkboxes">
47 ${h.checkbox('default_repo_private',value="True")}
48 <span class="help-block">${_('Private repositories are only visible to people explicitly added as collaborators.')}</span>
49 </div>
50 </div>
51
52
53 <div class="field">
54 <div class="label label-checkbox">
55 <label for="default_repo_enable_statistics">${_('Enable statistics')}:</label>
56 </div>
57 <div class="checkboxes">
58 ${h.checkbox('default_repo_enable_statistics',value="True")}
59 <span class="help-block">${_('Enable statistics window on summary page.')}</span>
60 </div>
61 </div>
62
63 <div class="field">
64 <div class="label label-checkbox">
65 <label for="default_repo_enable_downloads">${_('Enable downloads')}:</label>
66 </div>
67 <div class="checkboxes">
68 ${h.checkbox('default_repo_enable_downloads',value="True")}
69 <span class="help-block">${_('Enable download menu on summary page.')}</span>
70 </div>
71 </div>
72
73 <div class="field">
74 <div class="label label-checkbox">
75 <label for="default_repo_enable_locking">${_('Enable locking')}:</label>
76 </div>
77 <div class="checkboxes">
78 ${h.checkbox('default_repo_enable_locking',value="True")}
79 <span class="help-block">${_('Enable lock-by-pulling on repository.')}</span>
80 </div>
81 </div>
82
83 <div class="buttons">
84 ${h.submit('save',_('Save'),class_="ui-btn large")}
85 </div>
86 </div>
87 </div>
88 ${h.end_form()}
89
90 ##<h3>${_('Groups defaults')}</h3>
91
92 </div>
93 </%def>
@@ -0,0 +1,72 b''
1 from rhodecode.tests import *
2 from rhodecode.model.db import RhodeCodeSetting
3
4
5 class TestDefaultsController(TestController):
6
7 def test_index(self):
8 self.log_user()
9 response = self.app.get(url('defaults'))
10 response.mustcontain('default_repo_private')
11 response.mustcontain('default_repo_enable_statistics')
12 response.mustcontain('default_repo_enable_downloads')
13 response.mustcontain('default_repo_enable_locking')
14
15 def test_index_as_xml(self):
16 response = self.app.get(url('formatted_defaults', format='xml'))
17
18 def test_create(self):
19 response = self.app.post(url('defaults'))
20
21 def test_new(self):
22 response = self.app.get(url('new_default'))
23
24 def test_new_as_xml(self):
25 response = self.app.get(url('formatted_new_default', format='xml'))
26
27 def test_update(self):
28 self.log_user()
29 params = {
30 'default_repo_enable_locking': True,
31 'default_repo_enable_downloads': True,
32 'default_repo_enable_statistics': True,
33 'default_repo_private': True,
34 'default_repo_type': 'hg',
35 }
36 response = self.app.put(url('default', id='default'), params=params)
37 self.checkSessionFlash(response, 'Default settings updated successfully')
38 defs = RhodeCodeSetting.get_default_repo_settings()
39 self.assertEqual(params, defs)
40
41 params = {
42 'default_repo_enable_locking': False,
43 'default_repo_enable_downloads': False,
44 'default_repo_enable_statistics': False,
45 'default_repo_private': False,
46 'default_repo_type': 'git',
47 }
48 response = self.app.put(url('default', id='default'), params=params)
49 self.checkSessionFlash(response, 'Default settings updated successfully')
50 defs = RhodeCodeSetting.get_default_repo_settings()
51 self.assertEqual(params, defs)
52
53 def test_update_browser_fakeout(self):
54 response = self.app.post(url('default', id=1), params=dict(_method='put'))
55
56 def test_delete(self):
57 response = self.app.delete(url('default', id=1))
58
59 def test_delete_browser_fakeout(self):
60 response = self.app.post(url('default', id=1), params=dict(_method='delete'))
61
62 def test_show(self):
63 response = self.app.get(url('default', id=1))
64
65 def test_show_as_xml(self):
66 response = self.app.get(url('formatted_default', id=1, format='xml'))
67
68 def test_edit(self):
69 response = self.app.get(url('edit_default', id=1))
70
71 def test_edit_as_xml(self):
72 response = self.app.get(url('formatted_edit_default', id=1, format='xml'))
@@ -262,6 +262,10 b' def make_map(config):'
262 rmap.resource('permission', 'permissions',
262 rmap.resource('permission', 'permissions',
263 controller='admin/permissions', path_prefix=ADMIN_PREFIX)
263 controller='admin/permissions', path_prefix=ADMIN_PREFIX)
264
264
265 #ADMIN DEFAULTS REST ROUTES
266 rmap.resource('default', 'defaults',
267 controller='admin/defaults', path_prefix=ADMIN_PREFIX)
268
265 ##ADMIN LDAP SETTINGS
269 ##ADMIN LDAP SETTINGS
266 rmap.connect('ldap_settings', '%s/ldap' % ADMIN_PREFIX,
270 rmap.connect('ldap_settings', '%s/ldap' % ADMIN_PREFIX,
267 controller='admin/ldap_settings', action='ldap_settings',
271 controller='admin/ldap_settings', action='ldap_settings',
@@ -42,7 +42,8 b' from rhodecode.lib.base import BaseContr'
42 from rhodecode.lib.utils import invalidate_cache, action_logger, repo_name_slug
42 from rhodecode.lib.utils import invalidate_cache, action_logger, repo_name_slug
43 from rhodecode.lib.helpers import get_token
43 from rhodecode.lib.helpers import get_token
44 from rhodecode.model.meta import Session
44 from rhodecode.model.meta import Session
45 from rhodecode.model.db import User, Repository, UserFollowing, RepoGroup
45 from rhodecode.model.db import User, Repository, UserFollowing, RepoGroup,\
46 RhodeCodeSetting
46 from rhodecode.model.forms import RepoForm
47 from rhodecode.model.forms import RepoForm
47 from rhodecode.model.scm import ScmModel
48 from rhodecode.model.scm import ScmModel
48 from rhodecode.model.repo import RepoModel
49 from rhodecode.model.repo import RepoModel
@@ -481,7 +481,15 b' class SettingsController(BaseController)'
481 new_repo = request.GET.get('repo', '')
481 new_repo = request.GET.get('repo', '')
482 c.new_repo = repo_name_slug(new_repo)
482 c.new_repo = repo_name_slug(new_repo)
483
483
484 return render('admin/repos/repo_add_create_repository.html')
484 ## apply the defaults from defaults page
485 defaults = RhodeCodeSetting.get_default_repo_settings(strip_prefix=True)
486 return htmlfill.render(
487 render('admin/repos/repo_add_create_repository.html'),
488 defaults=defaults,
489 errors={},
490 prefix_error=False,
491 encoding="UTF-8"
492 )
485
493
486 def _get_hg_ui_settings(self):
494 def _get_hg_ui_settings(self):
487 ret = RhodeCodeUi.query().all()
495 ret = RhodeCodeUi.query().all()
@@ -273,6 +273,7 b' class DbManage(object):'
273
273
274 def step_8(self):
274 def step_8(self):
275 self.klass.populate_default_permissions()
275 self.klass.populate_default_permissions()
276 self.klass.create_default_options(skip_existing=True)
276 Session().commit()
277 Session().commit()
277
278
278 upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
279 upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
@@ -482,6 +483,22 b' class DbManage(object):'
482 setting = RhodeCodeSetting(k, v)
483 setting = RhodeCodeSetting(k, v)
483 self.sa.add(setting)
484 self.sa.add(setting)
484
485
486 def create_default_options(self, skip_existing=False):
487 """Creates default settings"""
488
489 for k, v in [
490 ('default_repo_enable_locking', False),
491 ('default_repo_enable_downloads', False),
492 ('default_repo_enable_statistics', False),
493 ('default_repo_private', False),
494 ('default_repo_type', 'hg')]:
495
496 if skip_existing and RhodeCodeSetting.get_by_name(k) != None:
497 log.debug('Skipping option %s' % k)
498 continue
499 setting = RhodeCodeSetting(k, v)
500 self.sa.add(setting)
501
485 def fixup_groups(self):
502 def fixup_groups(self):
486 def_usr = User.get_by_username('default')
503 def_usr = User.get_by_username('default')
487 for g in RepoGroup.query().all():
504 for g in RepoGroup.query().all():
@@ -622,6 +639,7 b' class DbManage(object):'
622 self.sa.add(sett6)
639 self.sa.add(sett6)
623
640
624 self.create_ldap_options()
641 self.create_ldap_options()
642 self.create_default_options()
625
643
626 log.info('created ui config')
644 log.info('created ui config')
627
645
@@ -23,6 +23,7 b' def upgrade(migrate_engine):'
23 """
23 """
24 pass
24 pass
25
25
26
26 def downgrade(migrate_engine):
27 def downgrade(migrate_engine):
27 meta = MetaData()
28 meta = MetaData()
28 meta.bind = migrate_engine
29 meta.bind = migrate_engine
@@ -287,7 +287,7 b' def remove_suffix(s, suffix):'
287
287
288 def remove_prefix(s, prefix):
288 def remove_prefix(s, prefix):
289 if s.startswith(prefix):
289 if s.startswith(prefix):
290 s = s[:-1 * len(prefix)]
290 s = s[len(prefix):]
291 return s
291 return s
292
292
293
293
@@ -46,7 +46,7 b' from rhodecode.lib.vcs.exceptions import'
46 from rhodecode.lib.vcs.utils.lazy import LazyProperty
46 from rhodecode.lib.vcs.utils.lazy import LazyProperty
47
47
48 from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \
48 from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \
49 safe_unicode, remove_suffix
49 safe_unicode, remove_suffix, remove_prefix
50 from rhodecode.lib.compat import json
50 from rhodecode.lib.compat import json
51 from rhodecode.lib.caching_query import FromCache
51 from rhodecode.lib.caching_query import FromCache
52
52
@@ -167,7 +167,11 b' class RhodeCodeSetting(Base, BaseModel):'
167 @hybrid_property
167 @hybrid_property
168 def app_settings_value(self):
168 def app_settings_value(self):
169 v = self._app_settings_value
169 v = self._app_settings_value
170 if self.app_settings_name == 'ldap_active':
170 if self.app_settings_name in ["ldap_active",
171 "default_repo_enable_statistics",
172 "default_repo_enable_locking",
173 "default_repo_private",
174 "default_repo_enable_downloads"]:
171 v = str2bool(v)
175 v = str2bool(v)
172 return v
176 return v
173
177
@@ -225,6 +229,19 b' class RhodeCodeSetting(Base, BaseModel):'
225
229
226 return fd
230 return fd
227
231
232 @classmethod
233 def get_default_repo_settings(cls, cache=False, strip_prefix=False):
234 ret = cls.query()\
235 .filter(cls.app_settings_name.startswith('default_')).all()
236 fd = {}
237 for row in ret:
238 key = row.app_settings_name
239 if strip_prefix:
240 key = remove_prefix(key, prefix='default_')
241 fd.update({key: row.app_settings_value})
242
243 return fd
244
228
245
229 class RhodeCodeUi(Base, BaseModel):
246 class RhodeCodeUi(Base, BaseModel):
230 __tablename__ = 'rhodecode_ui'
247 __tablename__ = 'rhodecode_ui'
@@ -173,19 +173,19 b' def RepoForm(edit=False, old_data={}, su'
173 repo_groups=[], landing_revs=[]):
173 repo_groups=[], landing_revs=[]):
174 class _RepoForm(formencode.Schema):
174 class _RepoForm(formencode.Schema):
175 allow_extra_fields = True
175 allow_extra_fields = True
176 filter_extra_fields = False
176 filter_extra_fields = True
177 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
177 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
178 v.SlugifyName())
178 v.SlugifyName())
179 clone_uri = All(v.UnicodeString(strip=True, min=1, not_empty=False))
180 repo_group = All(v.CanWriteGroup(),
179 repo_group = All(v.CanWriteGroup(),
181 v.OneOf(repo_groups, hideList=True))
180 v.OneOf(repo_groups, hideList=True))
182 repo_type = v.OneOf(supported_backends)
181 repo_type = v.OneOf(supported_backends)
183 description = v.UnicodeString(strip=True, min=1, not_empty=False)
182 repo_description = v.UnicodeString(strip=True, min=1, not_empty=False)
184 private = v.StringBoolean(if_missing=False)
183 repo_private = v.StringBoolean(if_missing=False)
185 enable_statistics = v.StringBoolean(if_missing=False)
184 repo_enable_statistics = v.StringBoolean(if_missing=False)
186 enable_downloads = v.StringBoolean(if_missing=False)
185 repo_enable_downloads = v.StringBoolean(if_missing=False)
187 enable_locking = v.StringBoolean(if_missing=False)
186 repo_enable_locking = v.StringBoolean(if_missing=False)
188 landing_rev = v.OneOf(landing_revs, hideList=True)
187 repo_landing_rev = v.OneOf(landing_revs, hideList=True)
188 clone_uri = All(v.UnicodeString(strip=True, min=1, not_empty=False))
189
189
190 if edit:
190 if edit:
191 #this is repo owner
191 #this is repo owner
@@ -218,9 +218,8 b' def RepoForkForm(edit=False, old_data={}'
218 return _RepoForkForm
218 return _RepoForkForm
219
219
220
220
221 def RepoSettingsForm(edit=False, old_data={},
221 def RepoSettingsForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
222 supported_backends=BACKENDS.keys(), repo_groups=[],
222 repo_groups=[], landing_revs=[]):
223 landing_revs=[]):
224 class _RepoForm(formencode.Schema):
223 class _RepoForm(formencode.Schema):
225 allow_extra_fields = True
224 allow_extra_fields = True
226 filter_extra_fields = False
225 filter_extra_fields = False
@@ -282,8 +281,8 b' def ApplicationUiSettingsForm():'
282 return _ApplicationUiSettingsForm
281 return _ApplicationUiSettingsForm
283
282
284
283
285 def DefaultPermissionsForm(repo_perms_choices, group_perms_choices, register_choices, create_choices,
284 def DefaultPermissionsForm(repo_perms_choices, group_perms_choices,
286 fork_choices):
285 register_choices, create_choices, fork_choices):
287 class _DefaultPermissionsForm(formencode.Schema):
286 class _DefaultPermissionsForm(formencode.Schema):
288 allow_extra_fields = True
287 allow_extra_fields = True
289 filter_extra_fields = True
288 filter_extra_fields = True
@@ -299,6 +298,19 b' def DefaultPermissionsForm(repo_perms_ch'
299 return _DefaultPermissionsForm
298 return _DefaultPermissionsForm
300
299
301
300
301 def DefaultsForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()):
302 class _DefaultsForm(formencode.Schema):
303 allow_extra_fields = True
304 filter_extra_fields = True
305 default_repo_type = v.OneOf(supported_backends)
306 default_repo_private = v.StringBoolean(if_missing=False)
307 default_repo_enable_statistics = v.StringBoolean(if_missing=False)
308 default_repo_enable_downloads = v.StringBoolean(if_missing=False)
309 default_repo_enable_locking = v.StringBoolean(if_missing=False)
310
311 return _DefaultsForm
312
313
302 def LdapSettingsForm(tls_reqcert_choices, search_scope_choices,
314 def LdapSettingsForm(tls_reqcert_choices, search_scope_choices,
303 tls_kind_choices):
315 tls_kind_choices):
304 class _LdapSettingsForm(formencode.Schema):
316 class _LdapSettingsForm(formencode.Schema):
@@ -37,7 +37,8 b' from rhodecode.lib.hooks import log_crea'
37
37
38 from rhodecode.model import BaseModel
38 from rhodecode.model import BaseModel
39 from rhodecode.model.db import Repository, UserRepoToPerm, User, Permission, \
39 from rhodecode.model.db import Repository, UserRepoToPerm, User, Permission, \
40 Statistics, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi, RepoGroup
40 Statistics, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi, RepoGroup,\
41 RhodeCodeSetting
41 from rhodecode.lib import helpers as h
42 from rhodecode.lib import helpers as h
42
43
43
44
@@ -205,7 +206,8 b' class RepoModel(BaseModel):'
205 def create_repo(self, repo_name, repo_type, description, owner,
206 def create_repo(self, repo_name, repo_type, description, owner,
206 private=False, clone_uri=None, repos_group=None,
207 private=False, clone_uri=None, repos_group=None,
207 landing_rev='tip', just_db=False, fork_of=None,
208 landing_rev='tip', just_db=False, fork_of=None,
208 copy_fork_permissions=False):
209 copy_fork_permissions=False, enable_statistics=False,
210 enable_locking=False, enable_downloads=False):
209 """
211 """
210 Create repository
212 Create repository
211
213
@@ -234,6 +236,10 b' class RepoModel(BaseModel):'
234 new_repo.clone_uri = clone_uri
236 new_repo.clone_uri = clone_uri
235 new_repo.landing_rev = landing_rev
237 new_repo.landing_rev = landing_rev
236
238
239 new_repo.enable_statistics = enable_statistics
240 new_repo.enable_locking = enable_locking
241 new_repo.enable_downloads = enable_downloads
242
237 if repos_group:
243 if repos_group:
238 new_repo.enable_locking = repos_group.enable_locking
244 new_repo.enable_locking = repos_group.enable_locking
239
245
@@ -307,20 +313,27 b' class RepoModel(BaseModel):'
307 :param just_db:
313 :param just_db:
308 :param fork:
314 :param fork:
309 """
315 """
310
316 owner = cur_user
311 repo_name = form_data['repo_name_full']
317 repo_name = form_data['repo_name_full']
312 repo_type = form_data['repo_type']
318 repo_type = form_data['repo_type']
313 description = form_data['description']
319 description = form_data['repo_description']
314 owner = cur_user
320 private = form_data['repo_private']
315 private = form_data['private']
316 clone_uri = form_data.get('clone_uri')
321 clone_uri = form_data.get('clone_uri')
317 repos_group = form_data['repo_group']
322 repos_group = form_data['repo_group']
318 landing_rev = form_data['landing_rev']
323 landing_rev = form_data['repo_landing_rev']
319 copy_fork_permissions = form_data.get('copy_permissions')
324 copy_fork_permissions = form_data.get('copy_permissions')
320 fork_of = form_data.get('fork_parent_id')
325 fork_of = form_data.get('fork_parent_id')
326
327 ##defaults
328 defs = RhodeCodeSetting.get_default_repo_settings(strip_prefix=True)
329 enable_statistics = defs.get('repo_enable_statistic')
330 enable_locking = defs.get('repo_enable_locking')
331 enable_downloads = defs.get('repo_enable_downloads')
332
321 return self.create_repo(
333 return self.create_repo(
322 repo_name, repo_type, description, owner, private, clone_uri,
334 repo_name, repo_type, description, owner, private, clone_uri,
323 repos_group, landing_rev, just_db, fork_of, copy_fork_permissions
335 repos_group, landing_rev, just_db, fork_of, copy_fork_permissions,
336 enable_statistics, enable_locking, enable_downloads
324 )
337 )
325
338
326 def create_fork(self, form_data, cur_user):
339 def create_fork(self, form_data, cur_user):
@@ -626,6 +626,14 b' div:hover > a.permalink {'
626 padding: 12px 9px 7px 24px;
626 padding: 12px 9px 7px 24px;
627 }
627 }
628
628
629 #header #header-inner #quick li ul li a.defaults,#header #header-inner #quick li ul li a.defaults:hover
630 {
631 background: #FFF url("../images/icons/wrench.png") no-repeat 4px 9px;
632 width: 167px;
633 margin: 0;
634 padding: 12px 9px 7px 24px;
635 }
636
629 #header #header-inner #quick li ul li a.settings,#header #header-inner #quick li ul li a.settings:hover
637 #header #header-inner #quick li ul li a.settings,#header #header-inner #quick li ul li a.settings:hover
630 {
638 {
631 background: #FFF url("../images/icons/cog.png") no-repeat 4px 9px;
639 background: #FFF url("../images/icons/cog.png") no-repeat 4px 9px;
@@ -44,28 +44,28 b''
44 </div>
44 </div>
45 <div class="field">
45 <div class="field">
46 <div class="label">
46 <div class="label">
47 <label for="landing_rev">${_('Landing revision')}:</label>
47 <label for="repo_landing_rev">${_('Landing revision')}:</label>
48 </div>
48 </div>
49 <div class="input">
49 <div class="input">
50 ${h.select('landing_rev','',c.landing_revs,class_="medium")}
50 ${h.select('repo_landing_rev','',c.landing_revs,class_="medium")}
51 <span class="help-block">${_('Default revision for files page, downloads, whoosh and readme')}</span>
51 <span class="help-block">${_('Default revision for files page, downloads, whoosh and readme')}</span>
52 </div>
52 </div>
53 </div>
53 </div>
54 <div class="field">
54 <div class="field">
55 <div class="label label-textarea">
55 <div class="label label-textarea">
56 <label for="description">${_('Description')}:</label>
56 <label for="repo_description">${_('Description')}:</label>
57 </div>
57 </div>
58 <div class="textarea text-area editor">
58 <div class="textarea text-area editor">
59 ${h.textarea('description')}
59 ${h.textarea('repo_description')}
60 <span class="help-block">${_('Keep it short and to the point. Use a README file for longer descriptions.')}</span>
60 <span class="help-block">${_('Keep it short and to the point. Use a README file for longer descriptions.')}</span>
61 </div>
61 </div>
62 </div>
62 </div>
63 <div class="field">
63 <div class="field">
64 <div class="label label-checkbox">
64 <div class="label label-checkbox">
65 <label for="private">${_('Private repository')}:</label>
65 <label for="repo_private">${_('Private repository')}:</label>
66 </div>
66 </div>
67 <div class="checkboxes">
67 <div class="checkboxes">
68 ${h.checkbox('private',value="True")}
68 ${h.checkbox('repo_private',value="True")}
69 <span class="help-block">${_('Private repositories are only visible to people explicitly added as collaborators.')}</span>
69 <span class="help-block">${_('Private repositories are only visible to people explicitly added as collaborators.')}</span>
70 </div>
70 </div>
71 </div>
71 </div>
@@ -236,6 +236,7 b''
236 <li>${h.link_to(_('users groups'),h.url('users_groups'),class_='groups')}</li>
236 <li>${h.link_to(_('users groups'),h.url('users_groups'),class_='groups')}</li>
237 <li>${h.link_to(_('permissions'),h.url('edit_permission',id='default'),class_='permissions')}</li>
237 <li>${h.link_to(_('permissions'),h.url('edit_permission',id='default'),class_='permissions')}</li>
238 <li>${h.link_to(_('ldap'),h.url('ldap_home'),class_='ldap')}</li>
238 <li>${h.link_to(_('ldap'),h.url('ldap_home'),class_='ldap')}</li>
239 <li>${h.link_to(_('defaults'),h.url('defaults'),class_='defaults')}</li>
239 <li class="last">${h.link_to(_('settings'),h.url('admin_settings'),class_='settings')}</li>
240 <li class="last">${h.link_to(_('settings'),h.url('admin_settings'),class_='settings')}</li>
240 </ul>
241 </ul>
241 </%def>
242 </%def>
@@ -47,7 +47,7 b' log = logging.getLogger(__name__)'
47 'TEST_USER_REGULAR2_PASS', 'TEST_USER_REGULAR2_EMAIL', 'TEST_HG_REPO',
47 'TEST_USER_REGULAR2_PASS', 'TEST_USER_REGULAR2_EMAIL', 'TEST_HG_REPO',
48 'TEST_HG_REPO_CLONE', 'TEST_HG_REPO_PULL', 'TEST_GIT_REPO',
48 'TEST_HG_REPO_CLONE', 'TEST_HG_REPO_PULL', 'TEST_GIT_REPO',
49 'TEST_GIT_REPO_CLONE', 'TEST_GIT_REPO_PULL', 'HG_REMOTE_REPO',
49 'TEST_GIT_REPO_CLONE', 'TEST_GIT_REPO_PULL', 'HG_REMOTE_REPO',
50 'GIT_REMOTE_REPO', 'SCM_TESTS',
50 'GIT_REMOTE_REPO', 'SCM_TESTS', '_get_repo_create_params'
51 ]
51 ]
52
52
53 # Invoke websetup with the current config file
53 # Invoke websetup with the current config file
@@ -163,3 +163,24 b' class TestController(TestCase):'
163 'msg `%s` not found in session flash: got `%s` instead' % (
163 'msg `%s` not found in session flash: got `%s` instead' % (
164 msg, response.session['flash'])
164 msg, response.session['flash'])
165 )
165 )
166
167
168 ## HELPERS ##
169
170 def _get_repo_create_params(**custom):
171 defs = {
172 'repo_name': None,
173 'repo_type': 'hg',
174 'clone_uri': '',
175 'repo_group': '',
176 'repo_description': 'DESC',
177 'repo_private': False,
178 'repo_landing_rev': 'tip'
179 }
180 defs.update(custom)
181 if 'repo_name_full' not in custom:
182 defs.update({'repo_name_full': defs['repo_name']})
183
184 return defs
185
186
@@ -61,15 +61,10 b' def destroy_users_group(name=TEST_USERS_'
61
61
62 def create_repo(repo_name, repo_type):
62 def create_repo(repo_name, repo_type):
63 # create new repo
63 # create new repo
64 form_data = dict(repo_name=repo_name,
64 form_data = _get_repo_create_params(
65 repo_name_full=repo_name,
65 repo_name_full=repo_name,
66 fork_name=None,
66 repo_description='description %s' % repo_name,
67 description='description %s' % repo_name,
67 )
68 repo_group=None,
69 private=False,
70 repo_type=repo_type,
71 clone_uri=None,
72 landing_rev='tip')
73 cur_user = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN)
68 cur_user = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN)
74 r = RepoModel().create(form_data, cur_user)
69 r = RepoModel().create(form_data, cur_user)
75 Session().commit()
70 Session().commit()
@@ -26,14 +26,10 b' class TestAdminReposController(TestContr'
26 self.log_user()
26 self.log_user()
27 repo_name = NEW_HG_REPO
27 repo_name = NEW_HG_REPO
28 description = 'description for newly created repo'
28 description = 'description for newly created repo'
29 private = False
29 response = self.app.post(url('repos'),
30 response = self.app.post(url('repos'), {'repo_name': repo_name,
30 _get_repo_create_params(repo_private=False,
31 'repo_type': 'hg',
31 repo_name=repo_name,
32 'clone_uri': '',
32 repo_description=description))
33 'repo_group': '',
34 'description': description,
35 'private': private,
36 'landing_rev': 'tip'})
37 self.checkSessionFlash(response,
33 self.checkSessionFlash(response,
38 'created repository %s' % (repo_name))
34 'created repository %s' % (repo_name))
39
35
@@ -63,13 +59,10 b' class TestAdminReposController(TestContr'
63 description = 'description for newly created repo' + non_ascii
59 description = 'description for newly created repo' + non_ascii
64 description_unicode = description.decode('utf8')
60 description_unicode = description.decode('utf8')
65 private = False
61 private = False
66 response = self.app.post(url('repos'), {'repo_name': repo_name,
62 response = self.app.post(url('repos'),
67 'repo_type': 'hg',
63 _get_repo_create_params(repo_private=False,
68 'clone_uri': '',
64 repo_name=repo_name,
69 'repo_group': '',
65 repo_description=description))
70 'description': description,
71 'private': private,
72 'landing_rev': 'tip'})
73 self.checkSessionFlash(response,
66 self.checkSessionFlash(response,
74 'created repository %s' % (repo_name_unicode))
67 'created repository %s' % (repo_name_unicode))
75
68
@@ -103,14 +96,12 b' class TestAdminReposController(TestContr'
103 repo_name = 'ingroup'
96 repo_name = 'ingroup'
104 repo_name_full = RepoGroup.url_sep().join([group_name, repo_name])
97 repo_name_full = RepoGroup.url_sep().join([group_name, repo_name])
105 description = 'description for newly created repo'
98 description = 'description for newly created repo'
106 private = False
99 response = self.app.post(url('repos'),
107 response = self.app.post(url('repos'), {'repo_name': repo_name,
100 _get_repo_create_params(repo_private=False,
108 'repo_type': 'hg',
101 repo_name=repo_name,
109 'clone_uri': '',
102 repo_description=description,
110 'repo_group': gr.group_id,
103 repo_group=gr.group_id,))
111 'description': description,
104
112 'private': private,
113 'landing_rev': 'tip'})
114 self.checkSessionFlash(response,
105 self.checkSessionFlash(response,
115 'created repository %s' % (repo_name))
106 'created repository %s' % (repo_name))
116
107
@@ -142,14 +133,12 b' class TestAdminReposController(TestContr'
142 self.log_user()
133 self.log_user()
143 repo_name = NEW_GIT_REPO
134 repo_name = NEW_GIT_REPO
144 description = 'description for newly created repo'
135 description = 'description for newly created repo'
145 private = False
136
146 response = self.app.post(url('repos'), {'repo_name': repo_name,
137 response = self.app.post(url('repos'),
147 'repo_type': 'git',
138 _get_repo_create_params(repo_private=False,
148 'clone_uri': '',
139 repo_type='git',
149 'repo_group': '',
140 repo_name=repo_name,
150 'description': description,
141 repo_description=description))
151 'private': private,
152 'landing_rev': 'tip'})
153 self.checkSessionFlash(response,
142 self.checkSessionFlash(response,
154 'created repository %s' % (repo_name))
143 'created repository %s' % (repo_name))
155
144
@@ -179,13 +168,12 b' class TestAdminReposController(TestContr'
179 description = 'description for newly created repo' + non_ascii
168 description = 'description for newly created repo' + non_ascii
180 description_unicode = description.decode('utf8')
169 description_unicode = description.decode('utf8')
181 private = False
170 private = False
182 response = self.app.post(url('repos'), {'repo_name': repo_name,
171 response = self.app.post(url('repos'),
183 'repo_type': 'git',
172 _get_repo_create_params(repo_private=False,
184 'clone_uri': '',
173 repo_type='git',
185 'repo_group': '',
174 repo_name=repo_name,
186 'description': description,
175 repo_description=description))
187 'private': private,
176
188 'landing_rev': 'tip'})
189 self.checkSessionFlash(response,
177 self.checkSessionFlash(response,
190 'created repository %s' % (repo_name_unicode))
178 'created repository %s' % (repo_name_unicode))
191
179
@@ -226,13 +214,12 b' class TestAdminReposController(TestContr'
226 repo_name = 'vcs_test_new_to_delete'
214 repo_name = 'vcs_test_new_to_delete'
227 description = 'description for newly created repo'
215 description = 'description for newly created repo'
228 private = False
216 private = False
229 response = self.app.post(url('repos'), {'repo_name': repo_name,
217 response = self.app.post(url('repos'),
230 'repo_type': 'hg',
218 _get_repo_create_params(repo_private=False,
231 'clone_uri': '',
219 repo_type='hg',
232 'repo_group': '',
220 repo_name=repo_name,
233 'description': description,
221 repo_description=description))
234 'private': private,
222
235 'landing_rev': 'tip'})
236 self.checkSessionFlash(response,
223 self.checkSessionFlash(response,
237 'created repository %s' % (repo_name))
224 'created repository %s' % (repo_name))
238
225
@@ -275,13 +262,12 b' class TestAdminReposController(TestContr'
275 repo_name = 'vcs_test_new_to_delete'
262 repo_name = 'vcs_test_new_to_delete'
276 description = 'description for newly created repo'
263 description = 'description for newly created repo'
277 private = False
264 private = False
278 response = self.app.post(url('repos'), {'repo_name': repo_name,
265 response = self.app.post(url('repos'),
279 'repo_type': 'git',
266 _get_repo_create_params(repo_private=False,
280 'clone_uri': '',
267 repo_type='git',
281 'repo_group': '',
268 repo_name=repo_name,
282 'description': description,
269 repo_description=description))
283 'private': private,
270
284 'landing_rev': 'tip'})
285 self.checkSessionFlash(response,
271 self.checkSessionFlash(response,
286 'created repository %s' % (repo_name))
272 'created repository %s' % (repo_name))
287
273
@@ -1,4 +1,6 b''
1 from rhodecode.tests import *
1 from rhodecode.tests import *
2 from rhodecode.model.db import Repository
3 from rhodecode.model.meta import Session
2
4
3 ARCHIVE_SPECS = {
5 ARCHIVE_SPECS = {
4 '.tar.bz2': ('application/x-bzip2', 'tbz2', ''),
6 '.tar.bz2': ('application/x-bzip2', 'tbz2', ''),
@@ -7,6 +9,13 b' ARCHIVE_SPECS = {'
7 }
9 }
8
10
9
11
12 def _set_downloads(repo_name, set_to):
13 repo = Repository.get_by_repo_name(repo_name)
14 repo.enable_downloads = set_to
15 Session().add(repo)
16 Session().commit()
17
18
10 class TestFilesController(TestController):
19 class TestFilesController(TestController):
11
20
12 def test_index(self):
21 def test_index(self):
@@ -216,7 +225,7 b' removed extra unicode conversion in diff'
216
225
217 def test_archival(self):
226 def test_archival(self):
218 self.log_user()
227 self.log_user()
219
228 _set_downloads(HG_REPO, set_to=True)
220 for arch_ext, info in ARCHIVE_SPECS.items():
229 for arch_ext, info in ARCHIVE_SPECS.items():
221 short = '27cd5cce30c9%s' % arch_ext
230 short = '27cd5cce30c9%s' % arch_ext
222 fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext
231 fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext
@@ -237,7 +246,7 b' removed extra unicode conversion in diff'
237
246
238 def test_archival_wrong_ext(self):
247 def test_archival_wrong_ext(self):
239 self.log_user()
248 self.log_user()
240
249 _set_downloads(HG_REPO, set_to=True)
241 for arch_ext in ['tar', 'rar', 'x', '..ax', '.zipz']:
250 for arch_ext in ['tar', 'rar', 'x', '..ax', '.zipz']:
242 fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext
251 fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext
243
252
@@ -249,7 +258,7 b' removed extra unicode conversion in diff'
249
258
250 def test_archival_wrong_revision(self):
259 def test_archival_wrong_revision(self):
251 self.log_user()
260 self.log_user()
252
261 _set_downloads(HG_REPO, set_to=True)
253 for rev in ['00x000000', 'tar', 'wrong', '@##$@$42413232', '232dffcd']:
262 for rev in ['00x000000', 'tar', 'wrong', '@##$@$42413232', '232dffcd']:
254 fname = '%s.zip' % rev
263 fname = '%s.zip' % rev
255
264
@@ -4,7 +4,7 b' from rhodecode.tests import *'
4
4
5 from rhodecode.model.repos_group import ReposGroupModel
5 from rhodecode.model.repos_group import ReposGroupModel
6 from rhodecode.model.repo import RepoModel
6 from rhodecode.model.repo import RepoModel
7 from rhodecode.model.db import RepoGroup, User, Repository
7 from rhodecode.model.db import RepoGroup, User
8 from rhodecode.model.meta import Session
8 from rhodecode.model.meta import Session
9 from sqlalchemy.exc import IntegrityError
9 from sqlalchemy.exc import IntegrityError
10
10
@@ -125,17 +125,7 b' class TestReposGroups(unittest.TestCase)'
125 g2 = _make_group('g2')
125 g2 = _make_group('g2')
126
126
127 # create new repo
127 # create new repo
128 form_data = dict(repo_name='john',
128 form_data = _get_repo_create_params(repo_name='john')
129 repo_name_full='john',
130 fork_name=None,
131 description=None,
132 repo_group=None,
133 private=False,
134 repo_type='hg',
135 clone_uri=None,
136 landing_rev='tip',
137 enable_locking=False,
138 recursive=False)
139 cur_user = User.get_by_username(TEST_USER_ADMIN_LOGIN)
129 cur_user = User.get_by_username(TEST_USER_ADMIN_LOGIN)
140 r = RepoModel().create(form_data, cur_user)
130 r = RepoModel().create(form_data, cur_user)
141
131
General Comments 0
You need to be logged in to leave comments. Login now