Skip to content

Commit

Permalink
fix linters issues - add return unless user.present? to ability.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
IsmaelMastronardi committed Dec 12, 2023
1 parent 6e0b716 commit 01aca05
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ group :test do
gem 'selenium-webdriver'
end

gem 'cancancan'
gem 'devise'
gem 'devise-jwt'
gem 'faker'
gem 'foreman', '~> 0.87.2'
gem 'jsonapi-serializer'
gem 'rack-cors'
gem 'tailwindcss-rails', '~> 2.0'
gem 'cancancan'
33 changes: 5 additions & 28 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,13 @@ class Ability
include CanCan::Ability

def initialize(user)
return unless user.present?
can :read, :all
can :manage, Rental

# Check if the user is an admin, and if so, allow them to manage (do everything with) all Rentals
if user.admin?
can :manage, :all
end
# Define abilities for the user here. For example:
#
# return unless user.present?
# can :read, :all
# return unless user.admin?
# can :manage, :all
#
# The first argument to `can` is the action you are giving the user
# permission to do.
# If you pass :manage it will apply to every action. Other common actions
# here are :read, :create, :update and :destroy.
#
# The second argument is the resource the user can perform the action on.
# If you pass :all it will apply to every resource. Otherwise pass a Ruby
# class of the resource.
#
# The third argument is an optional hash of conditions to further filter the
# objects.
# For example, here the user can only update published articles.
#
# can :update, Article, published: true
#
# See the wiki for details:
# https://github.com/CanCanCommunity/cancancan/blob/develop/docs/define_check_abilities.md
return unless user.admin?

can :manage, :all

end
end

0 comments on commit 01aca05

Please sign in to comment.