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

Use RESTful routing for users' API key management #3442

Merged

Conversation

kennyadsl
Copy link
Member

@kennyadsl kennyadsl commented Nov 28, 2019

Description

This PR refactors how we are using routes and controller actions to handle users' API key. In order to use RESTful actions, this is moving the non-RESTful endpoints into a separate controller.

This changes the default routing structure in this way:

Operation Rails Url Helper Request
Create a key Before generate_api_key_admin_user_path PUT /admin/users/:id/generate_api_key
After admin_user_api_key_path POST /admin/users/:user_id/api_key
Destroy a key Before clear_api_key_admin_user_path PUT /admin/users/:id/clear_api_key
After admin_user_api_key_path DELETE /admin/users/:user_id/api_key

This has the benefit to have a more organized codebase, but also to improve the granularity of how we can set permissions. For example, now we can have a permission set that does not allow to change or revoke users' API key but allows management of other users things. For this reason, a new ability is required and has been added in the provided UserManagement permission set.

This PR also deprecates the old controller actions, printing a message in the log of users that are still using the old actions.

The controller tests for the old actions have been deprecated as well, and copied over the new controller specs file but it is only checking controller related stuff now, since the real functionality is already covered by unit and feature specs elsewhere.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

@kennyadsl kennyadsl added the changelog:solidus_backend Changes to the solidus_backend gem label Nov 28, 2019
@kennyadsl kennyadsl self-assigned this Nov 28, 2019
This commit refactors how we are using routes to use RESTful
actions, moving the non-RESTful endpoint into a separate
controller.

This has the benefit to have a more organized codebase, but
also to improve the granularity of how we can set permissions.
For example, now we can have a permission set that does not
allow to change or revoke users' API key but allows management
of other users things. For this reason, a new ability is required
and has been added in the provided UserManagement permission set.

This commit also deprecates the old controller actions, printing
a message in the log of users that are still using the old actions.

The controller tests for the old actions have been deprecated as
well, and copied over the new controller specs file but it is
only checking controller related stuff now, since the real
functionality is already covered by unit and feature specs
elsewhere.
@kennyadsl kennyadsl force-pushed the kennyadsl/refactor-api-key-actions branch from 5769d55 to 4153238 Compare November 28, 2019 21:23
Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kennyadsl looks good to me, thank you!

Just one question: do you think it may be worth adding integration specs for this?

end

context "without ability to manage users and API keys" do
stub_authorization! do |_user|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 is there any reason for having the empty block here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's weird but if no block is passed a full authorization will be granted, see the method definition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, thank you for clarifying it to me!

@kennyadsl
Copy link
Member Author

@spaghetticode For the integraton tests question, we already have integration tests for this and I'm satisfied since that they are green without the need to change them anyhow. If you think we should still add more specs, just let me know!

@spaghetticode
Copy link
Member

@kennyadsl I agree those specs are all we need, thank you

Copy link
Contributor

@ericsaupe ericsaupe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@kennyadsl kennyadsl merged commit d42ee9c into solidusio:master Jan 28, 2020
@kennyadsl kennyadsl deleted the kennyadsl/refactor-api-key-actions branch January 28, 2020 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_backend Changes to the solidus_backend gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants