]> git.openstreetmap.org Git - rails.git/blob - app/abilities/ability.rb
Merge remote-tracking branch 'upstream/pull/4478'
[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, :query], :browse
9     can [:show, :new], Note
10     can :search, :direction
11     can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :key, :id], :site
12     can [:finish, :embed], :export
13     can [:search, :search_latlon, :search_osm_nominatim, :search_osm_nominatim_reverse], :geocoder
14     can [:token, :request_token, :access_token, :test_request], :oauth
15
16     if Settings.status != "database_offline"
17       can [:index, :feed], Changeset
18       can :index, ChangesetComment
19       can [:confirm, :confirm_resend, :confirm_email], :confirmation
20       can [:index, :rss, :show, :comments], DiaryEntry
21       can [:index], Note
22       can [:new, :create, :edit, :update], :password
23       can [:index, :show], Redaction
24       can [:new, :create, :destroy], :session
25       can [:index, :show, :data, :georss, :picture, :icon], Trace
26       can [:terms, :new, :create, :save, :suspended, :show, :auth_success, :auth_failure], User
27       can [:index, :show, :blocks_on, :blocks_by], UserBlock
28     end
29
30     if user&.active?
31       can :welcome, :site
32       can [:revoke, :authorize], :oauth
33       can [:show], :deletion
34
35       if Settings.status != "database_offline"
36         can [:index, :new, :create, :show, :edit, :update, :destroy], ClientApplication
37         can [:index, :new, :create, :show, :edit, :update, :destroy], :oauth2_application
38         can [:index, :destroy], :oauth2_authorized_application
39         can [:new, :show, :create, :destroy], :oauth2_authorization
40         can [:edit, :update, :destroy], :account
41         can [:show], :dashboard
42         can [:new, :create, :edit, :update, :comment, :subscribe, :unsubscribe], DiaryEntry
43         can [:make_friend, :remove_friend], Friendship
44         can [:new, :create, :reply, :show, :inbox, :outbox, :muted, :mark, :unmute, :destroy], Message
45         can [:close, :reopen], Note
46         can [:show, :edit, :update], :preference
47         can [:edit, :update], :profile
48         can [:new, :create], Report
49         can [:mine, :new, :create, :edit, :update, :destroy], Trace
50         can [:account, :go_public], User
51         can [:index, :create, :destroy], UserMute
52
53         if user.moderator?
54           can [:hide, :unhide, :hidecomment, :unhidecomment], DiaryEntry
55           can [:index, :show, :resolve, :ignore, :reopen], Issue
56           can :create, IssueComment
57           can [:new, :create, :edit, :update, :destroy], Redaction
58           can [:new, :edit, :create, :update, :revoke, :revoke_all], UserBlock
59         end
60
61         if user.administrator?
62           can [:hide, :unhide, :hidecomment, :unhidecomment], DiaryEntry
63           can [:index, :show, :resolve, :ignore, :reopen], Issue
64           can :create, IssueComment
65           can [:set_status, :destroy, :index], User
66           can [:grant, :revoke], UserRole
67         end
68       end
69     end
70
71     # Define abilities for the passed in user here. For example:
72     #
73     #   user ||= User.new # guest user (not logged in)
74     #   if user.admin?
75     #     can :manage, :all
76     #   else
77     #     can :read, :all
78     #   end
79     #
80     # The first argument to `can` is the action you are giving the user
81     # permission to do.
82     # If you pass :manage it will apply to every action. Other common actions
83     # here are :read, :create, :update and :destroy.
84     #
85     # The second argument is the resource the user can perform the action on.
86     # If you pass :all it will apply to every resource. Otherwise pass a Ruby
87     # class of the resource.
88     #
89     # The third argument is an optional hash of conditions to further filter the
90     # objects.
91     # For example, here the user can only update published articles.
92     #
93     #   can :update, Article, :published => true
94     #
95     # See the wiki for details:
96     # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
97   end
98 end