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