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