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