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

refactor: refactors company controller policies and tests to include … #45

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MDelarosa1993
Copy link
Collaborator

…authorization

Type of Change

  • feature ⛲
  • [?] documentation update 📃
  • refactor 🧑‍💻
  • testing 🧪

Description

Refactored our Companies controller to include the Pundit and rollify functionality, Also refactored the company__policy spec to test the authorization our users had for the companies. We added the rollify method in our company model to use the roles.

Motivation and Context

This change was required because, we introduced authorization to our app and our companies controller wasn't set up for that.

Added Test?

  • Yes 🫡
  • All previous tests still pass 🥳

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

def index?
user.present?
end

Copy link
Collaborator

Choose a reason for hiding this comment

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

So you only want to check if a user is present and, if true, allow this action? Check out the admin? and user? methods inherited from application_policy.rb.

Correct me if I'm wrong, but it looks like it is checking the presence of a user and not checking the role of a user.

Furthermore, should an admin also be authorized to take these controller actions? As of now, a user can ONLY be either a :user (by default) or an :admin (by using the set_role(role_name)) method in user.rb)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes - good catch. We have updated the index? to utilize the ApplicationPolicy and allow admin access to the index (not create)

Screenshot 2024-12-12 at 2 57 53 PM

We pushed the change.

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

Successfully merging this pull request may close these issues.

3 participants