Commit 9a5cbdf2 authored by Eugenij's avatar Eugenij

Remove unused functions from PleromaAccountOperation, remove the update_nickname action

parent 8c0b21dd
...@@ -535,19 +535,6 @@ Status: 404 ...@@ -535,19 +535,6 @@ Status: 404
{"error": "Not found"} {"error": "Not found"}
``` ```
## `PATCH /api/pleroma/admin/users/:current_nickname/update_nickname`
### Update nickname for a user with a given nickname
- Note: feature is conditionally enabled, see `:instance, :allow_local_nickname_changing` setting
- Methods: `PATCH`
- Params:
- `nickname`
- Response:
- On failure (feature is disabled): HTTP 403 Forbidden, `{"error": "Nickname change is disabled"}`
- On failure: HTTP 422 Unprocessable Entity, `{"error": "…"}`
- On success: JSON of the user
## `PATCH /api/pleroma/admin/users/by_mfc_id/:mfc_id/update_nickname` ## `PATCH /api/pleroma/admin/users/by_mfc_id/:mfc_id/update_nickname`
### Update nickname for a user with a given mfc_id ### Update nickname for a user with a given mfc_id
......
...@@ -234,19 +234,6 @@ See [Admin-API](admin_api.md) ...@@ -234,19 +234,6 @@ See [Admin-API](admin_api.md)
- PATCH `/api/v1/pleroma/accounts/update_avatar`: Set/clear user avatar image - PATCH `/api/v1/pleroma/accounts/update_avatar`: Set/clear user avatar image
- PATCH `/api/v1/pleroma/accounts/update_banner`: Set/clear user banner image - PATCH `/api/v1/pleroma/accounts/update_banner`: Set/clear user banner image
- PATCH `/api/v1/pleroma/accounts/update_background`: Set/clear user background image - PATCH `/api/v1/pleroma/accounts/update_background`: Set/clear user background image
- PATCH `/api/v1/pleroma/accounts/update_nickname`: Update user nickname
## `/api/v1/pleroma/accounts/update_nickname`
### Update user nickname
* Note: feature is conditionally enabled, see `:instance, :allow_local_nickname_changing` setting
* Method `PATCH`
* Params:
* `nickname` (or, alternatively, `username`): new nickname
* Authentication: required
- Response:
- On failure (feature is disabled): 403 Forbidden, `{"error": "Nickname change is disabled"}`
- On failure: 422 Unprocessable Entity, `{"error": "…"}`
- On success: 200 OK, `{"nickname": updated_nickname}`
## `/api/v1/pleroma/accounts/confirmation_resend` ## `/api/v1/pleroma/accounts/confirmation_resend`
### Resend confirmation email ### Resend confirmation email
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
defmodule Pleroma.Web.ApiSpec.PleromaAccountOperation do defmodule Pleroma.Web.ApiSpec.PleromaAccountOperation do
alias OpenApiSpex.Operation alias OpenApiSpex.Operation
alias OpenApiSpex.Schema
alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
alias Pleroma.Web.ApiSpec.Schemas.ApiError alias Pleroma.Web.ApiSpec.Schemas.ApiError
alias Pleroma.Web.ApiSpec.Schemas.FlakeID alias Pleroma.Web.ApiSpec.Schemas.FlakeID
...@@ -40,26 +39,6 @@ def confirmation_resend_operation do ...@@ -40,26 +39,6 @@ def confirmation_resend_operation do
} }
end end
def update_nickname_operation do
%Operation{
tags: ["Accounts", "MFC"],
summary: "Update user nickname",
operationId: "PleromaAPI.AccountController.update_nickname",
requestBody: request_body("Parameters", update_nickname_request(), required: true),
security: [%{"oAuth" => ["write:accounts"]}],
responses: %{
200 =>
Operation.response("Response", "application/json", %Schema{
type: :object,
properties: %{
nickname: %Schema{type: :string}
}
}),
422 => Operation.response("Bad Request", "application/json", ApiError)
}
}
end
def favourites_operation do def favourites_operation do
%Operation{ %Operation{
tags: ["Accounts"], tags: ["Accounts"],
...@@ -114,15 +93,4 @@ defp id_param do ...@@ -114,15 +93,4 @@ defp id_param do
required: true required: true
) )
end end
defp update_nickname_request do
%Schema{
title: "PleromaAccountUpdateNicknameRequest",
type: :object,
properties: %{
nickname: %Schema{type: :string},
username: %Schema{type: :string}
}
}
end
end end
...@@ -9,8 +9,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do ...@@ -9,8 +9,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
only: [ only: [
json_response: 3, json_response: 3,
add_link_headers: 2, add_link_headers: 2,
assign_account_by_id: 2, assign_account_by_id: 2
handle_update_nickname_error: 2
] ]
alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
...@@ -39,15 +38,6 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do ...@@ -39,15 +38,6 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
%{scopes: ["follow", "write:follows"]} when action in [:subscribe, :unsubscribe] %{scopes: ["follow", "write:follows"]} when action in [:subscribe, :unsubscribe]
) )
plug(
OAuthScopesPlug,
%{scopes: ["write:accounts"]}
# Note: the following actions are not permission-secured in Mastodon:
when action in [
:update_nickname
]
)
plug( plug(
OAuthScopesPlug, OAuthScopesPlug,
%{scopes: ["read:favourites"], fallback: :proceed_unauthenticated} when action == :favourites %{scopes: ["read:favourites"], fallback: :proceed_unauthenticated} when action == :favourites
...@@ -70,17 +60,6 @@ def confirmation_resend(conn, params) do ...@@ -70,17 +60,6 @@ def confirmation_resend(conn, params) do
end end
end end
@doc "PATCH /api/v1/pleroma/accounts/update_nickname"
def update_nickname(%{assigns: %{user: user}, body_params: params} = conn, _) do
nickname = params[:nickname] || params[:username]
with {:ok, _user} <- User.update_nickname(user, nickname) do
json(conn, %{nickname: nickname})
else
result -> handle_update_nickname_error(conn, result)
end
end
@doc "GET /api/v1/pleroma/accounts/:id/favourites" @doc "GET /api/v1/pleroma/accounts/:id/favourites"
def favourites(%{assigns: %{account: %{hide_favorites: true}}} = conn, _params) do def favourites(%{assigns: %{account: %{hide_favorites: true}}} = conn, _params) do
render_error(conn, :forbidden, "Can't get favorites") render_error(conn, :forbidden, "Can't get favorites")
......
...@@ -337,7 +337,6 @@ defmodule Pleroma.Web.Router do ...@@ -337,7 +337,6 @@ defmodule Pleroma.Web.Router do
post("/conversations/read", ConversationController, :mark_as_read) post("/conversations/read", ConversationController, :mark_as_read)
patch("/conversations/:id", ConversationController, :update) patch("/conversations/:id", ConversationController, :update)
patch("/accounts/update_nickname", AccountController, :update_nickname)
put("/statuses/:id/reactions/:emoji", EmojiReactionController, :create) put("/statuses/:id/reactions/:emoji", EmojiReactionController, :create)
delete("/statuses/:id/reactions/:emoji", EmojiReactionController, :delete) delete("/statuses/:id/reactions/:emoji", EmojiReactionController, :delete)
post("/notifications/read", NotificationController, :mark_as_read) post("/notifications/read", NotificationController, :mark_as_read)
......
...@@ -75,6 +75,8 @@ ...@@ -75,6 +75,8 @@
"myhtmlex": {:git, "https://git.pleroma.social/pleroma/myhtmlex.git", "ad0097e2f61d4953bfef20fb6abddf23b87111e6", [ref: "ad0097e2f61d4953bfef20fb6abddf23b87111e6", submodules: true]}, "myhtmlex": {:git, "https://git.pleroma.social/pleroma/myhtmlex.git", "ad0097e2f61d4953bfef20fb6abddf23b87111e6", [ref: "ad0097e2f61d4953bfef20fb6abddf23b87111e6", submodules: true]},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.3", "def21c10a9ed70ce22754fdeea0810dafd53c2db3219a0cd54cf5526377af1c6", [:mix], [], "hexpm", "589b5af56f4afca65217a1f3eb3fee7e79b09c40c742fddc1c312b3ac0b3399f"}, "nimble_parsec": {:hex, :nimble_parsec, "0.5.3", "def21c10a9ed70ce22754fdeea0810dafd53c2db3219a0cd54cf5526377af1c6", [:mix], [], "hexpm", "589b5af56f4afca65217a1f3eb3fee7e79b09c40c742fddc1c312b3ac0b3399f"},
"nodex": {:git, "https://git.pleroma.social/pleroma/nodex", "cb6730f943cfc6aad674c92161be23a8411f15d1", [ref: "cb6730f943cfc6aad674c92161be23a8411f15d1"]}, "nodex": {:git, "https://git.pleroma.social/pleroma/nodex", "cb6730f943cfc6aad674c92161be23a8411f15d1", [ref: "cb6730f943cfc6aad674c92161be23a8411f15d1"]},
"oauth2": {:hex, :oauth2, "2.0.0", "338382079fe16c514420fa218b0903f8ad2d4bfc0ad0c9f988867dfa246731b0", [:mix], [{:hackney, "~> 1.13", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "881b8364ac7385f9fddc7949379cbe3f7081da37233a1aa7aab844670a91e7e7"},
"oauther": {:hex, :oauther, "1.1.1", "7d8b16167bb587ecbcddd3f8792beb9ec3e7b65c1f8ebd86b8dd25318d535752", [:mix], [], "hexpm", "9374f4302045321874cccdc57eb975893643bd69c3b22bf1312dab5f06e5788e"},
"oban": {:hex, :oban, "2.0.0", "e6ce70d94dd46815ec0882a1ffb7356df9a9d5b8a40a64ce5c2536617a447379", [:mix], [{:ecto_sql, ">= 3.4.3", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.14", [hex: :postgrex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cf574813bd048b98a698aa587c21367d2e06842d4e1b1993dcd6a696e9e633bd"}, "oban": {:hex, :oban, "2.0.0", "e6ce70d94dd46815ec0882a1ffb7356df9a9d5b8a40a64ce5c2536617a447379", [:mix], [{:ecto_sql, ">= 3.4.3", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.14", [hex: :postgrex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cf574813bd048b98a698aa587c21367d2e06842d4e1b1993dcd6a696e9e633bd"},
"open_api_spex": {:git, "https://git.pleroma.social/pleroma/elixir-libraries/open_api_spex.git", "f296ac0924ba3cf79c7a588c4c252889df4c2edd", [ref: "f296ac0924ba3cf79c7a588c4c252889df4c2edd"]}, "open_api_spex": {:git, "https://git.pleroma.social/pleroma/elixir-libraries/open_api_spex.git", "f296ac0924ba3cf79c7a588c4c252889df4c2edd", [ref: "f296ac0924ba3cf79c7a588c4c252889df4c2edd"]},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"}, "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
...@@ -112,6 +114,8 @@ ...@@ -112,6 +114,8 @@
"trailing_format_plug": {:hex, :trailing_format_plug, "0.0.7", "64b877f912cf7273bed03379936df39894149e35137ac9509117e59866e10e45", [:mix], [{:plug, "> 0.12.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "bd4fde4c15f3e993a999e019d64347489b91b7a9096af68b2bdadd192afa693f"}, "trailing_format_plug": {:hex, :trailing_format_plug, "0.0.7", "64b877f912cf7273bed03379936df39894149e35137ac9509117e59866e10e45", [:mix], [{:plug, "> 0.12.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "bd4fde4c15f3e993a999e019d64347489b91b7a9096af68b2bdadd192afa693f"},
"tzdata": {:hex, :tzdata, "1.0.3", "73470ad29dde46e350c60a66e6b360d3b99d2d18b74c4c349dbebbc27a09a3eb", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "a6e1ee7003c4d04ecbd21dd3ec690d4c6662db5d3bbdd7262d53cdf5e7c746c1"}, "tzdata": {:hex, :tzdata, "1.0.3", "73470ad29dde46e350c60a66e6b360d3b99d2d18b74c4c349dbebbc27a09a3eb", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "a6e1ee7003c4d04ecbd21dd3ec690d4c6662db5d3bbdd7262d53cdf5e7c746c1"},
"ueberauth": {:hex, :ueberauth, "0.6.2", "25a31111249d60bad8b65438b2306a4dc91f3208faa62f5a8c33e8713989b2e8", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "db9fbfb5ac707bc4f85a297758406340bf0358b4af737a88113c1a9eee120ac7"}, "ueberauth": {:hex, :ueberauth, "0.6.2", "25a31111249d60bad8b65438b2306a4dc91f3208faa62f5a8c33e8713989b2e8", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "db9fbfb5ac707bc4f85a297758406340bf0358b4af737a88113c1a9eee120ac7"},
"ueberauth_facebook": {:hex, :ueberauth_facebook, "0.8.1", "c254be4ab367c276773c2e41d3c0fe343ae118e244afc8d5a4e3e5c438951fdc", [:mix], [{:oauth2, "~> 1.0 or ~> 2.0", [hex: :oauth2, repo: "hexpm", optional: false]}, {:ueberauth, "~> 0.6.0", [hex: :ueberauth, repo: "hexpm", optional: false]}], "hexpm", "c2cf210ef45bd20611234ef17517f9d1dff6b31d3fb6ad96789143eb0943f540"},
"ueberauth_twitter": {:hex, :ueberauth_twitter, "0.4.0", "4b98620341bc91bac90459093bba093c650823b6e2df35b70255c493c17e9227", [:mix], [{:httpoison, "~> 1.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:oauther, "~> 1.1", [hex: :oauther, repo: "hexpm", optional: false]}, {:ueberauth, "~> 0.6", [hex: :ueberauth, repo: "hexpm", optional: false]}], "hexpm", "fb29c9047ca263038c0c61f5a0ec8597e8564aba3f2b4cb02704b60205fd4468"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.5.0", "8516502659002cec19e244ebd90d312183064be95025a319a6c7e89f4bccd65b", [:rebar3], [], "hexpm", "d48d002e15f5cc105a696cf2f1bbb3fc72b4b770a184d8420c8db20da2674b38"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.5.0", "8516502659002cec19e244ebd90d312183064be95025a319a6c7e89f4bccd65b", [:rebar3], [], "hexpm", "d48d002e15f5cc105a696cf2f1bbb3fc72b4b770a184d8420c8db20da2674b38"},
"unsafe": {:hex, :unsafe, "1.0.1", "a27e1874f72ee49312e0a9ec2e0b27924214a05e3ddac90e91727bc76f8613d8", [:mix], [], "hexpm", "6c7729a2d214806450d29766abc2afaa7a2cbecf415be64f36a6691afebb50e5"}, "unsafe": {:hex, :unsafe, "1.0.1", "a27e1874f72ee49312e0a9ec2e0b27924214a05e3ddac90e91727bc76f8613d8", [:mix], [], "hexpm", "6c7729a2d214806450d29766abc2afaa7a2cbecf415be64f36a6691afebb50e5"},
"web_push_encryption": {:hex, :web_push_encryption, "0.2.3", "a0ceab85a805a30852f143d22d71c434046fbdbafbc7292e7887cec500826a80", [:mix], [{:httpoison, "~> 1.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}, {:poison, "~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm", "9315c8f37c108835cf3f8e9157d7a9b8f420a34f402d1b1620a31aed5b93ecdf"}, "web_push_encryption": {:hex, :web_push_encryption, "0.2.3", "a0ceab85a805a30852f143d22d71c434046fbdbafbc7292e7887cec500826a80", [:mix], [{:httpoison, "~> 1.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}, {:poison, "~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm", "9315c8f37c108835cf3f8e9157d7a9b8f420a34f402d1b1620a31aed5b93ecdf"},
......
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule PleromaMfc.Web.PleromaAPI.AccountControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.Config
describe "PATCH /api/v1/pleroma/accounts/update_nickname" do
setup do: oauth_access(["write:accounts"])
setup do: clear_config([:instance, :federating], false)
setup do: clear_config([:instance, :allow_local_nickname_changing], true)
test "local user's nickname can be changed", %{user: user, conn: conn} do
new_nickname = user.nickname <> "a"
conn =
conn
|> put_req_header("content-type", "application/json")
|> patch("/api/v1/pleroma/accounts/update_nickname", %{nickname: new_nickname})
assert json_response_and_validate_schema(conn, 200)
user = refresh_record(user)
assert new_nickname == user.nickname
end
test "renders error json if nickname validation failed, extended nickname format enabled", %{
conn: conn
} do
clear_config([:instance, :extended_nickname_format], true)
conn =
conn
|> put_req_header("content-type", "application/json")
|> patch("/api/v1/pleroma/accounts/update_nickname", %{nickname: "^bad%nickname"})
assert json_response_and_validate_schema(conn, 422) == %{
"error" => "nickname has invalid format"
}
end
test "renders error json if nickname validation failed, extended nickname format disabled", %{
conn: conn
} do
clear_config([:instance, :extended_nickname_format], false)
conn =
conn
|> put_req_header("content-type", "application/json")
|> patch("/api/v1/pleroma/accounts/update_nickname", %{nickname: "^bad%nickname"})
assert json_response_and_validate_schema(conn, 422) == %{
"error" => "nickname has invalid format"
}
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment