Example #1
0
 def _can_create_repo_group(self, parent_group_id=None):
     is_admin = HasPermissionAll('hg.admin')('group create controller')
     create_repo_group = HasPermissionAll('hg.repogroup.create.true')(
         'group create controller')
     if is_admin or (create_repo_group and not parent_group_id):
         # we're global admin, or we have global repo group create
         # permission
         # we're ok and we can create TOP level groups
         return True
     elif parent_group_id:
         # we check the permission if we can write to parent group
         group = RepoGroup.get(parent_group_id)
         group_name = group.group_name if group else None
         if HasRepoGroupPermissionAll('group.admin')(
                 group_name, 'check if user is an admin of group'):
             # we're an admin of passed in group, we're ok.
             return True
         else:
             return False
     return False
Example #2
0
    def update(self, group_name):
        """PUT /repos_groups/group_name: Update an existing item"""
        # Forms posted to this method should contain a hidden field:
        #    <input type="hidden" name="_method" value="PUT" />
        # Or using helpers:
        #    h.form(url('repos_group', group_name=GROUP_NAME),
        #           method='put')
        # url('repos_group', group_name=GROUP_NAME)

        c.repos_group = ReposGroupModel()._get_repos_group(group_name)
        if HasPermissionAll('hg.admin')('group edit'):
            #we're global admin, we're ok and we can create TOP level groups
            allow_empty_group = True
        elif not c.repos_group.parent_group:
            allow_empty_group = True
        else:
            allow_empty_group = False
        self.__load_defaults(allow_empty_group=allow_empty_group,
                             exclude_group_ids=[c.repos_group.group_id])

        repos_group_form = ReposGroupForm(
            edit=True,
            old_data=c.repos_group.get_dict(),
            available_groups=c.repo_groups_choices,
            can_create_in_root=allow_empty_group,
        )()
        try:
            form_result = repos_group_form.to_python(dict(request.POST))
            if not c.rhodecode_user.is_admin:
                if self._revoke_perms_on_yourself(form_result):
                    msg = _('Cannot revoke permission for yourself as admin')
                    h.flash(msg, category='warning')
                    raise Exception('revoke admin permission on self')

            new_gr = ReposGroupModel().update(group_name, form_result)
            Session().commit()
            h.flash(_('Updated repository group %s') \
                    % form_result['group_name'], category='success')
            # we now have new name !
            group_name = new_gr.group_name
            #TODO: in future action_logger(, '', '', '', self.sa)
        except formencode.Invalid, errors:

            return htmlfill.render(
                render('admin/repos_groups/repos_groups_edit.html'),
                defaults=errors.value,
                errors=errors.error_dict or {},
                prefix_error=False,
                encoding="UTF-8")
Example #3
0
    def __load_defaults(self, allow_empty_group=False, exclude_group_ids=[]):
        if HasPermissionAll('hg.admin')('group edit'):
            #we're global admin, we're ok and we can create TOP level groups
            allow_empty_group = True

        #override the choices for this form, we need to filter choices
        #and display only those we have ADMIN right
        groups_with_admin_rights = RepoGroupList(RepoGroup.query().all(),
                                                 perm_set=['group.admin'])
        c.repo_groups = RepoGroup.groups_choices(
            groups=groups_with_admin_rights,
            show_empty_group=allow_empty_group)
        # exclude filtered ids
        c.repo_groups = filter(lambda x: x[0] not in exclude_group_ids,
                               c.repo_groups)
        c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
        repo_model = RepoModel()
        c.users_array = repo_model.get_users_js()
        c.users_groups_array = repo_model.get_users_groups_js()
Example #4
0
    def new(self, format='html'):
        """GET /repos_groups/new: Form to create a new item"""
        # url('new_repos_group')
        if HasPermissionAll('hg.admin')('group create'):
            #we're global admin, we're ok and we can create TOP level groups
            pass
        else:
            # we pass in parent group into creation form, thus we know
            # what would be the group, we can check perms here !
            group_id = safe_int(request.GET.get('parent_group'))
            group = RepoGroup.get(group_id) if group_id else None
            group_name = group.group_name if group else None
            if HasReposGroupPermissionAll('group.admin')(group_name,
                                                         'group create'):
                pass
            else:
                return abort(403)

        self.__load_defaults()
        return render('admin/repos_groups/repos_groups_add.html')
Example #5
0
    def edit(self, group_name, format='html'):
        """GET /repos_groups/group_name/edit: Form to edit an existing item"""
        # url('edit_repos_group', group_name=GROUP_NAME)

        c.repos_group = ReposGroupModel()._get_repo_group(group_name)
        #we can only allow moving empty group if it's already a top-level
        #group, ie has no parents, or we're admin
        if HasPermissionAll('hg.admin')('group edit'):
            #we're global admin, we're ok and we can create TOP level groups
            allow_empty_group = True
        elif not c.repos_group.parent_group:
            allow_empty_group = True
        else:
            allow_empty_group = False

        self.__load_defaults(allow_empty_group=allow_empty_group,
                             exclude_group_ids=[c.repos_group.group_id])
        defaults = self.__load_data(c.repos_group.group_id)

        return htmlfill.render(
            render('admin/repos_groups/repos_groups_edit.html'),
            defaults=defaults,
            encoding="UTF-8",
            force_defaults=False)