# HG changeset patch # User Marcin Kuzminski # Date 1277904910 -7200 # Node ID 05b212954275e6adc7a40553fa2214711039d5bf # Parent c12f4d19c95065f313eefcd45eac9ef507f5fa55 Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository diff -r c12f4d19c950 -r 05b212954275 pylons_app/config/routing.py --- a/pylons_app/config/routing.py Tue Jun 29 20:45:35 2010 +0200 +++ b/pylons_app/config/routing.py Wed Jun 30 15:35:10 2010 +0200 @@ -115,4 +115,12 @@ map.connect('files_archive_home', '/{repo_name:.*}/archive/{revision}/{fileformat}', controller='files', action='archivefile', revision='tip', conditions=dict(function=check_repo)) + map.connect('repo_settings_update', '/{repo_name:.*}/settings', + controller='settings', action="update", + conditions=dict(method=["PUT"], function=check_repo)) + map.connect('repo_settings_home', '/{repo_name:.*}/settings', + controller='settings', action='index', + conditions=dict(function=check_repo)) + + return map diff -r c12f4d19c950 -r 05b212954275 pylons_app/controllers/settings.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/controllers/settings.py Wed Jun 30 15:35:10 2010 +0200 @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# encoding: utf-8 +# settings controller for pylons +# Copyright (C) 2009-2010 Marcin Kuzminski + +# 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; version 2 +# of the License or (at your opinion) any later version of the license. +# +# 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. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. +""" +Created on June 30, 2010 +settings controller for pylons +@author: marcink +""" +from formencode import htmlfill +from pylons import tmpl_context as c, request, url +from pylons.controllers.util import redirect +from pylons.i18n.translation import _ +from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAllDecorator +from pylons_app.lib.base import BaseController, render +from pylons_app.lib.utils import invalidate_cache +from pylons_app.model.forms import RepoSettingsForm +from pylons_app.model.repo_model import RepoModel +import formencode +import logging +import pylons_app.lib.helpers as h +log = logging.getLogger(__name__) + +class SettingsController(BaseController): + + @LoginRequired() + @HasRepoPermissionAllDecorator('repository.admin') + def __before__(self): + super(SettingsController, self).__before__() + + def index(self, repo_name): + repo_model = RepoModel() + c.repo_info = repo = repo_model.get(repo_name) + if not repo: + h.flash(_('%s repository is not mapped to db perhaps' + ' it was created or renamed from the filesystem' + ' please run the application again' + ' in order to rescan repositories') % repo_name, + category='error') + + return redirect(url('repos')) + defaults = c.repo_info.__dict__ + defaults.update({'user':c.repo_info.user.username}) + c.users_array = repo_model.get_users_js() + + for p in c.repo_info.repo2perm: + defaults.update({'perm_%s' % p.user.username: + p.permission.permission_name}) + + return htmlfill.render( + render('settings/repo_settings.html'), + defaults=defaults, + encoding="UTF-8", + force_defaults=False + ) + + def update(self, repo_name): + print request.POST + print 'x' * 110 + repo_model = RepoModel() + _form = RepoSettingsForm(edit=True)() + try: + form_result = _form.to_python(dict(request.POST)) + repo_model.update(repo_name, form_result) + invalidate_cache('cached_repo_list') + h.flash(_('Repository %s updated succesfully' % repo_name), + category='success') + + except formencode.Invalid as errors: + c.repo_info = repo_model.get(repo_name) + c.users_array = repo_model.get_users_js() + errors.value.update({'user':c.repo_info.user.username}) + c.form_errors = errors.error_dict + return htmlfill.render( + render('admin/repos/repo_edit.html'), + defaults=errors.value, + encoding="UTF-8") + except Exception: + h.flash(_('error occured during update of repository %s') \ + % form_result['repo_name'], category='error') + + return redirect(url('repo_settings_home', repo_name=repo_name)) diff -r c12f4d19c950 -r 05b212954275 pylons_app/model/forms.py --- a/pylons_app/model/forms.py Tue Jun 29 20:45:35 2010 +0200 +++ b/pylons_app/model/forms.py Wed Jun 30 15:35:10 2010 +0200 @@ -182,7 +182,15 @@ state=State_obj) raise formencode.Invalid(msg, value, state, error_dict={'perm_new_user_name':msg}) return value - + +class ValidSettings(formencode.validators.FancyValidator): + + def to_python(self, value, state): + #settings form can't edit user + if value.has_key('user'): + del['value']['user'] + + return value #=============================================================================== # FORMS #=============================================================================== @@ -240,3 +248,18 @@ chained_validators = [ValidPerms] return _RepoForm + +def RepoSettingsForm(edit=False): + class _RepoForm(formencode.Schema): + allow_extra_fields = True + filter_extra_fields = False + repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit)) + description = UnicodeString(strip=True, min=3, not_empty=True) + private = StringBoolean(if_missing=False) + + chained_validators = [ValidPerms, ValidSettings] + return _RepoForm + + + + diff -r c12f4d19c950 -r 05b212954275 pylons_app/templates/base/base.html --- a/pylons_app/templates/base/base.html Tue Jun 29 20:45:35 2010 +0200 +++ b/pylons_app/templates/base/base.html Wed Jun 30 15:35:10 2010 +0200 @@ -107,7 +107,7 @@
  • ${h.link_to(_('tags'),h.url('tags_home',repo_name=c.repo_name))}
  • ${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name))}
  • %if h.HasRepoPermissionAll('repository.admin')(c.repo_name): -
  • ${h.link_to(_('settings'),h.url('edit_repo',repo_name=c.repo_name))}
  • +
  • ${h.link_to(_('settings'),h.url('repo_settings_home',repo_name=c.repo_name))}
  • %endif %else: diff -r c12f4d19c950 -r 05b212954275 pylons_app/templates/settings/repo_settings.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/templates/settings/repo_settings.html Wed Jun 30 15:35:10 2010 +0200 @@ -0,0 +1,240 @@ +## -*- coding: utf-8 -*- +<%inherit file="/base/base.html"/> + +<%def name="title()"> + ${_('Repository settings')} + +<%def name="breadcrumbs()"> + ${h.link_to(u'Home',h.url('/'))} + / + ${h.link_to(c.repo_name,h.url('shortlog_home',repo_name=c.repo_name))} + / + ${_('settings')} + +<%def name="page_nav()"> + ${self.menu('settings')} + +<%def name="main()"> + +
    + ${h.form(url('repo_settings_update', repo_name=c.repo_info.repo_name),method='put')} + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ${_('Name')}${h.text('repo_name',size="28")}${self.get_form_error('repo_name')}
    ${_('Description')}${h.textarea('description',cols=32,rows=5)}${self.get_form_error('description')}
    ${_('Private')}${h.checkbox('private',value="True")}${self.get_form_error('private')}
    ${_('Permissions')} + + + + + + + + + + %for r2p in c.repo_info.repo2perm: + %if r2p.user.username =='default' and c.repo_info.private: + + + + + %else: + + + + + + + + + %endif + %endfor + <% + if not hasattr(c,'form_errors'): + d = 'display:none;' + else: + d='' + %> + + + + + + + + + + + + +
    ${_('none')}${_('read')}${_('write')}${_('admin')}${_('user')}
    + ${_('disabled for private repository')}${r2p.user.username}
    ${h.radio('perm_%s' % r2p.user.username,'repository.none')}${h.radio('perm_%s' % r2p.user.username,'repository.read')}${h.radio('perm_%s' % r2p.user.username,'repository.write')}${h.radio('perm_%s' % r2p.user.username,'repository.admin')}${r2p.user.username} + %if r2p.user.username !='default': + + + + %endif +
    ${h.radio('perm_new_user','repository.none')}${h.radio('perm_new_user','repository.read')}${h.radio('perm_new_user','repository.write')}${h.radio('perm_new_user','repository.admin')} +
    + ${h.text('perm_new_user_name',class_='yui-ac-input')} +
    +
    +
    ${self.get_form_error('perm_new_user_name')}
    + + ${_('Add another user')} + +
    +
    ${h.submit('update','update')}
    + ${h.end_form()} + + +
    + diff -r c12f4d19c950 -r 05b212954275 pylons_app/templates/shortlog/shortlog.html --- a/pylons_app/templates/shortlog/shortlog.html Tue Jun 29 20:45:35 2010 +0200 +++ b/pylons_app/templates/shortlog/shortlog.html Wed Jun 30 15:35:10 2010 +0200 @@ -1,3 +1,4 @@ +## -*- coding: utf-8 -*- <%inherit file="/base/base.html"/> <%def name="title()"> diff -r c12f4d19c950 -r 05b212954275 pylons_app/tests/functional/test_settings.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/tests/functional/test_settings.py Wed Jun 30 15:35:10 2010 +0200 @@ -0,0 +1,7 @@ +from pylons_app.tests import * + +class TestSettingsController(TestController): + + def test_index(self): + response = self.app.get(url(controller='settings', action='index')) + # Test response...