class ApiAbility
include CanCan::Ability
- def initialize(user)
- can :show, :capability
- can :index, :change
- can :index, :map
- can :show, :permission
- can [:search_all, :search_nodes, :search_ways, :search_relations], :search
- can [:trackpoints], :swf
+ def initialize(user, scopes)
+ can :read, [:version, :capability, :permission, :map]
if Settings.status != "database_offline"
- can [:show, :download, :query], Changeset
- can [:index, :create, :comment, :feed, :show, :search], Note
- can :index, Tracepoint
- can [:api_users, :api_read], User
- can [:index, :show], Node
- can [:index, :show, :full, :ways_for_node], Way
- can [:index, :show, :full, :relations_for_node, :relations_for_way, :relations_for_relation], Relation
- can [:history, :version], OldNode
- can [:history, :version], OldWay
- can [:history, :version], OldRelation
- end
+ can [:read, :feed, :search], Note
+ can :create, Note unless user
+
+ can [:read, :download], Changeset
+ can :read, Tracepoint
+ can :read, User
+ can :read, [Node, Way, Relation, OldNode, OldWay, OldRelation]
+ can :read, UserBlock
+
+ if user&.active?
+ can [:create, :comment, :close, :reopen], Note if scopes.include?("write_notes")
+ can [:create, :destroy], NoteSubscription if scopes.include?("write_notes")
+
+ can :read, Trace if scopes.include?("read_gpx")
+ can [:create, :update, :destroy], Trace if scopes.include?("write_gpx")
- if user
- can :welcome, :site
- can [:revoke, :authorize], :oauth
+ can :details, User if scopes.include?("read_prefs")
+ can :read, UserPreference if scopes.include?("read_prefs")
+ can [:update, :update_all, :destroy], UserPreference if scopes.include?("write_prefs")
- if Settings.status != "database_offline"
- can [:index, :new, :create, :show, :edit, :update, :destroy], ClientApplication
- can [:new, :create, :reply, :show, :inbox, :outbox, :mark, :destroy], Message
- can [:close, :reopen], Note
- can [:new, :create], Report
- can [:api_create, :api_read, :api_update, :api_delete, :api_data], Trace
- can [:api_details, :api_gpx_files], User
- can [:read, :read_one, :update, :update_one, :delete_one], UserPreference
+ can [:read, :update, :destroy], Message if scopes.include?("consume_messages")
+ can :create, Message if scopes.include?("send_messages")
+
+ can :read, :active_user_blocks_list if scopes.include?("read_prefs")
if user.terms_agreed?
- can [:create, :update, :upload, :close, :subscribe, :unsubscribe, :expand_bbox], Changeset
- can :create, ChangesetComment
- can [:create, :update, :delete], Node
- can [:create, :update, :delete], Way
- can [:create, :update, :delete], Relation
+ can [:create, :update, :upload, :close, :subscribe, :unsubscribe], Changeset if scopes.include?("write_map")
+ can :create, ChangesetComment if scopes.include?("write_changeset_comments")
+ can [:create, :update, :destroy], [Node, Way, Relation] if scopes.include?("write_map")
end
if user.moderator?
- can [:destroy, :restore], ChangesetComment
- can :destroy, Note
+ can [:destroy, :restore], ChangesetComment if scopes.include?("write_changeset_comments")
+
+ can :destroy, Note if scopes.include?("write_notes")
+
+ can :redact, [OldNode, OldWay, OldRelation] if user.terms_agreed? && scopes.include?("write_redactions")
- if user.terms_agreed?
- can :redact, OldNode
- can :redact, OldWay
- can :redact, OldRelation
- end
+ can :create, UserBlock if scopes.include?("write_blocks")
end
end
end