本文整理汇总了Python中pyramid.interfaces.IRequest.has_permission方法的典型用法代码示例。如果您正苦于以下问题:Python IRequest.has_permission方法的具体用法?Python IRequest.has_permission怎么用?Python IRequest.has_permission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.interfaces.IRequest
的用法示例。
在下文中一共展示了IRequest.has_permission方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _options
# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import has_permission [as 别名]
def _options(self, context: IResource, request: IRequest) -> 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']
if not request.has_permission('delete', context):
del cstruct['DELETE']
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