-
Notifications
You must be signed in to change notification settings - Fork 84
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: check validate_organization! on graphql resolve when RequiredOrganization included #1853
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
josemoyab
force-pushed
the
clean-resolvers
branch
2 times, most recently
from
April 8, 2024 11:09
328f3a1
to
1ec2727
Compare
…edOrganization include
josemoyab
force-pushed
the
clean-resolvers
branch
from
April 8, 2024 11:52
1ec2727
to
5d0767f
Compare
josemoyab
changed the title
refactor: check validate_organization! on graphql resolve when RequiredOrganization include
refactor: check validate_organization! on graphql resolve when RequiredOrganization included
Apr 8, 2024
vincent-pochet
approved these changes
Apr 9, 2024
Really good @josemoyab! Thank you very much for this contribution |
julienbourdeau
added a commit
that referenced
this pull request
Apr 29, 2024
## Context Granular permissions are being added to Lago ## Description A first PR added all the permission system foundations to Lago (#1926). A second PR added permissions to all GraphQL mutations (#1941). - As I'm working on adding it to Resolvers, I realized I needed the exact the thing as mutations so I extracted some logic into `CanRequirePermissions` concern. - Not all resolvers were extending our custom BaseResolvers, now they do. - As I was testing my new concern, I added tests to `AuthenticableApiUser` and `RequiredOrganization` concerns When I was editing tests for mutations, I add to edit MANY tests re-testing _"without current user"_ and _"without current organization"_. I believe those tests are redundant and we can now simply tests of the Mutation/Resolver includes the correct concern. The behavior is tested once in the concern. See e48109d for single example. Recently @josemoyab introduced [a great refactor](#1853) of `RequiredOrganization` to avoid calling `validate_organization!` in every `resolve` method. I'm taking this one step further by removing the meta programming and using the `ready?` method to be consistent with other concerns. I'll deal with `AuthenticableCustomerPortalUser` concern separately as this PR is already huge and it doesn't affect my work on RBAC. ### About execution order Each `ready?` method will be executed in order, starting by the last concern added, all the way to the first concern added. ```ruby class CreateThing < BaseMutation include AuthenticableApiUser include RequiredOrganization ... end ``` In the above snippet, we'll call `RequiredOrganization#ready?` first, then `AuthenticableApiUser#ready?`. In this case, you'll never get to the `AuthenticableApiUser` error because `RequiredOrganization#ready?` also checks that the current_user is part of the current_organization. Without a current_user, this check will never pass. **This is the reason why I had to edit all mutation tests in the PR**. Previously, the `AuthenticableApiUser#ready?` would run first, then `resolve` would automatically call `current_organization!`. ### Nota Bene We don't need to add dedicated tests case for current_user and curent_organization in every new mutation or resolver.
drejc
pushed a commit
to fliqa-io/lago-api
that referenced
this pull request
May 15, 2024
…redOrganization is included (getlago#1853)
drejc
pushed a commit
to fliqa-io/lago-api
that referenced
this pull request
May 15, 2024
## Context Granular permissions are being added to Lago ## Description A first PR added all the permission system foundations to Lago (getlago#1926). A second PR added permissions to all GraphQL mutations (getlago#1941). - As I'm working on adding it to Resolvers, I realized I needed the exact the thing as mutations so I extracted some logic into `CanRequirePermissions` concern. - Not all resolvers were extending our custom BaseResolvers, now they do. - As I was testing my new concern, I added tests to `AuthenticableApiUser` and `RequiredOrganization` concerns When I was editing tests for mutations, I add to edit MANY tests re-testing _"without current user"_ and _"without current organization"_. I believe those tests are redundant and we can now simply tests of the Mutation/Resolver includes the correct concern. The behavior is tested once in the concern. See e48109d for single example. Recently @josemoyab introduced [a great refactor](getlago#1853) of `RequiredOrganization` to avoid calling `validate_organization!` in every `resolve` method. I'm taking this one step further by removing the meta programming and using the `ready?` method to be consistent with other concerns. I'll deal with `AuthenticableCustomerPortalUser` concern separately as this PR is already huge and it doesn't affect my work on RBAC. ### About execution order Each `ready?` method will be executed in order, starting by the last concern added, all the way to the first concern added. ```ruby class CreateThing < BaseMutation include AuthenticableApiUser include RequiredOrganization ... end ``` In the above snippet, we'll call `RequiredOrganization#ready?` first, then `AuthenticableApiUser#ready?`. In this case, you'll never get to the `AuthenticableApiUser` error because `RequiredOrganization#ready?` also checks that the current_user is part of the current_organization. Without a current_user, this check will never pass. **This is the reason why I had to edit all mutation tests in the PR**. Previously, the `AuthenticableApiUser#ready?` would run first, then `resolve` would automatically call `current_organization!`. ### Nota Bene We don't need to add dedicated tests case for current_user and curent_organization in every new mutation or resolver.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Following the convention over configuration and DRY (Don't Repeat Yourself) principles of Ruby on Rails design paradigm, this PR implements automatic validation of
validate_organization!
when including theRequiredOrganization
concern on GraphQL query/mutation resolversDescription
validate_organization!
forresolve
whenRequiredOrganization
is included.Mutations::Invites::Revoke
to use a user within the organization.Mutations::Wallets::Update
to include the current organization in the GraphQL mutation.expirationAt
check to prevent false positives when tests run for more than 1 second.