]> git.openstreetmap.org Git - rails.git/blob - app/abilities/ability.rb
Merge pull request #7302 from tomhughes/terms-locale
[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 :read, [:feature_query, :layers_pane, :legend_pane, :share_pane, :languages_pane, :webgl_error_pane]
8     can :read, [Node, Way, Relation, OldNode, OldWay, OldRelation]
9     can :read, [RelationMember, OldRelationMember]
10     can [:show, :create], Note
11     can :read, :directions
12     can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :id], :site
13     can [:create, :show], :export
14     can [:create, :read], :search
15     can [:create, :show], :auth_deletion
16
17     if Settings.status != "database_offline"
18       can [:read, :feed], Changeset
19       can :read, ChangesetComment
20       can [:confirm, :confirm_resend, :confirm_email], :confirmation
21       can [:read, :rss], DiaryEntry
22       can :read, DiaryComment
23       can [:index], Note
24       can [:create, :update], :password
25       can :read, Redaction
26       can [:create, :destroy], :session
27       can [:read, :data], Trace unless Settings.traces_disabled
28       can [:read, :create, :suspended, :auth_success, :auth_failure], User
29       can :read, UserBlock
30     end
31
32     if user&.active?
33       can :welcome, :site
34       can :read, [:deletion, :account_terms, :account_pd_declaration, :account_home]
35
36       if Settings.status != "database_offline"
37         can [:read, :create, :destroy], ChangesetSubscription
38         can [:read, :create, :update, :destroy], :oauth2_application
39         can [:read, :destroy], :oauth2_authorized_application
40         can [:read, :create, :destroy], :oauth2_authorization
41         can [:read, :update, :destroy], :account
42         can :update, :account_terms
43         can :create, :account_pd_declaration
44         can :read, :dashboard
45         can :index, :notification
46         can [:read, :update], [:preferences, :profile]
47         can [:create, :subscribe, :unsubscribe], DiaryEntry
48         can [:update, :hide, :unhide], DiaryEntry, :user => user
49         can [:create], DiaryComment
50         can [:show, :create, :destroy], Follow
51         can [:read, :create, :destroy], Message
52         can [:close, :reopen], Note
53         can :create, Report
54         can [:mine, :create, :update, :destroy], Trace unless Settings.traces_disabled
55         can [:account, :go_public], User
56         can [:read, :create, :destroy], UserMute
57
58         if user.moderator?
59           can [:hide, :unhide], [DiaryEntry, DiaryComment]
60           can [:read, :resolve, :ignore, :reopen], Issue
61           can :create, IssueComment
62           can [:create, :update, :destroy], Redaction
63           can [:create, :destroy], UserBlock
64           can :update, UserBlock, :creator => user
65           can :update, UserBlock, :revoker => user
66           can :update, UserBlock, :active? => true
67           can [:read, :create, :destroy], ModerationZone
68           can :update, ModerationZone, :creator => user
69           can :update, ModerationZone, :revoker => user
70           can :update, ModerationZone, :active? => true
71         end
72
73         if user.administrator?
74           can [:hide, :unhide], [DiaryEntry, DiaryComment]
75           can [:read, :resolve, :ignore, :reopen], Issue
76           can :create, IssueComment
77
78           can [:update], :user_status
79           can [:read, :update], :users_list
80           can [:create, :destroy], UserRole
81         end
82       end
83     end
84
85     # Define abilities for the passed in user here. For example:
86     #
87     #   user ||= User.new # guest user (not logged in)
88     #   if user.admin?
89     #     can :manage, :all
90     #   else
91     #     can :read, :all
92     #   end
93     #
94     # The first argument to `can` is the action you are giving the user
95     # permission to do.
96     # If you pass :manage it will apply to every action. Other common actions
97     # here are :read, :create, :update and :destroy.
98     #
99     # The second argument is the resource the user can perform the action on.
100     # If you pass :all it will apply to every resource. Otherwise pass a Ruby
101     # class of the resource.
102     #
103     # The third argument is an optional hash of conditions to further filter the
104     # objects.
105     # For example, here the user can only update published articles.
106     #
107     #   can :update, Article, :published => true
108     #
109     # See the wiki for details:
110     # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
111   end
112 end