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

Permissions on types #3735

Open
patrick91 opened this issue Dec 22, 2024 · 1 comment
Open

Permissions on types #3735

patrick91 opened this issue Dec 22, 2024 · 1 comment

Comments

@patrick91
Copy link
Member

I was thinking about having the following two options:

  1. Permissions on types
  2. Default field permissions on types

Not sure if we need both, worth investigating for sure.

Permission on types

Something like this:

import strawberry

@strawberry.type(permission_classes=[AdminOnly, CurrentUser])
class User:
    id: strawberry.ID
    email: str

For this to work we need to hook into the resolvers and make sure we check the permissions of the returned object.

I see some complexity with interfaces and unions.

Also we might need to think about pre/post permissions (permission that run before the resolver and permissions that run after)

Default field permissions on types

This might be easier to implement, and it would look like this:

import strawberry

@strawberry.type(default_field_permission_classes=[AdminOnly, CurrentUser])
class User:
    id: strawberry.ID
    email: str
    name: str = strawberry.field(permission_classes=[])

(I don't like the long name)

This would basically change the permission classes for all the fields of this class, unless they already have a permission classes list set.

For something I'm working on this would be more useful than the first option.

I'm interested in people's opinion, I'd love to know what you think it's better to have :D

@XChikuX
Copy link
Contributor

XChikuX commented Dec 26, 2024

default_permissions should suffice

The rest is intuitive. Nothing other than the fields could have the permisson.

Add in the docs that you can only pass permission classes. Should be clear as day!

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

No branches or pull requests

2 participants