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


Python Request.has_permission方法代码示例

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


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

示例1: _options

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import has_permission [as 别名]
    def _options(self, context: IResource, request: Request) -> dict:
        empty = {}  # tiny performance tweak
        cstruct = deepcopy(options_resource_response_data_dict)

        if request.has_permission('edit_some', context):
            edits = self.content.get_sheets_edit(context, request)
            put_sheets = [(s.meta.isheet.__identifier__, empty) for s in edits]
            if put_sheets:
                put_sheets_dict = dict(put_sheets)
                self._add_metadata_edit_permission_info(put_sheets_dict)
                self._add_workflow_edit_permission_info(put_sheets_dict, edits)
                cstruct['PUT']['request_body']['data'] = put_sheets_dict
            else:
                del cstruct['PUT']
        else:
            del cstruct['PUT']

        if request.has_permission('view', context):
            views = self.content.get_sheets_read(context, request)
            get_sheets = [(s.meta.isheet.__identifier__, empty) for s in views]
            if get_sheets:
                cstruct['GET']['response_body']['data'] = dict(get_sheets)
            else:
                del cstruct['GET']
        else:
            del cstruct['GET']

        is_users = IUsersService.providedBy(context) \
            and request.has_permission('create_user', context)
        # TODO move the is_user specific part the UsersRestView
        if request.has_permission('create', self.context) or is_users:
            addables = self.content.get_resources_meta_addable(context,
                                                               request)
            if addables:
                for resource_meta in addables:
                    iresource = resource_meta.iresource
                    resource_typ = iresource.__identifier__
                    creates = self.content.get_sheets_create(context,
                                                             request,
                                                             iresource)
                    sheet_typs = [s.meta.isheet.__identifier__ for s
                                  in creates]
                    sheets_dict = dict.fromkeys(sheet_typs, empty)
                    post_data = {'content_type': resource_typ,
                                 'data': sheets_dict}
                    cstruct['POST']['request_body'].append(post_data)
            else:
                del cstruct['POST']
        else:
            del cstruct['POST']
        return cstruct
开发者ID:andantic,项目名称:adhocracy3,代码行数:53,代码来源:views.py

示例2: _filter_permission

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import has_permission [as 别名]
 def _filter_permission(metas: [ResourceMetadata],
                        context: object,
                        request: Request,
                        permission_attr: str) -> [ResourceMetadata]:
     for meta in metas:
         permission = getattr(meta, permission_attr)
         if request.has_permission(permission, context):
             yield(meta)
开发者ID:liqd,项目名称:adhocracy3,代码行数:10,代码来源:__init__.py

示例3: _filter_permission

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import has_permission [as 别名]
 def _filter_permission(sheets: list, permission_attr: str, context: object,
                        request: Request=None):
     if request is None:
         return
     sheets_candiates = copy(sheets)
     for sheet in sheets_candiates:
         permission = getattr(sheet.meta, permission_attr)
         if not request.has_permission(permission, context):
             sheets.remove(sheet)
开发者ID:andantic,项目名称:adhocracy3,代码行数:11,代码来源:__init__.py

示例4: can_add_anonymized

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import has_permission [as 别名]
 def can_add_anonymized(self, context: object, request: Request) -> bool:
     """Check if children can be created/added anonymized to `context`."""
     if IItem.providedBy(context):
         # if item was anonymized you can also add versions anonymized
         is_allowed = is_created_anonymized(context)
     else:
         is_allowed = IAllowAddAnonymized.providedBy(context)
     has_permission = request.has_permission(ANONYMIZE_PERMISSION, context)
     return is_allowed and has_permission
开发者ID:liqd,项目名称:adhocracy3,代码行数:11,代码来源:__init__.py

示例5: can_add_resource

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import has_permission [as 别名]
    def can_add_resource(self, request: Request, meta: ResourceMetadata,
                         context: IPool) -> bool:
        """Check that the resource type in `meta` is addable to `context`.

        For the `bplan` process we want anonymous to create proposal items
        and the first non empty version. To make this work we check
        the item create permission instead of the version create permission if
        the first version is empty (without sheet data).
        """
        if self._is_bplan_and_has_no_version_with_sheet_data(meta, context):
            from adhocracy_core.utils import get_iresource
            iresource = get_iresource(context)
            permission = self.resources_meta[iresource].permission_create
        else:
            permission = meta.permission_create
        allowed = request.has_permission(permission, context)
        return allowed
开发者ID:Janaba,项目名称:adhocracy3,代码行数:19,代码来源:__init__.py

示例6: has_permission

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import has_permission [as 别名]
    def has_permission(self, permission, context=None):
        """ Check if the current request has the given permission on the
        current or explicitly passed context.  This is different from
        :meth:`pyramid.request.Request.has_permission`` in that a context other
        than the one bound to the request can be passed.  This allows to
        consider local roles for the check.

        :param permission: name of the permission to check
        :type permission: str

        :param context: context for which the permission is checked.
                        Defaults to the context on which the request invoked.
        :type context: :class:`kotti.resources.Node`

        :result: True if has_permission, False else
        :rtype: bool
        """

        from kotti.security import authz_context

        with authz_context(context, self):
            return BaseRequest.has_permission(self, permission, context)
开发者ID:adamcheasley,项目名称:Kotti,代码行数:24,代码来源:request.py

示例7: can_add_resource

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import has_permission [as 别名]
 def can_add_resource(self, request: Request, meta: ResourceMetadata,
                      context: IPool) -> bool:
     """Check that the resource type in `meta` is addable to `context`."""
     permission = meta.permission_create
     allowed = request.has_permission(permission, context)
     return allowed
开发者ID:liqd,项目名称:adhocracy3,代码行数:8,代码来源:__init__.py

示例8: _is_anonymized_and_has_permission

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import has_permission [as 别名]
def _is_anonymized_and_has_permission(context: object,
                                      request: Request) -> bool:
    is_anonymized = is_created_anonymized(context)
    has_permission = request.has_permission(ANONYMIZE_PERMISSION, context)
    return is_anonymized and has_permission
开发者ID:liqd,项目名称:adhocracy3,代码行数:7,代码来源:__init__.py


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