Skip to content

[question] Authorization/Queryset filtering #490

Closed

Description

@cocochepeau

First of all, thanks for the amazing work!

By using this: http://docs.graphene-python.org/projects/django/en/latest/authorization/#queryset-filtering-on-lists
How can I achieve the same thing with relay queries. For example with:

class ProjectNode(DjangoObjectType):
    class Meta:
        model = Project
        interfaces = (relay.Node, )


class ProjectFilter(django_filters.FilterSet):
    class Meta:
        model = Project
        fields = [
            'id', 'published',
        ]


class Query(object):
    project = relay.Node.Field(ProjectNode)
    projects = DjangoFilterConnectionField(
        ProjectNode,
        filterset_class=ProjectFilter
    )

    def resolve_projects(self, args, info): # It does not work
        return Project.objects.filter(published=True)

Basically, I want to limit the queryset to only published projects.

Thanks again.

Activity

  1. zbyte64 commented on Oct 3, 2018

    @zbyte64
    Collaborator

    I don't currently see a good way to do this, the querysets are merged during DjangoConnectionField.resolve_connection which grabs the default_queryset from the model's manager. I've had to extend my own DjangoFilterConnectionField to perform authorization checks. #79 purposes that the object nodes support a get_queryset method which would make this allot easier.

  2. cocochepeau commented on Oct 4, 2018

    @cocochepeau
    Author

    Thanks for your answer. I'm still learning Python/Django so thanks again for the explanation. :)
    The idea would be to let us decide directly on the get_queryset method, like in https://docs.djangoproject.com/en/2.1/topics/db/managers/#modifying-a-manager-s-initial-queryset?

    I'll try to follow #79 as well.

  3. stale commented on Jun 11, 2019

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  4. zbyte64 commented on Apr 14, 2021

    @zbyte64
    Collaborator

    You would now define a ProjetNode.get_queryset to filter by user globally.

  5. locked and limited conversation to collaborators on Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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