1 # frozen_string_literal: true
4 include CanCan::Ability
7 can :read, [:version, :capability, :permission, :map]
9 if Settings.status != "database_offline"
10 user = User.find(token.resource_owner_id) if token
12 can [:read, :feed, :search], Note
13 can :create, Note unless token
15 can [:read, :download], Changeset
19 can [:read, :full, :ways_for_node], Way
20 can [:read, :full, :relations_for_node, :relations_for_way, :relations_for_relation], Relation
21 can [:history, :read], [OldNode, OldWay, OldRelation]
25 can [:create, :comment, :close, :reopen], Note if scope?(token, :write_notes)
26 can [:create, :destroy], NoteSubscription if scope?(token, :write_notes)
28 can :read, Trace if scope?(token, :read_gpx)
29 can [:create, :update, :destroy], Trace if scope?(token, :write_gpx)
31 can :details, User if scope?(token, :read_prefs)
32 can :gpx_files, User if scope?(token, :read_gpx)
34 can :read, UserPreference if scope?(token, :read_prefs)
35 can [:update, :update_all, :destroy], UserPreference if scope?(token, :write_prefs)
37 can [:inbox, :outbox, :read, :update, :destroy], Message if scope?(token, :consume_messages)
38 can :create, Message if scope?(token, :send_messages)
41 can [:create, :update, :upload, :close, :subscribe, :unsubscribe], Changeset if scope?(token, :write_api)
42 can :create, ChangesetComment if scope?(token, :write_api)
43 can [:create, :update, :delete], [Node, Way, Relation] if scope?(token, :write_api)
47 can [:destroy, :restore], ChangesetComment if scope?(token, :write_api)
49 can :destroy, Note if scope?(token, :write_notes)
51 can :redact, [OldNode, OldWay, OldRelation] if user&.terms_agreed? && scope?(token, :write_redactions)
56 # Define abilities for the passed in user here. For example:
58 # user ||= User.new # guest user (not logged in)
65 # The first argument to `can` is the action you are giving the user
67 # If you pass :manage it will apply to every action. Other common actions
68 # here are :read, :create, :update and :destroy.
70 # The second argument is the resource the user can perform the action on.
71 # If you pass :all it will apply to every resource. Otherwise pass a Ruby
72 # class of the resource.
74 # The third argument is an optional hash of conditions to further filter the
76 # For example, here the user can only update published articles.
78 # can :update, Article, :published => true
80 # See the wiki for details:
81 # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
86 def scope?(token, scope)
87 token&.includes_scope?(scope)