]> git.openstreetmap.org Git - rails.git/blob - app/abilities/ability.rb
Use CanCanCan for redaction authorizations
[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], Redaction
12     can [:index, :show, :blocks_on, :blocks_by], UserBlock
13
14     if user
15       can :welcome, :site
16       can [:create, :edit, :comment, :subscribe, :unsubscribe], DiaryEntry
17       can [:new, :create], Report
18       can [:read, :read_one, :update, :update_one, :delete_one], UserPreference
19
20       if user.moderator?
21         can [:index, :show, :resolve, :ignore, :reopen], Issue
22         can :create, IssueComment
23         can [:new, :create, :edit, :update, :destroy], Redaction
24         can [:new, :edit, :create, :update, :revoke], UserBlock
25       end
26
27       if user.administrator?
28         can [:hide, :hidecomment], [DiaryEntry, DiaryComment]
29         can [:index, :show, :resolve, :ignore, :reopen], Issue
30         can :create, IssueComment
31       end
32     end
33
34     # Define abilities for the passed in user here. For example:
35     #
36     #   user ||= User.new # guest user (not logged in)
37     #   if user.admin?
38     #     can :manage, :all
39     #   else
40     #     can :read, :all
41     #   end
42     #
43     # The first argument to `can` is the action you are giving the user
44     # permission to do.
45     # If you pass :manage it will apply to every action. Other common actions
46     # here are :read, :create, :update and :destroy.
47     #
48     # The second argument is the resource the user can perform the action on.
49     # If you pass :all it will apply to every resource. Otherwise pass a Ruby
50     # class of the resource.
51     #
52     # The third argument is an optional hash of conditions to further filter the
53     # objects.
54     # For example, here the user can only update published articles.
55     #
56     #   can :update, Article, :published => true
57     #
58     # See the wiki for details:
59     # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
60   end
61 end