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