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