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