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

Add authorization rules #10

Merged
merged 16 commits into from
Feb 3, 2023
Merged

Add authorization rules #10

merged 16 commits into from
Feb 3, 2023

Conversation

laiifuu
Copy link
Owner

@laiifuu laiifuu commented Feb 2, 2023

Hi 👋

For this PR we:

  • Installed CanCanCan in the project.
  • Added a role column to the users table with a migration.
  • If a user is an admin, then they can delete all posts and comments, else, they can delete only their own posts and comments.

Copy link

@youmari youmari left a comment

Choose a reason for hiding this comment

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

Hi @laiifuu @tarikbouari ,

Good job so far!
There are some issues that you still need to work on to go to the next project but you are almost there!

Highlights

✔️ Great commit messages
✔️ PRO PR
✔️ No linter error

Required Changes ♻️

Check the comments under the review.

Optional suggestions

Every comment with the [OPTIONAL] prefix is not crucial enough to stop the approval of this PR. However, I strongly recommend you to take them into account as they can make your code better.

Cheers and Happy coding!👏👏👏

Feel free to leave any questions or comments in the PR thread if something is not 100% clear.
Please, remember to tag me in your question so I can receive the notification.

Please, do not open a new Pull Request for re-reviews. You should use the same Pull Request submitted for the first review, either valid or invalid unless it is requested otherwise.


As described in the Code reviews limits policy you have a limited number of reviews per project (check the exact number in your Dashboard). If you think that the code review was not fair, you can request a second opinion using this form.

Comment on lines 3 to 10

def initialize(user)
can :read, Post, :all
can(%i[create destroy], Post, user:)
can(:destroy, Comment, user:)
can :manage, :all if user.role == 'admin'
end
end
Copy link

@youmari youmari Feb 2, 2023

Choose a reason for hiding this comment

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

  • a user can delete all users' posts if they have the role admin when I add role admin to the user I'm unable to delete all the posts so please make sure to fix that

@@ -31,4 +31,12 @@ def create

redirect_to user_posts_path
end

Copy link

@youmari youmari Feb 2, 2023

Choose a reason for hiding this comment

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

  • it would be better if you add load_and_authorize_resource to the postsController in order to authorize the resource which is the post as required

Copy link

@DeliceLydia DeliceLydia Feb 2, 2023

Choose a reason for hiding this comment

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

Addressed

@@ -8,6 +8,8 @@ class User < ApplicationRecord
has_many :likes, foreign_key: :author_id
has_many :comments, foreign_key: :author_id

ROLES = %i[admin user].freeze

Copy link

@youmari youmari Feb 2, 2023

Choose a reason for hiding this comment

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

  • you should also add a method that checks if the user is admin or not like
def admin?
    user.role == 'admin'
end

Copy link

@DeliceLydia DeliceLydia left a comment

Choose a reason for hiding this comment

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

Hi Team,

Your project is complete! There is nothing else to say other than... it's time to merge it :shipit:

Congratulations! 🎉

Cheers and Happy coding!👏👏👏

Feel free to leave any questions or comments in the PR thread if something is not 100% clear.
Please, remember to tag me in your question so I can receive the notification.


As described in the Code reviews limits policy you have a limited number of reviews per project (check the exact number in your Dashboard). If you think that the code review was not fair, you can request a second opinion using this form.

@laiifuu laiifuu merged commit 93da76a into dev Feb 3, 2023
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.

4 participants