]> git.openstreetmap.org Git - rails.git/blob - app/abilities/api_ability.rb
Merge remote-tracking branch 'upstream/pull/2450'
[rails.git] / app / abilities / api_ability.rb
1 # frozen_string_literal: true
2
3 class ApiAbility
4   include CanCan::Ability
5
6   def initialize(user)
7     can :show, :capability
8     can :index, :change
9     can :index, :map
10     can :show, :permission
11     can :show, :version
12
13     if Settings.status != "database_offline"
14       can [:show, :download, :query], Changeset
15       can [:index, :create, :comment, :feed, :show, :search], Note
16       can :index, Tracepoint
17       can [:index, :show], User
18       can [:index, :show], Node
19       can [:index, :show, :full, :ways_for_node], Way
20       can [:index, :show, :full, :relations_for_node, :relations_for_way, :relations_for_relation], Relation
21       can [:history, :version], OldNode
22       can [:history, :version], OldWay
23       can [:history, :version], OldRelation
24     end
25
26     if user
27       can :welcome, :site
28       can [:revoke, :authorize], :oauth
29
30       if Settings.status != "database_offline"
31         can [:index, :new, :create, :show, :edit, :update, :destroy], ClientApplication
32         can [:new, :create, :reply, :show, :inbox, :outbox, :mark, :destroy], Message
33         can [:close, :reopen], Note
34         can [:new, :create], Report
35         can [:create, :show, :update, :destroy, :data], Trace
36         can [:details, :gpx_files], User
37         can [:index, :show, :update, :update_all, :destroy], UserPreference
38
39         if user.terms_agreed?
40           can [:create, :update, :upload, :close, :subscribe, :unsubscribe, :expand_bbox], Changeset
41           can :create, ChangesetComment
42           can [:create, :update, :delete], Node
43           can [:create, :update, :delete], Way
44           can [:create, :update, :delete], Relation
45         end
46
47         if user.moderator?
48           can [:destroy, :restore], ChangesetComment
49           can :destroy, Note
50
51           if user.terms_agreed?
52             can :redact, OldNode
53             can :redact, OldWay
54             can :redact, OldRelation
55           end
56         end
57       end
58     end
59
60     # Define abilities for the passed in user here. For example:
61     #
62     #   user ||= User.new # guest user (not logged in)
63     #   if user.admin?
64     #     can :manage, :all
65     #   else
66     #     can :read, :all
67     #   end
68     #
69     # The first argument to `can` is the action you are giving the user
70     # permission to do.
71     # If you pass :manage it will apply to every action. Other common actions
72     # here are :read, :create, :update and :destroy.
73     #
74     # The second argument is the resource the user can perform the action on.
75     # If you pass :all it will apply to every resource. Otherwise pass a Ruby
76     # class of the resource.
77     #
78     # The third argument is an optional hash of conditions to further filter the
79     # objects.
80     # For example, here the user can only update published articles.
81     #
82     #   can :update, Article, :published => true
83     #
84     # See the wiki for details:
85     # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
86   end
87 end