Skip to content

DjangomodelFormMutation Authorization #942

@jgarzautexas

Description

@jgarzautexas

I'm able to use DjangoModelFormMutation but am curious of how to limit mutation access along with query access similar to https://docs.graphene-python.org/projects/django/en/latest/authorization/

Currently I simply have a class inheriting from DjangoModelFormMutation. I want to be able to restrict access to the owners of the Model Objects, and possibly do other filter on based on user for querying.

This is currently how I am handling it and fine to keep doing this if this is the best practice.

   @classmethod
    def mutate_and_get_payload(cls, root, info, **input):
        user = info.context.user

        # TODO add a check to see if user has access
        if not user.is_authenticated:
            raise GraphQLError("Unauthorized")

        return super().mutate_and_get_payload(root, info, **input)

Thanks for the help.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions