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