]> git.openstreetmap.org Git - rails.git/blob - app/abilities/ability.rb
fa0e30f03b38ac1c7681deb87c67538d2502ae15
[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 [:relation, :relation_history, :way, :way_history, :node, :node_history, :changeset, :note], :browse
8     can :index, ChangesetComment
9     can :search, :direction
10     can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :preview, :copyright, :key, :id], :site
11     can [:index, :rss, :show, :comments], DiaryEntry
12     can [:finish, :embed], :export
13     can [:search, :search_latlon, :search_ca_postcode, :search_osm_nominatim,
14          :search_geonames, :search_osm_nominatim_reverse, :search_geonames_reverse], :geocoder
15     can [:index, :create, :comment, :feed, :show, :search, :mine], Note
16     can [:index, :show], Redaction
17     can [:search_all, :search_nodes, :search_ways, :search_relations], :search
18     can [:terms, :api_users, :login, :logout, :new, :create, :save, :confirm, :confirm_resend, :confirm_email, :lost_password, :reset_password, :show, :api_read, :auth_success, :auth_failure], User
19     can [:index, :show, :blocks_on, :blocks_by], UserBlock
20
21     if user
22       can :welcome, :site
23       can [:create, :edit, :comment, :subscribe, :unsubscribe], DiaryEntry
24       can [:close, :reopen], Note
25       can [:new, :create], Report
26       can [:account, :go_public, :make_friend, :remove_friend, :api_details, :api_gpx_files], User
27       can [:read, :read_one, :update, :update_one, :delete_one], UserPreference
28
29       if user.terms_agreed? || !REQUIRE_TERMS_AGREED # rubocop:disable Style/IfUnlessModifier
30         can :create, ChangesetComment
31       end
32
33       if user.moderator?
34         can [:destroy, :restore], ChangesetComment
35         can [:index, :show, :resolve, :ignore, :reopen], Issue
36         can :create, IssueComment
37         can :destroy, Note
38         can [:new, :create, :edit, :update, :destroy], Redaction
39         can [:new, :edit, :create, :update, :revoke], UserBlock
40       end
41
42       if user.administrator?
43         can [:hide, :hidecomment], [DiaryEntry, DiaryComment]
44         can [:index, :show, :resolve, :ignore, :reopen], Issue
45         can :create, IssueComment
46         can [:set_status, :delete, :index], User
47         can [:grant, :revoke], UserRole
48       end
49     end
50
51     # Define abilities for the passed in user here. For example:
52     #
53     #   user ||= User.new # guest user (not logged in)
54     #   if user.admin?
55     #     can :manage, :all
56     #   else
57     #     can :read, :all
58     #   end
59     #
60     # The first argument to `can` is the action you are giving the user
61     # permission to do.
62     # If you pass :manage it will apply to every action. Other common actions
63     # here are :read, :create, :update and :destroy.
64     #
65     # The second argument is the resource the user can perform the action on.
66     # If you pass :all it will apply to every resource. Otherwise pass a Ruby
67     # class of the resource.
68     #
69     # The third argument is an optional hash of conditions to further filter the
70     # objects.
71     # For example, here the user can only update published articles.
72     #
73     #   can :update, Article, :published => true
74     #
75     # See the wiki for details:
76     # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
77   end
78 end