##// END OF EJS Templates
backward compat: use safe .get on show_id function CONFIG calls
backward compat: use safe .get on show_id function CONFIG calls

File last commit:

r3525:0cef54d3 default
r3558:d91cdc11 beta
Show More
settings.py
200 lines | 7.5 KiB | text/x-python | PythonLexer
updated docs on every controller
r861 # -*- coding: utf-8 -*-
"""
rhodecode.controllers.settings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Settings controller for rhodecode
source code cleanup: remove trailing white space, normalize file endings
r1203
updated docs on every controller
r861 :created_on: Jun 30, 2010
:author: marcink
2012 copyrights
r1824 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
updated docs on every controller
r861 :license: GPLv3, see COPYING for more details.
"""
fixed license issue #149
r1206 # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
source code cleanup: remove trailing white space, normalize file endings
r1203 #
renamed project to rhodecode
r547 # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
source code cleanup: remove trailing white space, normalize file endings
r1203 #
renamed project to rhodecode
r547 # You should have received a copy of the GNU General Public License
fixed license issue #149
r1206 # along with this program. If not, see <http://www.gnu.org/licenses/>.
updated docs on every controller
r861
import logging
import traceback
fixed some very strange issue with htmlfill import - don't know why but this needs to be imported as separate module
r1067 import formencode
updated docs on every controller
r861
fixed some very strange issue with htmlfill import - don't know why but this needs to be imported as separate module
r1067 from formencode import htmlfill
updated docs on every controller
r861
renamed project to rhodecode
r547 from pylons import tmpl_context as c, request, url
from pylons.controllers.util import redirect
from pylons.i18n.translation import _
updated docs on every controller
r861
import rhodecode.lib.helpers as h
#113 removed anonymous access from forking, added system messages in login box.
r1056
Add quick toggle link for locking for users with write or admin permissions
r2833 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAllDecorator,\
HasRepoPermissionAnyDecorator
another major codes rewrite:...
r1045 from rhodecode.lib.base import BaseRepoController, render
renamed project to rhodecode
r547 from rhodecode.lib.utils import invalidate_cache, action_logger
#113 removed anonymous access from forking, added system messages in login box.
r1056
#235 forking page repo group selection...
r1722 from rhodecode.model.forms import RepoSettingsForm
Code refactoring,models renames...
r629 from rhodecode.model.repo import RepoModel
repository extra fields implementation...
r3308 from rhodecode.model.db import RepoGroup, Repository, RepositoryField
#235 forking page repo group selection...
r1722 from rhodecode.model.meta import Session
filter out repo groups choices to only ones that you have write+ access to. Before it was read+ access and you got proper...
r3239 from rhodecode.model.scm import ScmModel, GroupList
renamed project to rhodecode
r547
log = logging.getLogger(__name__)
pep8ify
r1212
another major codes rewrite:...
r1045 class SettingsController(BaseRepoController):
renamed project to rhodecode
r547
@LoginRequired()
def __before__(self):
super(SettingsController, self).__before__()
#235 forking page repo group selection...
r1722
fixes #288...
r1594 def __load_defaults(self):
filter out repo groups choices to only ones that you have write+ access to. Before it was read+ access and you got proper...
r3239 acl_groups = GroupList(RepoGroup.query().all(),
perm_set=['group.write', 'group.admin'])
c.repo_groups = RepoGroup.groups_choices(groups=acl_groups)
fixes #288...
r1594 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
#235 forking page repo group selection...
r1722
fixes #288...
r1594 repo_model = RepoModel()
c.users_array = repo_model.get_users_js()
c.users_groups_array = repo_model.get_users_groups_js()
validating choices for landing_rev
r2460 choices, c.landing_revs = ScmModel().get_repo_landing_revs()
c.landing_revs_choices = choices
#235 forking page repo group selection...
r1722
Fixed some issues with edit form...
r3089 def __load_data(self, repo_name=None):
"""
Load defaults settings for edit, and update
:param repo_name:
"""
self.__load_defaults()
repository extra fields implementation...
r3308 c.repo_info = db_repo = Repository.get_by_repo_name(repo_name)
Fixed some issues with edit form...
r3089
if c.repo_info is None:
- #683 fixed difference between messages about not mapped repositories
r3110 h.not_mapped_error(repo_name)
Fixes for raw_id, needed for git...
r636 return redirect(url('home'))
#56 added ajax removal of users groups,...
r1015
Fixed some issues with edit form...
r3089 ##override defaults for exact repo info here git/hg etc
choices, c.landing_revs = ScmModel().get_repo_landing_revs(c.repo_info)
c.landing_revs_choices = choices
repository extra fields implementation...
r3308 c.repo_fields = RepositoryField.query()\
.filter(RepositoryField.repository == db_repo).all()
fixes #288...
r1594 defaults = RepoModel()._get_defaults(repo_name)
Fixes for raw_id, needed for git...
r636
Fixed some issues with edit form...
r3089 return defaults
@HasRepoPermissionAllDecorator('repository.admin')
def index(self, repo_name):
defaults = self.__load_data(repo_name)
fixed some very strange issue with htmlfill import - don't know why but this needs to be imported as separate module
r1067 return htmlfill.render(
renamed project to rhodecode
r547 render('settings/repo_settings.html'),
defaults=defaults,
encoding="UTF-8",
force_defaults=False
Fixes for raw_id, needed for git...
r636 )
renamed project to rhodecode
r547
fixed #113 to high permission was required to fork a repository
r1054 @HasRepoPermissionAllDecorator('repository.admin')
renamed project to rhodecode
r547 def update(self, repo_name):
Fixed some issues with edit form...
r3089 self.__load_defaults()
renamed project to rhodecode
r547 repo_model = RepoModel()
changed_name = repo_name
Fixed some issues with edit form...
r3089 #override the choices with extracted revisions !
choices, c.landing_revs = ScmModel().get_repo_landing_revs(repo_name)
c.landing_revs_choices = choices
Pass in old groups data to CanWriteToGroup validator for later skipping group checks....
r3524 repo = Repository.get_by_repo_name(repo_name)
pep8ify
r1212 _form = RepoSettingsForm(edit=True,
Pass in old groups data to CanWriteToGroup validator for later skipping group checks....
r3524 old_data={'repo_name': repo_name,
'repo_group': repo.group.get_dict() \
if repo.group else {}},
validating choices for landing_rev
r2460 repo_groups=c.repo_groups_choices,
landing_revs=c.landing_revs_choices)()
renamed project to rhodecode
r547 try:
form_result = _form.to_python(dict(request.POST))
Fixed some issues with edit form...
r3089 repo_model.update(repo_name, **form_result)
Moved out reposcan into hg Model....
r665 invalidate_cache('get_repo_cached_%s' % repo_name)
Takumi IINO
i18n improve
r2570 h.flash(_('Repository %s updated successfully') % repo_name,
renamed project to rhodecode
r547 category='success')
fixes #288...
r1594 changed_name = form_result['repo_name_full']
#48 rewrote action logger, translated action logger messages, added some extra messages. Linked and showed pushed revisions in logs
r660 action_logger(self.rhodecode_user, 'user_updated_repo',
Implemented #467 Journal logs comments on changesets...
r2375 changed_name, self.ip_addr, self.sa)
Add quick toggle link for locking for users with write or admin permissions
r2833 Session().commit()
refactor codes and setup for python 2.5...
r564 except formencode.Invalid, errors:
Fixed some issues with edit form...
r3089 defaults = self.__load_data(repo_name)
defaults.update(errors.value)
fixed some very strange issue with htmlfill import - don't know why but this needs to be imported as separate module
r1067 return htmlfill.render(
renamed project to rhodecode
r547 render('settings/repo_settings.html'),
defaults=errors.value,
errors=errors.error_dict or {},
prefix_error=False,
Fixes for raw_id, needed for git...
r636 encoding="UTF-8")
Fixed some issues with edit form...
r3089
renamed project to rhodecode
r547 except Exception:
log.error(traceback.format_exc())
Moved out reposcan into hg Model....
r665 h.flash(_('error occurred during update of repository %s') \
renamed project to rhodecode
r547 % repo_name, category='error')
Fixes for raw_id, needed for git...
r636
renamed project to rhodecode
r547 return redirect(url('repo_settings_home', repo_name=changed_name))
fixed #113 to high permission was required to fork a repository
r1054 @HasRepoPermissionAllDecorator('repository.admin')
Fixes for raw_id, needed for git...
r636 def delete(self, repo_name):
renamed project to rhodecode
r547 """DELETE /repos/repo_name: Delete an existing item"""
# Forms posted to this method should contain a hidden field:
# <input type="hidden" name="_method" value="DELETE" />
# Or using helpers:
# h.form(url('repo_settings_delete', repo_name=ID),
# method='delete')
# url('repo_settings_delete', repo_name=ID)
Fixes for raw_id, needed for git...
r636
renamed project to rhodecode
r547 repo_model = RepoModel()
added action loggers to following repositories,...
r735 repo = repo_model.get_by_repo_name(repo_name)
renamed project to rhodecode
r547 if not repo:
- #683 fixed difference between messages about not mapped repositories
r3110 h.not_mapped_error(repo_name)
Fixes for raw_id, needed for git...
r636 return redirect(url('home'))
renamed project to rhodecode
r547 try:
refactor codes and setup for python 2.5...
r564 action_logger(self.rhodecode_user, 'user_deleted_repo',
Implemented #467 Journal logs comments on changesets...
r2375 repo_name, self.ip_addr, self.sa)
Fixes for raw_id, needed for git...
r636 repo_model.delete(repo)
Moved out reposcan into hg Model....
r665 invalidate_cache('get_repo_cached_%s' % repo_name)
renamed project to rhodecode
r547 h.flash(_('deleted repository %s') % repo_name, category='success')
Add quick toggle link for locking for users with write or admin permissions
r2833 Session().commit()
renamed project to rhodecode
r547 except Exception:
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached...
r1366 log.error(traceback.format_exc())
renamed project to rhodecode
r547 h.flash(_('An error occurred during deletion of %s') % repo_name,
category='error')
Fixes for raw_id, needed for git...
r636
fixes issue #675 Don't Re-direct from "My Repos" page when deleting a repository
r3083 return redirect(url('admin_settings_my_account', anchor='my'))
Add quick toggle link for locking for users with write or admin permissions
r2833
@HasRepoPermissionAnyDecorator('repository.write', 'repository.admin')
def toggle_locking(self, repo_name):
"""
Toggle locking of repository by simple GET call to url
:param repo_name:
"""
try:
repo = Repository.get_by_repo_name(repo_name)
if repo.enable_locking:
if repo.locked[0]:
Repository.unlock(repo)
action = _('unlocked')
else:
Repository.lock(repo, c.rhodecode_user.user_id)
action = _('locked')
h.flash(_('Repository has been %s') % action,
category='success')
except Exception, e:
log.error(traceback.format_exc())
h.flash(_('An error occurred during unlocking'),
category='error')
return redirect(url('summary_home', repo_name=repo_name))