]> git.openstreetmap.org Git - rails.git/blob - app/abilities/ability.rb
Merge remote-tracking branch 'upstream/pull/2115'
[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 [:trackpoints, :map, :changes, :capabilities, :permissions], :api
8     can [:relation, :relation_history, :way, :way_history, :node, :node_history,
9          :changeset, :note, :new_note, :query], :browse
10     can [:index, :feed, :read, :download, :query], Changeset
11     can :index, ChangesetComment
12     can :search, :direction
13     can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :preview, :copyright, :key, :id], :site
14     can [:index, :rss, :show, :comments], DiaryEntry
15     can [:finish, :embed], :export
16     can [:search, :search_latlon, :search_ca_postcode, :search_osm_nominatim,
17          :search_geonames, :search_osm_nominatim_reverse, :search_geonames_reverse], :geocoder
18     can [:index, :create, :comment, :feed, :show, :search, :mine], Note
19     can [:index, :show], Redaction
20     can [:search_all, :search_nodes, :search_ways, :search_relations], :search
21     can [:trackpoints], :swf
22     can [:index, :show, :data, :georss, :picture, :icon], Trace
23     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
24     can [:index, :show, :blocks_on, :blocks_by], UserBlock
25     can [:read, :nodes], Node
26     can [:read, :full, :ways, :ways_for_node], Way
27     can [:read, :full, :relations, :relations_for_node, :relations_for_way, :relations_for_relation], Relation
28     can [:history, :version], OldNode
29     can [:history, :version], OldWay
30     can [:history, :version], OldRelation
31
32     if user
33       can :welcome, :site
34       can [:index, :new, :create, :show, :edit, :update, :destroy], ClientApplication
35       can [:create, :edit, :comment, :subscribe, :unsubscribe], DiaryEntry
36       can [:new, :create, :reply, :show, :inbox, :outbox, :mark, :destroy], Message
37       can [:close, :reopen], Note
38       can [:new, :create], Report
39       can [:mine, :new, :create, :edit, :update, :delete, :api_create, :api_read, :api_update, :api_delete, :api_data], Trace
40       can [:account, :go_public, :make_friend, :remove_friend, :api_details, :api_gpx_files], User
41       can [:read, :read_one, :update, :update_one, :delete_one], UserPreference
42
43       if user.terms_agreed? || !REQUIRE_TERMS_AGREED
44         can [:create, :update, :upload, :close, :subscribe, :unsubscribe, :expand_bbox], Changeset
45         can :create, ChangesetComment
46         can [:create, :update, :delete], Node
47         can [:create, :update, :delete], Way
48         can [:create, :update, :delete], Relation
49       end
50
51       if user.moderator?
52         can [:destroy, :restore], ChangesetComment
53         can [:index, :show, :resolve, :ignore, :reopen], Issue
54         can :create, IssueComment
55         can :destroy, Note
56         can [:new, :create, :edit, :update, :destroy], Redaction
57         can [:new, :edit, :create, :update, :revoke], UserBlock
58         if user.terms_agreed? || !REQUIRE_TERMS_AGREED
59           can :redact, OldNode
60           can :redact, OldWay
61           can :redact, OldRelation
62         end
63       end
64
65       if user.administrator?
66         can [:hide, :hidecomment], [DiaryEntry, DiaryComment]
67         can [:index, :show, :resolve, :ignore, :reopen], Issue
68         can :create, IssueComment
69         can [:set_status, :delete, :index], User
70         can [:grant, :revoke], UserRole
71       end
72     end
73
74     # Define abilities for the passed in user here. For example:
75     #
76     #   user ||= User.new # guest user (not logged in)
77     #   if user.admin?
78     #     can :manage, :all
79     #   else
80     #     can :read, :all
81     #   end
82     #
83     # The first argument to `can` is the action you are giving the user
84     # permission to do.
85     # If you pass :manage it will apply to every action. Other common actions
86     # here are :read, :create, :update and :destroy.
87     #
88     # The second argument is the resource the user can perform the action on.
89     # If you pass :all it will apply to every resource. Otherwise pass a Ruby
90     # class of the resource.
91     #
92     # The third argument is an optional hash of conditions to further filter the
93     # objects.
94     # For example, here the user can only update published articles.
95     #
96     #   can :update, Article, :published => true
97     #
98     # See the wiki for details:
99     # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
100   end
101 end