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