v2 Suggestions: dismiss a suggestion
This commit is contained in:
parent
da06e1a17f
commit
aee55b9a8b
|
@ -9,7 +9,8 @@
|
|||
mute: 2,
|
||||
reblog_mute: 3,
|
||||
notification_mute: 4,
|
||||
inverse_subscription: 5
|
||||
inverse_subscription: 5,
|
||||
suggestion_dismiss: 6
|
||||
)
|
||||
|
||||
defenum(Pleroma.FollowingRelationship.State,
|
||||
|
|
|
@ -5,11 +5,13 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.SuggestionController do
|
||||
use Pleroma.Web, :controller
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserRelationship
|
||||
|
||||
require Logger
|
||||
|
||||
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
||||
plug(Pleroma.Web.Plugs.OAuthScopesPlug, %{scopes: ["read"]} when action in [:index, :index2])
|
||||
plug(Pleroma.Web.Plugs.OAuthScopesPlug, %{scopes: ["write"]} when action in [:dismiss])
|
||||
|
||||
def open_api_operation(action) do
|
||||
operation = String.to_existing_atom("#{action}_operation")
|
||||
|
@ -38,6 +40,26 @@ def index2_operation do
|
|||
}
|
||||
end
|
||||
|
||||
def dismiss_operation do
|
||||
%OpenApiSpex.Operation{
|
||||
tags: ["Suggestions"],
|
||||
summary: "Remove a suggestion",
|
||||
operationId: "SuggestionController.dismiss",
|
||||
parameters: [
|
||||
OpenApiSpex.Operation.parameter(
|
||||
:account_id,
|
||||
:path,
|
||||
%OpenApiSpex.Schema{type: :string},
|
||||
"Account to dismiss",
|
||||
required: true
|
||||
)
|
||||
],
|
||||
responses: %{
|
||||
200 => Pleroma.Web.ApiSpec.Helpers.empty_object_response()
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
@doc "GET /api/v1/suggestions"
|
||||
def index(conn, params),
|
||||
do: Pleroma.Web.MastodonAPI.MastodonAPIController.empty_array(conn, params)
|
||||
|
@ -53,4 +75,12 @@ def index2(%{assigns: %{user: user}} = conn, params) do
|
|||
|
||||
render(conn, "index.json", %{users: users, source: :staff, for: user})
|
||||
end
|
||||
|
||||
@doc "DELETE /api/v1/suggestions/:account_id"
|
||||
def dismiss(%{assigns: %{user: source}} = conn, %{account_id: user_id}) do
|
||||
with %User{} = target <- User.get_cached_by_id(user_id),
|
||||
{:ok, _} <- UserRelationship.create(:suggestion_dismiss, source, target) do
|
||||
json(conn, %{})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -539,6 +539,7 @@ defmodule Pleroma.Web.Router do
|
|||
delete("/push/subscription", SubscriptionController, :delete)
|
||||
|
||||
get("/suggestions", SuggestionController, :index)
|
||||
delete("/suggestions/:account_id", SuggestionController, :dismiss)
|
||||
|
||||
get("/timelines/home", TimelineController, :home)
|
||||
get("/timelines/direct", TimelineController, :direct)
|
||||
|
|
|
@ -894,9 +894,7 @@ test "PATCH /api/pleroma/admin/users/suggest", %{admin: admin, conn: conn} do
|
|||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} added suggested users: @#{user1.nickname}, @#{
|
||||
user2.nickname
|
||||
}"
|
||||
"@#{admin.nickname} added suggested users: @#{user1.nickname}, @#{user2.nickname}"
|
||||
end
|
||||
|
||||
test "PATCH /api/pleroma/admin/users/unsuggest", %{admin: admin, conn: conn} do
|
||||
|
@ -920,9 +918,7 @@ test "PATCH /api/pleroma/admin/users/unsuggest", %{admin: admin, conn: conn} do
|
|||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} removed suggested users: @#{user1.nickname}, @#{
|
||||
user2.nickname
|
||||
}"
|
||||
"@#{admin.nickname} removed suggested users: @#{user1.nickname}, @#{user2.nickname}"
|
||||
end
|
||||
|
||||
test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation", %{admin: admin, conn: conn} do
|
||||
|
|
|
@ -4,9 +4,10 @@
|
|||
|
||||
defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
alias Pleroma.UserRelationship
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do: oauth_access(["read"])
|
||||
setup do: oauth_access(["read", "write"])
|
||||
|
||||
test "returns empty result", %{conn: conn} do
|
||||
res =
|
||||
|
@ -27,4 +28,16 @@ test "returns v2 suggestions", %{conn: conn} do
|
|||
|
||||
assert [%{"source" => "staff", "account" => %{"id" => ^user_id}}] = res
|
||||
end
|
||||
|
||||
test "dismiss suggestion", %{conn: conn, user: source} do
|
||||
target = insert(:user, is_suggested: true)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> delete("/api/v1/suggestions/#{target.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert res == %{}
|
||||
assert UserRelationship.exists?(:suggestion_dismiss, source, target)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue