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