本文整理汇总了Python中permissions.Permission.check_permissions方法的典型用法代码示例。如果您正苦于以下问题:Python Permission.check_permissions方法的具体用法?Python Permission.check_permissions怎么用?Python Permission.check_permissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类permissions.Permission
的用法示例。
在下文中一共展示了Permission.check_permissions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dispatch
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def dispatch(self, request, *args, **kwargs):
self.document = get_object_or_404(
Document, pk=self.kwargs['document_pk']
)
self.smart_link = get_object_or_404(
SmartLink, pk=self.kwargs['smart_link_pk']
)
try:
Permission.check_permissions(
request.user, (permission_document_view,)
)
except PermissionDenied:
AccessControlList.objects.check_access(
permission_document_view, request.user, self.document
)
try:
Permission.check_permissions(
request.user, (permission_smart_link_view,)
)
except PermissionDenied:
AccessControlList.objects.check_access(
permission_smart_link_view, request.user, self.smart_link
)
return super(
ResolvedSmartLinkView, self
).dispatch(request, *args, **kwargs)
示例2: has_object_permission
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def has_object_permission(self, request, view, obj):
required_permission = getattr(
view, 'mayan_object_permissions', {}
).get(request.method, None)
if required_permission:
try:
Permission.check_permissions(request.user, required_permission)
except PermissionDenied:
try:
if hasattr(view, 'mayan_permission_attribute_check'):
AccessControlList.objects.check_access(
permissions=required_permission,
user=request.user, obj=obj,
related=view.mayan_permission_attribute_check
)
else:
AccessControlList.objects.check_access(
required_permission, request.user, obj
)
except PermissionDenied:
return False
else:
return True
else:
return True
else:
return True
示例3: template_node_edit
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def template_node_edit(request, node_pk):
node = get_object_or_404(IndexTemplateNode, pk=node_pk)
try:
Permission.check_permissions(
request.user, (permission_document_indexing_edit,)
)
except PermissionDenied:
AccessControlList.objects.check_access(
permission_document_indexing_edit, request.user, node.index
)
if request.method == 'POST':
form = IndexTemplateNodeForm(request.POST, instance=node)
if form.is_valid():
form.save()
messages.success(
request, _('Index template node edited successfully')
)
return HttpResponseRedirect(
reverse('indexing:index_setup_view', args=(node.index.pk,))
)
else:
form = IndexTemplateNodeForm(instance=node)
return render_to_response('appearance/generic_form.html', {
'form': form,
'index': node.index,
'navigation_object_list': ('index', 'node'),
'node': node,
'title': _('Edit index template node: %s') % node,
}, context_instance=RequestContext(request))
示例4: delete
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def delete(self, request, *args, **kwargs):
"""
Checkin a document.
"""
document = self.get_object().document
if document.checkout_info().user == request.user:
try:
Permission.check_permissions(
request.user, (permission_document_checkin,)
)
except PermissionDenied:
AccessControlList.objects.check_access(
permission_document_checkin, request.user, document
)
else:
try:
Permission.check_permissions(
request.user, (permission_document_checkin_override,)
)
except PermissionDenied:
AccessControlList.objects.check_access(
permission_document_checkin_override, request.user,
document
)
return super(
APICheckedoutDocumentView, self
).delete(request, *args, **kwargs)
示例5: get_document_image
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def get_document_image(request, document_id, size=setting_preview_size.value):
document = get_object_or_404(Document.passthrough, pk=document_id)
try:
Permission.check_permissions(request.user, (permission_document_view,))
except PermissionDenied:
AccessControlList.objects.check_access(
permission_document_view, request.user, document
)
page = int(request.GET.get('page', DEFAULT_PAGE_NUMBER))
zoom = int(request.GET.get('zoom', DEFAULT_ZOOM_LEVEL))
version = int(request.GET.get('version', document.latest_version.pk))
if zoom < setting_zoom_min_level.value:
zoom = setting_zoom_min_level.value
if zoom > setting_zoom_max_level.value:
zoom = setting_zoom_max_level.value
rotation = int(request.GET.get('rotation', DEFAULT_ROTATION)) % 360
document_page = document.pages.get(page_number=page)
task = task_get_document_page_image.apply_async(kwargs=dict(document_page_id=document_page.pk, size=size, zoom=zoom, rotation=rotation, as_base64=True, version=version))
data = task.get(timeout=DOCUMENT_IMAGE_TASK_TIMEOUT)
return HttpResponse(base64.b64decode(data[21:]), content_type='image')
示例6: key_delete
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def key_delete(request, fingerprint, key_type):
Permission.check_permissions(request.user, (permission_key_delete,))
secret = key_type == 'sec'
key = Key.get(gpg, fingerprint, secret=secret)
post_action_redirect = redirect('django_gpg:key_public_list')
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))))
next = request.POST.get('next', request.GET.get('next', post_action_redirect if post_action_redirect else request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))))
if request.method == 'POST':
try:
gpg.delete_key(key)
messages.success(request, _('Key: %s, deleted successfully.') % fingerprint)
return HttpResponseRedirect(next)
except Exception as exception:
messages.error(request, exception)
return HttpResponseRedirect(previous)
return render_to_response('appearance/generic_confirm.html', {
'title': _('Delete key'),
'delete_view': True,
'message': _(
'Delete key %s? If you delete a public key that is part of a '
'public/private pair the private key will be deleted as well.'
) % key,
'next': next,
'previous': previous,
}, context_instance=RequestContext(request))
示例7: transform_page
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def transform_page(request, document_page_id, zoom_function=None, rotation_function=None):
document_page = get_object_or_404(DocumentPage, pk=document_page_id)
try:
Permission.check_permissions(request.user, (permission_document_view,))
except PermissionDenied:
AccessControlList.objects.check_access(permission_document_view, request.user, document_page.document)
view = resolve(urlparse.urlparse(request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))).path).view_name
# Get the query string from the referer url
query = urlparse.urlparse(request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))).query
# Parse the query string and get the zoom value
# parse_qs return a dictionary whose values are lists
zoom = int(urlparse.parse_qs(query).get('zoom', ['100'])[0])
rotation = int(urlparse.parse_qs(query).get('rotation', ['0'])[0])
if zoom_function:
zoom = zoom_function(zoom)
if rotation_function:
rotation = rotation_function(rotation)
return HttpResponseRedirect(
'?'.join([
reverse(view, args=(document_page.pk,)),
urlencode({'zoom': zoom, 'rotation': rotation})
])
)
示例8: key_receive
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def key_receive(request, key_id):
Permission.check_permissions(request.user, (permission_key_receive,))
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))))
if request.method == 'POST':
try:
gpg.receive_key(key_id=key_id)
except Exception as exception:
messages.error(
request,
_('Unable to import key: %(key_id)s; %(error)s') %
{
'key_id': key_id,
'error': exception,
}
)
return HttpResponseRedirect(previous)
else:
messages.success(
request,
_('Successfully received key: %(key_id)s') %
{
'key_id': key_id,
}
)
return redirect('django_gpg:key_public_list')
return render_to_response('appearance/generic_confirm.html', {
'message': _('Import key ID: %s?') % key_id,
'previous': previous,
'title': _('Import key'),
}, context_instance=RequestContext(request))
示例9: document_type_filename_create
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def document_type_filename_create(request, document_type_id):
Permission.check_permissions(request.user, (permission_document_type_edit,))
document_type = get_object_or_404(DocumentType, pk=document_type_id)
if request.method == 'POST':
form = DocumentTypeFilenameForm_create(request.POST)
if form.is_valid():
try:
document_type_filename = DocumentTypeFilename(
document_type=document_type,
filename=form.cleaned_data['filename'],
enabled=True
)
document_type_filename.save()
messages.success(request, _('Document type quick label created successfully'))
return HttpResponseRedirect(reverse('documents:document_type_filename_list', args=(document_type_id,)))
except Exception as exception:
messages.error(request, _('Error creating document type quick label; %(error)s') % {
'error': exception})
else:
form = DocumentTypeFilenameForm_create()
return render_to_response('appearance/generic_form.html', {
'document_type': document_type,
'form': form,
'navigation_object_list': ('document_type',),
'title': _('Create quick label for document type: %s') % document_type,
}, context_instance=RequestContext(request))
示例10: document_signature_download
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def document_signature_download(request, document_pk):
document = get_object_or_404(Document, pk=document_pk)
try:
Permission.check_permissions(
request.user, (permission_signature_download,)
)
except PermissionDenied:
AccessControlList.objects.check_access(
permission_signature_download, request.user, document
)
try:
if DocumentVersionSignature.objects.has_detached_signature(document.latest_version):
signature = DocumentVersionSignature.objects.detached_signature(
document.latest_version
)
return serve_file(
request,
signature,
save_as='"%s.sig"' % document.filename,
content_type='application/octet-stream'
)
except Exception as exception:
messages.error(request, exception)
return HttpResponseRedirect(request.META['HTTP_REFERER'])
return HttpResponseRedirect(request.META['HTTP_REFERER'])
示例11: document_version_revert
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def document_version_revert(request, document_version_pk):
document_version = get_object_or_404(DocumentVersion, pk=document_version_pk)
try:
Permission.check_permissions(request.user, (permission_document_version_revert,))
except PermissionDenied:
AccessControlList.objects.check_access(permission_document_version_revert, request.user, document_version.document)
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))))
if request.method == 'POST':
try:
document_version.revert(_user=request.user)
messages.success(request, _('Document version reverted successfully'))
except Exception as exception:
messages.error(request, _('Error reverting document version; %s') % exception)
return HttpResponseRedirect(previous)
return render_to_response('appearance/generic_confirm.html', {
'previous': previous,
'object': document_version.document,
'title': _('Revert to this version?'),
'message': _('All later version after this one will be deleted too.'),
}, context_instance=RequestContext(request))
示例12: get_queryset
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def get_queryset(self):
document_type = get_object_or_404(DocumentType, pk=self.kwargs["document_type_pk"])
try:
Permission.check_permissions(self.request.user, (permission_document_type_view,))
except PermissionDenied:
AccessControlList.objects.check_access(permission_document_type_view, self.request.user, document_type)
return document_type.metadata.filter(required=self.required_metadata)
示例13: dispatch
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def dispatch(self, request, *args, **kwargs):
if self.view_permission:
Permission.check_permissions(
requester=self.request.user,
permissions=(self.view_permission,)
)
return super(
ViewPermissionCheckMixin, self
).dispatch(request, *args, **kwargs)
示例14: document_verify
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def document_verify(request, document_pk):
document = get_object_or_404(Document, pk=document_pk)
try:
Permission.check_permissions(
request.user, (permission_document_verify,)
)
except PermissionDenied:
AccessControlList.objects.check_access(
permission_document_verify, request.user, document
)
document.add_as_recent_document_for_user(request.user)
try:
signature = DocumentVersionSignature.objects.verify_signature(
document.latest_version
)
except AttributeError:
signature_state = SIGNATURE_STATES.get(SIGNATURE_STATE_NONE)
signature = None
else:
signature_state = SIGNATURE_STATES.get(
getattr(signature, 'status', None)
)
paragraphs = [_('Signature status: %s') % signature_state['text']]
try:
if DocumentVersionSignature.objects.has_embedded_signature(document.latest_version):
signature_type = _('Embedded')
else:
signature_type = _('Detached')
except ValueError:
signature_type = _('None')
if signature:
paragraphs.extend(
[
_('Signature ID: %s') % signature.signature_id,
_('Signature type: %s') % signature_type,
_('Key ID: %s') % signature.key_id,
_('Timestamp: %s') % datetime.fromtimestamp(
int(signature.sig_timestamp)
),
_('Signee: %s') % force_escape(getattr(signature, 'username', '')),
]
)
return render_to_response('appearance/generic_template.html', {
'document': document,
'object': document,
'paragraphs': paragraphs,
'title': _('Signature properties for document: %s') % document,
}, context_instance=RequestContext(request))
示例15: object_action
# 需要导入模块: from permissions import Permission [as 别名]
# 或者: from permissions.Permission import check_permissions [as 别名]
def object_action(self, instance):
try:
Permission.check_permissions(
self.request.user, (permission_ocr_document,)
)
except PermissionDenied:
AccessControlList.objects.check_access(
permission_ocr_document, self.request.user, instance
)
instance.submit_for_ocr()