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