2020-05-21 04:03:38 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-05-21 04:03:38 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ApiSpec.Admin.StatusOperation do
|
|
|
|
alias OpenApiSpex.Operation
|
|
|
|
alias OpenApiSpex.Schema
|
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.Account
|
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.ApiError
|
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.FlakeID
|
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.Status
|
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
|
|
|
|
|
|
|
|
import Pleroma.Web.ApiSpec.Helpers
|
|
|
|
import Pleroma.Web.ApiSpec.StatusOperation, only: [id_param: 0]
|
|
|
|
|
|
|
|
def open_api_operation(action) do
|
|
|
|
operation = String.to_existing_atom("#{action}_operation")
|
|
|
|
apply(__MODULE__, operation, [])
|
|
|
|
end
|
|
|
|
|
|
|
|
def index_operation do
|
|
|
|
%Operation{
|
2021-02-03 05:38:59 -07:00
|
|
|
tags: ["Status administration"],
|
2020-05-21 04:03:38 -06:00
|
|
|
operationId: "AdminAPI.StatusController.index",
|
2021-02-03 05:38:59 -07:00
|
|
|
summary: "Get all statuses",
|
2021-02-17 10:56:13 -07:00
|
|
|
security: [%{"oAuth" => ["admin:read:statuses"]}],
|
2020-05-21 04:03:38 -06:00
|
|
|
parameters: [
|
|
|
|
Operation.parameter(
|
|
|
|
:godmode,
|
|
|
|
:query,
|
|
|
|
%Schema{type: :boolean, default: false},
|
|
|
|
"Allows to see private statuses"
|
|
|
|
),
|
|
|
|
Operation.parameter(
|
|
|
|
:local_only,
|
|
|
|
:query,
|
|
|
|
%Schema{type: :boolean, default: false},
|
|
|
|
"Excludes remote statuses"
|
|
|
|
),
|
|
|
|
Operation.parameter(
|
|
|
|
:with_reblogs,
|
|
|
|
:query,
|
|
|
|
%Schema{type: :boolean, default: false},
|
|
|
|
"Allows to see reblogs"
|
|
|
|
),
|
|
|
|
Operation.parameter(
|
|
|
|
:page,
|
|
|
|
:query,
|
|
|
|
%Schema{type: :integer, default: 1},
|
|
|
|
"Page"
|
|
|
|
),
|
|
|
|
Operation.parameter(
|
|
|
|
:page_size,
|
|
|
|
:query,
|
|
|
|
%Schema{type: :integer, default: 50},
|
|
|
|
"Number of statuses to return"
|
|
|
|
)
|
2020-07-14 10:31:05 -06:00
|
|
|
| admin_api_params()
|
2020-05-21 04:03:38 -06:00
|
|
|
],
|
|
|
|
responses: %{
|
|
|
|
200 =>
|
|
|
|
Operation.response("Array of statuses", "application/json", %Schema{
|
|
|
|
type: :array,
|
|
|
|
items: status()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_operation do
|
|
|
|
%Operation{
|
2021-02-03 05:38:59 -07:00
|
|
|
tags: ["Status adminitration)"],
|
|
|
|
summary: "Get status",
|
2020-05-21 04:03:38 -06:00
|
|
|
operationId: "AdminAPI.StatusController.show",
|
2020-07-14 10:31:05 -06:00
|
|
|
parameters: [id_param() | admin_api_params()],
|
2021-02-17 10:56:13 -07:00
|
|
|
security: [%{"oAuth" => ["admin:read:statuses"]}],
|
2020-05-21 04:03:38 -06:00
|
|
|
responses: %{
|
2020-06-02 09:07:17 -06:00
|
|
|
200 => Operation.response("Status", "application/json", status()),
|
2020-05-21 04:03:38 -06:00
|
|
|
404 => Operation.response("Not Found", "application/json", ApiError)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_operation do
|
|
|
|
%Operation{
|
2021-02-03 05:38:59 -07:00
|
|
|
tags: ["Status adminitration)"],
|
|
|
|
summary: "Change the scope of a status",
|
2020-05-21 04:03:38 -06:00
|
|
|
operationId: "AdminAPI.StatusController.update",
|
2020-07-14 10:31:05 -06:00
|
|
|
parameters: [id_param() | admin_api_params()],
|
2021-02-17 10:56:13 -07:00
|
|
|
security: [%{"oAuth" => ["admin:write:statuses"]}],
|
2020-05-21 04:03:38 -06:00
|
|
|
requestBody: request_body("Parameters", update_request(), required: true),
|
|
|
|
responses: %{
|
|
|
|
200 => Operation.response("Status", "application/json", Status),
|
|
|
|
400 => Operation.response("Error", "application/json", ApiError)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_operation do
|
|
|
|
%Operation{
|
2021-02-03 05:38:59 -07:00
|
|
|
tags: ["Status adminitration)"],
|
|
|
|
summary: "Delete status",
|
2020-05-21 04:03:38 -06:00
|
|
|
operationId: "AdminAPI.StatusController.delete",
|
2020-07-14 10:31:05 -06:00
|
|
|
parameters: [id_param() | admin_api_params()],
|
2021-02-17 10:56:13 -07:00
|
|
|
security: [%{"oAuth" => ["admin:write:statuses"]}],
|
2020-05-21 04:03:38 -06:00
|
|
|
responses: %{
|
|
|
|
200 => empty_object_response(),
|
|
|
|
404 => Operation.response("Not Found", "application/json", ApiError)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
defp status do
|
|
|
|
%Schema{
|
|
|
|
anyOf: [
|
|
|
|
Status,
|
|
|
|
%Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
account: %Schema{allOf: [Account, admin_account()]}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-06-03 09:10:11 -06:00
|
|
|
def admin_account do
|
2020-05-21 04:03:38 -06:00
|
|
|
%Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
id: FlakeID,
|
|
|
|
avatar: %Schema{type: :string},
|
|
|
|
nickname: %Schema{type: :string},
|
|
|
|
display_name: %Schema{type: :string},
|
2020-10-12 16:42:27 -06:00
|
|
|
is_active: %Schema{type: :boolean},
|
2020-05-21 04:03:38 -06:00
|
|
|
local: %Schema{type: :boolean},
|
|
|
|
roles: %Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
admin: %Schema{type: :boolean},
|
|
|
|
moderator: %Schema{type: :boolean}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
tags: %Schema{type: :string},
|
2020-10-13 13:29:34 -06:00
|
|
|
is_confirmed: %Schema{type: :string}
|
2020-05-21 04:03:38 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
defp update_request do
|
|
|
|
%Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
sensitive: %Schema{
|
|
|
|
type: :boolean,
|
|
|
|
description: "Mark status and attached media as sensitive?"
|
|
|
|
},
|
|
|
|
visibility: VisibilityScope
|
|
|
|
},
|
|
|
|
example: %{
|
|
|
|
"visibility" => "private",
|
|
|
|
"sensitive" => "false"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|