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