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