当前位置: 首页>>代码示例>>Python>>正文


Python UserModel.has_perm方法代码示例

本文整理汇总了Python中kallithea.model.user.UserModel.has_perm方法的典型用法代码示例。如果您正苦于以下问题:Python UserModel.has_perm方法的具体用法?Python UserModel.has_perm怎么用?Python UserModel.has_perm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kallithea.model.user.UserModel的用法示例。


在下文中一共展示了UserModel.has_perm方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update

# 需要导入模块: from kallithea.model.user import UserModel [as 别名]
# 或者: from kallithea.model.user.UserModel import has_perm [as 别名]
    def update(self, id):
        """PUT /users/id: 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('update_user', id=ID),
        #           method='put')
        # url('user', id=ID)
        c.active = 'profile'
        user_model = UserModel()
        c.user = user_model.get(id)
        c.extern_type = c.user.extern_type
        c.extern_name = c.user.extern_name
        c.perm_user = AuthUser(user_id=id, ip_addr=self.ip_addr)
        _form = UserForm(edit=True, old_data={'user_id': id,
                                              'email': c.user.email})()
        form_result = {}
        try:
            form_result = _form.to_python(dict(request.POST))
            skip_attrs = ['extern_type', 'extern_name']
            #TODO: plugin should define if username can be updated
            if c.extern_type != kallithea.EXTERN_TYPE_INTERNAL:
                # forbid updating username for external accounts
                skip_attrs.append('username')

            user_model.update(id, form_result, skip_attrs=skip_attrs)
            usr = form_result['username']
            action_logger(self.authuser, 'admin_updated_user:%s' % usr,
                          None, self.ip_addr, self.sa)
            h.flash(_('User updated successfully'), category='success')
            Session().commit()
        except formencode.Invalid, errors:
            defaults = errors.value
            e = errors.error_dict or {}
            defaults.update({
                'create_repo_perm': user_model.has_perm(id,
                                                        'hg.create.repository'),
                'fork_repo_perm': user_model.has_perm(id, 'hg.fork.repository'),
                '_method': 'put'
            })
            return htmlfill.render(
                render('admin/users/user_edit.html'),
                defaults=defaults,
                errors=e,
                prefix_error=False,
                encoding="UTF-8",
                force_defaults=False)
开发者ID:zhumengyuan,项目名称:kallithea,代码行数:49,代码来源:users.py

示例2: edit_perms

# 需要导入模块: from kallithea.model.user import UserModel [as 别名]
# 或者: from kallithea.model.user.UserModel import has_perm [as 别名]
    def edit_perms(self, id):
        c.user = self._get_user_or_raise_if_default(id)
        c.active = 'perms'
        c.perm_user = AuthUser(dbuser=c.user)

        umodel = UserModel()
        defaults = c.user.get_dict()
        defaults.update({
            'create_repo_perm': umodel.has_perm(c.user, 'hg.create.repository'),
            'create_user_group_perm': umodel.has_perm(c.user,
                                                      'hg.usergroup.create.true'),
            'fork_repo_perm': umodel.has_perm(c.user, 'hg.fork.repository'),
        })
        return htmlfill.render(
            render('admin/users/user_edit.html'),
            defaults=defaults,
            encoding="UTF-8",
            force_defaults=False)
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:20,代码来源:users.py

示例3: edit_perms

# 需要导入模块: from kallithea.model.user import UserModel [as 别名]
# 或者: from kallithea.model.user.UserModel import has_perm [as 别名]
    def edit_perms(self, id):
        c.user = User.get_or_404(id)
        if c.user.username == User.DEFAULT_USER:
            h.flash(_("You can't edit this user"), category='warning')
            return redirect(url('users'))

        c.active = 'perms'
        c.perm_user = AuthUser(user_id=id, ip_addr=self.ip_addr)

        umodel = UserModel()
        defaults = c.user.get_dict()
        defaults.update({
            'create_repo_perm': umodel.has_perm(c.user, 'hg.create.repository'),
            'create_user_group_perm': umodel.has_perm(c.user,
                                                      'hg.usergroup.create.true'),
            'fork_repo_perm': umodel.has_perm(c.user, 'hg.fork.repository'),
        })
        return htmlfill.render(
            render('admin/users/user_edit.html'),
            defaults=defaults,
            encoding="UTF-8",
            force_defaults=False)
开发者ID:zhumengyuan,项目名称:kallithea,代码行数:24,代码来源:users.py

示例4: update

# 需要导入模块: from kallithea.model.user import UserModel [as 别名]
# 或者: from kallithea.model.user.UserModel import has_perm [as 别名]
    def update(self, id):
        user_model = UserModel()
        user = user_model.get(id)
        _form = UserForm(edit=True, old_data={'user_id': id,
                                              'email': user.email})()
        form_result = {}
        try:
            form_result = _form.to_python(dict(request.POST))
            skip_attrs = ['extern_type', 'extern_name',
                         ] + auth_modules.get_managed_fields(user)

            user_model.update(id, form_result, skip_attrs=skip_attrs)
            usr = form_result['username']
            action_logger(request.authuser, 'admin_updated_user:%s' % usr,
                          None, request.ip_addr)
            h.flash(_('User updated successfully'), category='success')
            Session().commit()
        except formencode.Invalid as errors:
            defaults = errors.value
            e = errors.error_dict or {}
            defaults.update({
                'create_repo_perm': user_model.has_perm(id,
                                                        'hg.create.repository'),
                'fork_repo_perm': user_model.has_perm(id, 'hg.fork.repository'),
            })
            return htmlfill.render(
                self._render_edit_profile(user),
                defaults=defaults,
                errors=e,
                prefix_error=False,
                encoding="UTF-8",
                force_defaults=False)
        except Exception:
            log.error(traceback.format_exc())
            h.flash(_('Error occurred during update of user %s') \
                    % form_result.get('username'), category='error')
        raise HTTPFound(location=url('edit_user', id=id))
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:39,代码来源:users.py


注:本文中的kallithea.model.user.UserModel.has_perm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。