]> git.openstreetmap.org Git - rails.git/blob - app/models/ability.rb
separate ability and capability
[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, :site
8     can [:permalink, :edit, :help, :fixthemap, :offline, :export, :about, :preview, :copyright, :key, :id, :welcome], :site
9
10     can [:list, :rss, :view, :comments], DiaryEntry
11
12     can [:search, :search_latlon, :search_ca_postcode, :search_osm_nominatim,
13          :search_geonames, :search_osm_nominatim_reverse, :search_geonames_reverse], :geocoder
14
15     if user
16       can :weclome, :site
17
18       can [:create, :edit, :comment, :subscribe, :unsubscribe], DiaryEntry
19
20       if user.administrator?
21         can [:hide, :hidecomment], [DiaryEntry, DiaryComment]
22       end
23     end
24     # Define abilities for the passed in user here. For example:
25     #
26     #   user ||= User.new # guest user (not logged in)
27     #   if user.admin?
28     #     can :manage, :all
29     #   else
30     #     can :read, :all
31     #   end
32     #
33     # The first argument to `can` is the action you are giving the user
34     # permission to do.
35     # If you pass :manage it will apply to every action. Other common actions
36     # here are :read, :create, :update and :destroy.
37     #
38     # The second argument is the resource the user can perform the action on.
39     # If you pass :all it will apply to every resource. Otherwise pass a Ruby
40     # class of the resource.
41     #
42     # The third argument is an optional hash of conditions to further filter the
43     # objects.
44     # For example, here the user can only update published articles.
45     #
46     #   can :update, Article, :published => true
47     #
48     # See the wiki for details:
49     # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
50   end
51 end