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