Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added message for PermissionRequiredMixin #731

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

Rainshaw
Copy link
Contributor

@Rainshaw Rainshaw commented Mar 1, 2021

As in django.contrib.auth.mixins.PermissionRequiredMixin, there is a message passed to the PermissionDenied exception when permissions check fails.

This PR adds object_permission_denied_message to guardian.mixins.PermissionRequiredMixin and uses it in get_object_permission_denied_message() function.

There is already a PR #720 which trys to add permission_denied_message, the reason I use object_permission_denied_message is that in this way we can use django.contrib.auth.mixins.PermissionRequiredMixin and guardian.mixins.PermissionRequiredMixin at same time, such as

from django.contrib.auth.mixins import PermissionRequiredMixin
from guardian.mixins import PermissionRequiredMixin as ObjectPermissionRequiredMixin
class UpdateView(PermissionRequiredMixin, ObjectPermissionRequiredMixin, UpdateView):
    model = Client
    form_class = ClientForm
    template_name = 'client_update.html'
    permission_required = 'clients.change_client'
    permission_denied_message = 'You do not have the permission to change client'
    object_permission_denied_message = 'You are not the creator of this client, '
                                                                  'so you do not have the right to modify this client!'
    raise_exception = True

in this situation, if user do not have clients.change_client, he will see permission_denied_message.
else if user have clients.change_client, then will check change_client on the object, if false, he will
see object_permission_denied_message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant