mute: 2,
reblog_mute: 3,
notification_mute: 4,
- inverse_subscription: 5
+ inverse_subscription: 5,
+ suggestion_dismiss: 6
)
defenum(Pleroma.FollowingRelationship.State,
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")
}
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)
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
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)
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
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
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 =
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