Add account aliases
[akkoma] / lib / pleroma / web / api_spec / operations / pleroma_account_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.PleromaAccountOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.Account
9 alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
10 alias Pleroma.Web.ApiSpec.Schemas.ApiError
11 alias Pleroma.Web.ApiSpec.Schemas.FlakeID
12 alias Pleroma.Web.ApiSpec.StatusOperation
13
14 import Pleroma.Web.ApiSpec.Helpers
15
16 def open_api_operation(action) do
17 operation = String.to_existing_atom("#{action}_operation")
18 apply(__MODULE__, operation, [])
19 end
20
21 def confirmation_resend_operation do
22 %Operation{
23 tags: ["Accounts"],
24 summary: "Resend confirmation email. Expects `email` or `nickname`",
25 operationId: "PleromaAPI.AccountController.confirmation_resend",
26 parameters: [
27 Operation.parameter(:email, :query, :string, "Email of that needs to be verified",
28 example: "cofe@cofe.io"
29 ),
30 Operation.parameter(
31 :nickname,
32 :query,
33 :string,
34 "Nickname of user that needs to be verified",
35 example: "cofefe"
36 )
37 ],
38 responses: %{
39 204 => no_content_response()
40 }
41 }
42 end
43
44 def favourites_operation do
45 %Operation{
46 tags: ["Accounts"],
47 summary: "Returns favorites timeline of any user",
48 operationId: "PleromaAPI.AccountController.favourites",
49 parameters: [id_param() | pagination_params()],
50 security: [%{"oAuth" => ["read:favourites"]}],
51 responses: %{
52 200 =>
53 Operation.response(
54 "Array of Statuses",
55 "application/json",
56 StatusOperation.array_of_statuses()
57 ),
58 403 => Operation.response("Forbidden", "application/json", ApiError),
59 404 => Operation.response("Not Found", "application/json", ApiError)
60 }
61 }
62 end
63
64 def subscribe_operation do
65 %Operation{
66 tags: ["Accounts"],
67 summary: "Subscribe to receive notifications for all statuses posted by a user",
68 operationId: "PleromaAPI.AccountController.subscribe",
69 parameters: [id_param()],
70 security: [%{"oAuth" => ["follow", "write:follows"]}],
71 responses: %{
72 200 => Operation.response("Relationship", "application/json", AccountRelationship),
73 404 => Operation.response("Not Found", "application/json", ApiError)
74 }
75 }
76 end
77
78 def unsubscribe_operation do
79 %Operation{
80 tags: ["Accounts"],
81 summary: "Unsubscribe to stop receiving notifications from user statuses",
82 operationId: "PleromaAPI.AccountController.unsubscribe",
83 parameters: [id_param()],
84 security: [%{"oAuth" => ["follow", "write:follows"]}],
85 responses: %{
86 200 => Operation.response("Relationship", "application/json", AccountRelationship),
87 404 => Operation.response("Not Found", "application/json", ApiError)
88 }
89 }
90 end
91
92 def add_aliases_operation do
93 %Operation{
94 tags: ["Accounts"],
95 summary: "Add ActivityPub aliases",
96 operationId: "PleromaAPI.AccountController.add_aliases",
97 requestBody: request_body("Parameters", alias_request(), required: true),
98 security: [%{"oAuth" => ["write:accounts"]}],
99 responses: %{
100 200 => Operation.response("Account", "application/json", Account),
101 403 => Operation.response("Forbidden", "application/json", ApiError)
102 }
103 }
104 end
105
106 def delete_aliases_operation do
107 %Operation{
108 tags: ["Accounts"],
109 summary: "Delete ActivityPub aliases",
110 operationId: "PleromaAPI.AccountController.delete_aliases",
111 requestBody: request_body("Parameters", alias_request(), required: true),
112 security: [%{"oAuth" => ["write:accounts"]}],
113 responses: %{
114 200 => Operation.response("Account", "application/json", Account)
115 }
116 }
117 end
118
119 defp id_param do
120 Operation.parameter(:id, :path, FlakeID, "Account ID",
121 example: "9umDrYheeY451cQnEe",
122 required: true
123 )
124 end
125
126 defp alias_request do
127 %Schema{
128 title: "AccountAliasRequest",
129 description: "POST body for adding/deleting AP aliases",
130 type: :object,
131 properties: %{
132 aliases: %Schema{
133 type: :array,
134 items: %Schema{type: :string}
135 }
136 },
137 example: %{
138 "aliases" => ["https://beepboop.social/users/beep", "https://mushroom.kingdom/users/toad"]
139 }
140 }
141 end
142 end