diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -73,6 +73,11 @@ def make_map(config): m.connect('delete_repo_user', "/repos_delete_user/{repo_name:.*}", action="delete_perm_user", conditions=dict(method=["DELETE"], function=check_repo)) + #ajax delete repo perm users_group + m.connect('delete_repo_users_group', "/repos_delete_users_group/{repo_name:.*}", + action="delete_perm_users_group", conditions=dict(method=["DELETE"], + function=check_repo)) + #settings actions m.connect('repo_stats', "/repos_stats/{repo_name:.*}", action="repo_stats", conditions=dict(method=["DELETE"], diff --git a/rhodecode/controllers/admin/repos.py b/rhodecode/controllers/admin/repos.py --- a/rhodecode/controllers/admin/repos.py +++ b/rhodecode/controllers/admin/repos.py @@ -215,8 +215,8 @@ class ReposController(BaseController): @HasPermissionAllDecorator('hg.admin') def delete_perm_user(self, repo_name): - """ - DELETE an existing repository permission user + """DELETE an existing repository permission user + :param repo_name: """ @@ -229,9 +229,24 @@ class ReposController(BaseController): raise HTTPInternalServerError() @HasPermissionAllDecorator('hg.admin') - def repo_stats(self, repo_name): + def delete_perm_users_group(self, repo_name): + """DELETE an existing repository permission users group + + :param repo_name: """ - DELETE an existing repository statistics + try: + repo_model = RepoModel() + repo_model.delete_perm_users_group(request.POST, repo_name) + except Exception, e: + h.flash(_('An error occurred during deletion of repository' + ' users groups'), + category='error') + raise HTTPInternalServerError() + + @HasPermissionAllDecorator('hg.admin') + def repo_stats(self, repo_name): + """DELETE an existing repository statistics + :param repo_name: """ @@ -245,8 +260,8 @@ class ReposController(BaseController): @HasPermissionAllDecorator('hg.admin') def repo_cache(self, repo_name): - """ - INVALIDATE existing repository cache + """INVALIDATE existing repository cache + :param repo_name: """ @@ -267,8 +282,9 @@ class ReposController(BaseController): """GET /repos/repo_name/edit: Form to edit an existing item""" # url('edit_repo', repo_name=ID) repo_model = RepoModel() + c.repo_info = repo_model.get_by_repo_name(repo_name) + r = ScmModel().get(repo_name) - c.repo_info = repo_model.get_by_repo_name(repo_name) if c.repo_info is None: h.flash(_('%s repository is not mapped to db perhaps' @@ -293,7 +309,12 @@ class ReposController(BaseController): c.stats_percentage = '%.2f' % ((float((last_rev)) / c.repo_last_rev) * 100) + c.users_array = repo_model.get_users_js() + c.users_groups_array = repo_model.get_users_groups_js() + defaults = c.repo_info.get_dict() + + #fill owner if c.repo_info.user: defaults.update({'user':c.repo_info.user.username}) else: @@ -301,11 +322,15 @@ class ReposController(BaseController): .filter(User.admin == True).first().username defaults.update({'user':replacement_user}) - c.users_array = repo_model.get_users_js() - c.users_groups_array = repo_model.get_users_groups_js() + #fill repository users for p in c.repo_info.repo_to_perm: - defaults.update({'perm_%s' % p.user.username: + defaults.update({'u_perm_%s' % p.user.username: + p.permission.permission_name}) + + #fill repository groups + for p in c.repo_info.users_group_to_perm: + defaults.update({'g_perm_%s' % p.users_group.users_group_name: p.permission.permission_name}) return htmlfill.render( diff --git a/rhodecode/controllers/settings.py b/rhodecode/controllers/settings.py --- a/rhodecode/controllers/settings.py +++ b/rhodecode/controllers/settings.py @@ -41,6 +41,7 @@ from rhodecode.lib.base import BaseContr from rhodecode.lib.utils import invalidate_cache, action_logger from rhodecode.model.forms import RepoSettingsForm, RepoForkForm from rhodecode.model.repo import RepoModel +from rhodecode.model.db import User log = logging.getLogger(__name__) @@ -62,12 +63,28 @@ class SettingsController(BaseController) category='error') return redirect(url('home')) - defaults = c.repo_info.get_dict() - defaults.update({'user':c.repo_info.user.username}) + c.users_array = repo_model.get_users_js() + c.users_groups_array = repo_model.get_users_groups_js() + defaults = c.repo_info.get_dict() + + #fill owner + if c.repo_info.user: + defaults.update({'user':c.repo_info.user.username}) + else: + replacement_user = self.sa.query(User)\ + .filter(User.admin == True).first().username + defaults.update({'user':replacement_user}) + + #fill repository users for p in c.repo_info.repo_to_perm: - defaults.update({'perm_%s' % p.user.username: + defaults.update({'u_perm_%s' % p.user.username: + p.permission.permission_name}) + + #fill repository groups + for p in c.repo_info.users_group_to_perm: + defaults.update({'g_perm_%s' % p.users_group.users_group_name: p.permission.permission_name}) return htmlfill.render( diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -202,6 +202,7 @@ class Repository(Base, BaseModel): fork = relationship('Repository', remote_side=repo_id) group = relationship('Group') repo_to_perm = relationship('RepoToPerm', cascade='all') + users_group_to_perm = relationship('UsersGroupToPerm', cascade='all') stats = relationship('Statistics', cascade='all', uselist=False) repo_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all') diff --git a/rhodecode/model/forms.py b/rhodecode/model/forms.py --- a/rhodecode/model/forms.py +++ b/rhodecode/model/forms.py @@ -246,24 +246,25 @@ class ValidPerms(formencode.validators.F perms_new = [] #build a list of permission to update and new permission to create for k, v in value.items(): - if k.startswith('perm_'): - if k.startswith('perm_new_member'): - #means new added member to permissions - new_perm = value.get('perm_new_member', False) - new_member = value.get('perm_new_member_name', False) - new_type = value.get('perm_new_member_type') + #means new added member to permissions + if k.startswith('perm_new_member'): + new_perm = value.get('perm_new_member', False) + new_member = value.get('perm_new_member_name', False) + new_type = value.get('perm_new_member_type') - if new_member and new_perm: - if (new_member, new_perm, new_type) not in perms_new: - perms_new.append((new_member, new_perm, new_type)) - else: - usr = k[5:] - t = 'user' - if usr == 'default': - if value['private']: - #set none for default when updating to private repo - v = 'repository.none' - perms_update.append((usr, v, t)) + if new_member and new_perm: + if (new_member, new_perm, new_type) not in perms_new: + perms_new.append((new_member, new_perm, new_type)) + elif k.startswith('u_perm_') or k.startswith('g_perm_'): + member = k[7:] + t = {'u':'user', + 'g':'users_group'}[k[0]] + if member == 'default': + if value['private']: + #set none for default when updating to private repo + v = 'repository.none' + perms_update.append((member, v, t)) + value['perms_updates'] = perms_update value['perms_new'] = perms_new @@ -352,8 +353,10 @@ class AttrLoginValidator(formencode.vali def to_python(self, value, state): if not value or not isinstance(value, (str, unicode)): - raise formencode.Invalid(_("The LDAP Login attribute of the CN must be specified " - "- this is the name of the attribute that is equivalent to 'username'"), + raise formencode.Invalid(_("The LDAP Login attribute of the CN " + "must be specified - this is the name " + "of the attribute that is equivalent " + "to 'username'"), value, state) return value diff --git a/rhodecode/model/repo.py b/rhodecode/model/repo.py --- a/rhodecode/model/repo.py +++ b/rhodecode/model/repo.py @@ -255,6 +255,19 @@ class RepoModel(BaseModel): self.sa.rollback() raise + def delete_perm_users_group(self, form_data, repo_name): + try: + self.sa.query(UsersGroupToPerm)\ + .filter(UsersGroupToPerm.repository \ + == self.get_by_repo_name(repo_name))\ + .filter(UsersGroupToPerm.users_group_id \ + == form_data['users_group_id']).delete() + self.sa.commit() + except: + log.error(traceback.format_exc()) + self.sa.rollback() + raise + def delete_stats(self, repo_name): try: self.sa.query(Statistics)\ diff --git a/rhodecode/templates/admin/repos/repo_edit.html b/rhodecode/templates/admin/repos/repo_edit.html --- a/rhodecode/templates/admin/repos/repo_edit.html +++ b/rhodecode/templates/admin/repos/repo_edit.html @@ -93,76 +93,8 @@
${_('none')} | -${_('read')} | -${_('write')} | -${_('admin')} | -${_('member')} | -- |
- - ${_('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_member','repository.none')} | -${h.radio('perm_new_member','repository.read')} | -${h.radio('perm_new_member','repository.write')} | -${h.radio('perm_new_member','repository.admin')} | -
-
- ${h.text('perm_new_member_name',class_='yui-ac-input')}
- ${h.hidden('perm_new_member_type')}
-
-
- |
- - |
- - ${_('Add another member')} - - | -