Skip to content

Commit

Permalink
Minimal cancan implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-bernhardt committed Mar 7, 2024
1 parent 53603aa commit efb293d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '3.2.2'

gem 'bootsnap', require: false
gem 'cancancan'
gem 'graphql'
gem 'graphql-client'
gem 'http'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ GEM
bootsnap (1.18.3)
msgpack (~> 1.2)
builder (3.2.4)
cancancan (3.5.0)
capybara (3.40.0)
addressable
matrix
Expand Down Expand Up @@ -385,6 +386,7 @@ DEPENDENCIES
better_errors
binding_of_caller
bootsnap
cancancan
capybara
climate_control
debug
Expand Down
32 changes: 32 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

class Ability
include CanCan::Ability

def initialize(user)
# 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
end
end

0 comments on commit efb293d

Please sign in to comment.