Skip to content

Commit ee0dbe9

Browse files
Minimal cancan implementation
1 parent 9e9ae0e commit ee0dbe9

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
44
ruby '3.2.2'
55

66
gem 'bootsnap', require: false
7+
gem 'cancancan'
78
gem 'graphql'
89
gem 'graphql-client'
910
gem 'http'

Gemfile.lock

+2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ GEM
103103
bootsnap (1.18.3)
104104
msgpack (~> 1.2)
105105
builder (3.2.4)
106+
cancancan (3.5.0)
106107
capybara (3.40.0)
107108
addressable
108109
matrix
@@ -385,6 +386,7 @@ DEPENDENCIES
385386
better_errors
386387
binding_of_caller
387388
bootsnap
389+
cancancan
388390
capybara
389391
climate_control
390392
debug

app/models/ability.rb

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
class Ability
4+
include CanCan::Ability
5+
6+
def initialize(user)
7+
# Define abilities for the user here. For example:
8+
#
9+
# return unless user.present?
10+
# can :read, :all
11+
# return unless user.admin?
12+
# can :manage, :all
13+
#
14+
# The first argument to `can` is the action you are giving the user
15+
# permission to do.
16+
# If you pass :manage it will apply to every action. Other common actions
17+
# here are :read, :create, :update and :destroy.
18+
#
19+
# The second argument is the resource the user can perform the action on.
20+
# If you pass :all it will apply to every resource. Otherwise pass a Ruby
21+
# class of the resource.
22+
#
23+
# The third argument is an optional hash of conditions to further filter the
24+
# objects.
25+
# For example, here the user can only update published articles.
26+
#
27+
# can :update, Article, published: true
28+
#
29+
# See the wiki for details:
30+
# https://github.com/CanCanCommunity/cancancan/blob/develop/docs/define_check_abilities.md
31+
end
32+
end

0 commit comments

Comments
 (0)