]> git.openstreetmap.org Git - rails.git/blob - app/abilities/ability.rb
ea60d496fb7bb914218b14d2c455587820171838
[rails.git] / app / abilities / ability.rb
1 # frozen_string_literal: true
2
3 class Ability
4   include CanCan::Ability
5
6   def initialize(user)
7     can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :preview, :copyright, :key, :id], :site
8     can [:index, :rss, :show, :comments], DiaryEntry
9     can [:search, :search_latlon, :search_ca_postcode, :search_osm_nominatim,
10          :search_geonames, :search_osm_nominatim_reverse, :search_geonames_reverse], :geocoder
11     can [:index, :show, :blocks_on, :blocks_by], UserBlock
12
13     if user
14       can :welcome, :site
15       can [:create, :edit, :comment, :subscribe, :unsubscribe], DiaryEntry
16       can [:new, :create], Report
17       can [:read, :read_one, :update, :update_one, :delete_one], UserPreference
18
19       if user.moderator?
20         can [:index, :show, :resolve, :ignore, :reopen], Issue
21         can :create, IssueComment
22         can [:new, :edit, :create, :update, :revoke], UserBlock
23       end
24
25       if user.administrator?
26         can [:hide, :hidecomment], [DiaryEntry, DiaryComment]
27         can [:index, :show, :resolve, :ignore, :reopen], Issue
28         can :create, IssueComment
29       end
30     end
31
32     # Define abilities for the passed in user here. For example:
33     #
34     #   user ||= User.new # guest user (not logged in)
35     #   if user.admin?
36     #     can :manage, :all
37     #   else
38     #     can :read, :all
39     #   end
40     #
41     # The first argument to `can` is the action you are giving the user
42     # permission to do.
43     # If you pass :manage it will apply to every action. Other common actions
44     # here are :read, :create, :update and :destroy.
45     #
46     # The second argument is the resource the user can perform the action on.
47     # If you pass :all it will apply to every resource. Otherwise pass a Ruby
48     # class of the resource.
49     #
50     # The third argument is an optional hash of conditions to further filter the
51     # objects.
52     # For example, here the user can only update published articles.
53     #
54     #   can :update, Article, :published => true
55     #
56     # See the wiki for details:
57     # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
58   end
59 end