X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/d112c01a1af65962e061ca43207a7289477562dc..90e787eed845a850eab63a22831c9cfa47f4dd3d:/app/abilities/api_ability.rb diff --git a/app/abilities/api_ability.rb b/app/abilities/api_ability.rb index e20b849d1..ec4de8f8e 100644 --- a/app/abilities/api_ability.rb +++ b/app/abilities/api_ability.rb @@ -3,40 +3,49 @@ class ApiAbility include CanCan::Ability - def initialize(user) - can :show, :capability - can :index, :map - can :show, :permission - can :show, :version + def initialize(user, scopes) + can :read, [:version, :capability, :permission, :map] if Settings.status != "database_offline" - can [:show, :download, :query], Changeset - can [:index, :create, :feed, :show, :search], Note - can :index, Tracepoint - can [:index, :show], 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, :show], [OldNode, OldWay, OldRelation] - can [:show], UserBlock + 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 [:comment, :close, :reopen], Note - can [:create, :show, :update, :destroy, :data], Trace - can [:details, :gpx_files], User - can [:index, :show, :update, :update_all, :destroy], UserPreference + 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") + + 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") + + 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], Changeset - can :create, ChangesetComment - can [:create, :update, :delete], [Node, Way, 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") - can :redact, [OldNode, OldWay, OldRelation] if user.terms_agreed? + can :create, UserBlock if scopes.include?("write_blocks") end end end