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