Currently it is not possible to use instances of PermissionClasses, leading to lots of boilerplate.
Usecase: I want to check for specific features, like this:
@strawberry.field(permission_classes=[FeatureRequired(feature_1), FeatureRequired(feature_2)]
This does not work, because permission_classes only takes classes and will be instanciated here.
To "fix" this the Typing must be fixed List[Type[BasePermission]] to something like List[Type[BasePermission] | BasePermission]]
and the code snippet here:
permission_instances = [
permission_class() for permission_class in permission_classes
]
needs some inspection like this:
permission_instances = list()
for permission_class in permission_classes:
if isinstance(permission_class, type):
permission_class = permission_class()
permission_instances.append(permission_instance)
with this changes I also would suggest to refactor the permission_classes
name to permissions
+ deprecating the permission_classes
argument on strawberry.field
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too