]> git.openstreetmap.org Git - rails.git/blob - app/models/ability.rb
897316691328fc8d673ace7001cbda2f73aa3473
[rails.git] / app / models / ability.rb
1 # frozen_string_literal: true
2
3 class Ability
4   include CanCan::Ability
5
6   def initialize(user, token)
7     can :index, :site
8     can [:permalink, :edit, :help, :fixthemap, :offline, :export, :about, :preview, :copyright, :key, :id, :welcome], :site
9
10     if user
11       can :weclome, :site
12     end
13     # Define abilities for the passed in user here. For example:
14     #
15     #   user ||= User.new # guest user (not logged in)
16     #   if user.admin?
17     #     can :manage, :all
18     #   else
19     #     can :read, :all
20     #   end
21     #
22     # The first argument to `can` is the action you are giving the user
23     # permission to do.
24     # If you pass :manage it will apply to every action. Other common actions
25     # here are :read, :create, :update and :destroy.
26     #
27     # The second argument is the resource the user can perform the action on.
28     # If you pass :all it will apply to every resource. Otherwise pass a Ruby
29     # class of the resource.
30     #
31     # The third argument is an optional hash of conditions to further filter the
32     # objects.
33     # For example, here the user can only update published articles.
34     #
35     #   can :update, Article, :published => true
36     #
37     # See the wiki for details:
38     # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
39   end
40
41   def has_capability?(token, cap)
42     token && token.read_attribute(cap)
43   end
44 end