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