]> git.openstreetmap.org Git - rails.git/blob - app/abilities/ability.rb
Rename api controller test files
[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 [: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 :index, Tracepoint
26     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
27     can [:index, :show, :blocks_on, :blocks_by], UserBlock
28     can [:index, :show], Node
29     can [:index, :show, :full, :ways_for_node], Way
30     can [:index, :show, :full, :relations_for_node, :relations_for_way, :relations_for_relation], Relation
31     can [:history, :version], OldNode
32     can [:history, :version], OldWay
33     can [:history, :version], OldRelation
34
35     if user
36       can :welcome, :site
37       can [:index, :new, :create, :show, :edit, :update, :destroy], ClientApplication
38       can [:create, :edit, :comment, :subscribe, :unsubscribe], DiaryEntry
39       can [:new, :create, :reply, :show, :inbox, :outbox, :mark, :destroy], Message
40       can [:close, :reopen], Note
41       can [:revoke, :authorize], :oauth
42       can [:new, :create], Report
43       can [:mine, :new, :create, :edit, :update, :delete, :api_create, :api_read, :api_update, :api_delete, :api_data], Trace
44       can [:account, :go_public, :make_friend, :remove_friend, :api_details, :api_gpx_files], User
45       can [:read, :read_one, :update, :update_one, :delete_one], UserPreference
46
47       if user.terms_agreed?
48         can [:create, :update, :upload, :close, :subscribe, :unsubscribe, :expand_bbox], Changeset
49         can :create, ChangesetComment
50         can [:create, :update, :delete], Node
51         can [:create, :update, :delete], Way
52         can [:create, :update, :delete], Relation
53       end
54
55       if user.moderator?
56         can [:destroy, :restore], ChangesetComment
57         can [:index, :show, :resolve, :ignore, :reopen], Issue
58         can :create, IssueComment
59         can :destroy, Note
60         can [:new, :create, :edit, :update, :destroy], Redaction
61         can [:new, :edit, :create, :update, :revoke], UserBlock
62         if user.terms_agreed?
63           can :redact, OldNode
64           can :redact, OldWay
65           can :redact, OldRelation
66         end
67       end
68
69       if user.administrator?
70         can [:hide, :hidecomment], [DiaryEntry, DiaryComment]
71         can [:index, :show, :resolve, :ignore, :reopen], Issue
72         can :create, IssueComment
73         can [:set_status, :delete, :index], User
74         can [:grant, :revoke], UserRole
75       end
76     end
77
78     # Define abilities for the passed in user here. For example:
79     #
80     #   user ||= User.new # guest user (not logged in)
81     #   if user.admin?
82     #     can :manage, :all
83     #   else
84     #     can :read, :all
85     #   end
86     #
87     # The first argument to `can` is the action you are giving the user
88     # permission to do.
89     # If you pass :manage it will apply to every action. Other common actions
90     # here are :read, :create, :update and :destroy.
91     #
92     # The second argument is the resource the user can perform the action on.
93     # If you pass :all it will apply to every resource. Otherwise pass a Ruby
94     # class of the resource.
95     #
96     # The third argument is an optional hash of conditions to further filter the
97     # objects.
98     # For example, here the user can only update published articles.
99     #
100     #   can :update, Article, :published => true
101     #
102     # See the wiki for details:
103     # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
104   end
105 end