I want to know permission name that causes forbidden error, get it in forbidden view and return to user. How to do it?
Pyramid version 1.10.4
...
# if user does not have PERMISSIONS.name that causes forbidden error
config.add_view(
SomeView,
attr="some_class_attribute",
permission=PERMISSIONS.name,
renderer="json",
request_method="GET",
route_name=route_name,
)
...
@forbidden_view_config(renderer="json")
def forbidden(request):
permission_name = get_permission_name(request)
return permission_name
HTTPForbidden exception has result
attr with ACLDenied type.
So permission_name = request.exception.result.permission