]> git.openstreetmap.org Git - rails.git/blob - app/abilities/ability.rb
Preview colour tag value using svg
[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       can [:index, :show], Node
29       can [:index, :show, :full, :ways_for_node], Way
30       can [:index, :show, :full, :relations_for_node, :relations_for_way, :relations_for_relation], Relation
31       can [:history, :version], OldNode
32       can [:history, :version], OldWay
33       can [:history, :version], OldRelation
34     end
35
36     if user&.active?
37       can :welcome, :site
38       can [:revoke, :authorize], :oauth
39       can [:show], :deletion
40
41       if Settings.status != "database_offline"
42         can [:index, :new, :create, :show, :edit, :update, :destroy], ClientApplication
43         can [:index, :new, :create, :show, :edit, :update, :destroy], :oauth2_application
44         can [:index, :destroy], :oauth2_authorized_application
45         can [:new, :show, :create, :destroy], :oauth2_authorization
46         can [:edit, :update, :destroy], :account
47         can [:show], :dashboard
48         can [:new, :create, :edit, :update, :comment, :subscribe, :unsubscribe], DiaryEntry
49         can [:make_friend, :remove_friend], Friendship
50         can [:new, :create, :reply, :show, :inbox, :outbox, :muted, :mark, :unmute, :destroy], Message
51         can [:close, :reopen], Note
52         can [:show, :edit, :update], :preference
53         can [:edit, :update], :profile
54         can [:new, :create], Report
55         can [:mine, :new, :create, :edit, :update, :destroy], Trace
56         can [:account, :go_public], User
57         can [:index, :create, :destroy], UserMute
58
59         if user.moderator?
60           can [:hide, :unhide, :hidecomment, :unhidecomment], DiaryEntry
61           can [:index, :show, :resolve, :ignore, :reopen], Issue
62           can :create, IssueComment
63           can [:new, :create, :edit, :update, :destroy], Redaction
64           can [:new, :edit, :create, :update, :revoke, :revoke_all], UserBlock
65         end
66
67         if user.administrator?
68           can [:hide, :unhide, :hidecomment, :unhidecomment], DiaryEntry
69           can [:index, :show, :resolve, :ignore, :reopen], Issue
70           can :create, IssueComment
71           can [:set_status, :destroy, :index], User
72           can [:grant, :revoke], UserRole
73         end
74       end
75     end
76
77     # Define abilities for the passed in user here. For example:
78     #
79     #   user ||= User.new # guest user (not logged in)
80     #   if user.admin?
81     #     can :manage, :all
82     #   else
83     #     can :read, :all
84     #   end
85     #
86     # The first argument to `can` is the action you are giving the user
87     # permission to do.
88     # If you pass :manage it will apply to every action. Other common actions
89     # here are :read, :create, :update and :destroy.
90     #
91     # The second argument is the resource the user can perform the action on.
92     # If you pass :all it will apply to every resource. Otherwise pass a Ruby
93     # class of the resource.
94     #
95     # The third argument is an optional hash of conditions to further filter the
96     # objects.
97     # For example, here the user can only update published articles.
98     #
99     #   can :update, Article, :published => true
100     #
101     # See the wiki for details:
102     # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
103   end
104 end