-
-
Notifications
You must be signed in to change notification settings - Fork 553
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
refactor: Permissions using Field Extensions #2570
refactor: Permissions using Field Extensions #2570
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2570 +/- ##
==========================================
+ Coverage 96.59% 96.61% +0.01%
==========================================
Files 482 483 +1
Lines 29988 30161 +173
Branches 3702 3726 +24
==========================================
+ Hits 28967 29140 +173
+ Misses 834 832 -2
- Partials 187 189 +2 |
Thanks for adding the Here's a preview of the changelog: Permissions classes now use a import strawberry
from strawberry.permission import PermissionExtension, BasePermission
class IsAuthorized(BasePermission):
message = "User is not authorized"
error_extensions = {"code": "UNAUTHORIZED"}
def has_permission(self, source, info, **kwargs) -> bool:
return False
@strawberry.type
class Query:
@strawberry.field(extensions=[PermissionExtension(permissions=[IsAuthorized()])])
def name(self) -> str:
return "ABC" The old way of adding permissions using Using the new Silent errorsTo return Custom Error Extensions & classesPermissions will now automatically add pre-defined error extensions to the error, and Customizable Error HandlingTo customize the error handling, the Schema DirectivesPermissions will automatically be added as schema directives to the schema. This Here's the tweet text:
|
This is awesome @erikwrede ! Much better than I could have done. |
for more information, see https://pre-commit.ci
Is there a time frame on this feature? Super excited by having authorization self-documenting on the schema |
@cpsnowden going to /cc @patrick91 on this, IIRC the work on this is done and this is ready for merge |
Co-authored-by: Etty <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left some initial comments :)
for more information, see https://pre-commit.ci
…nto 2168-permission-field-extension
CodSpeed Performance ReportMerging #2570 will not alter performanceComparing Summary
|
@patrick91 Py3.12 tests fail with this:
any idea? 👀 |
Ah yes, this happens once in a while, not sure why, it is fine to retry them 😊 |
@patrick91 @erikwrede Are we ready to merge this? I'm planning to start implementing permissions and I'd prefer to start with the new way. |
@XChikuX sorry for the delay, I didn't find any time to talk this through with patrick the last weeks. Trying to get it done this month. Does that work 4 u? |
I can't, in good conscience ask you to work faster 😁 I appreciate all the work you've put into the PR. Get it out at your time, I was mostly curious why it hasn't been merged. I'll refactor my code later as necessary. |
I'm suddenly getting snake case argument names instead of camel case in the kwargs passed to has_permissions. Is this an intentional change? I don't see it listed on the breaking changes page, but it's breaking some things. I can fix it locally, but it would be useful to know whether the change was intentional or whether it's likely to be reverted in the future. |
Description
blocked by #2168
Closes #244
Closes #2454
Types of Changes
Issues Fixed or Closed by This PR
Checklist