X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fmastodon_api%2Fcontrollers%2Fstatus_controller.ex;h=2eff4d9d08c04c9cd9ac8da5aaf2944ed8f75eb9;hb=9ee27fb5ecfec639614640c9ce92c00e701b3d8c;hp=47a5bbd60d51e387e632932136376c5dd5293e33;hpb=3dc7e89c54ea3d2bf7e81d99ac4efac37cd00e6c;p=akkoma diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex index 47a5bbd60..2eff4d9d0 100644 --- a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -21,15 +21,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do alias Pleroma.Web.CommonAPI alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.MastodonAPI.ScheduledActivityView + alias Pleroma.Web.OAuth.Token alias Pleroma.Web.Plugs.OAuthScopesPlug alias Pleroma.Web.Plugs.RateLimiter plug(Pleroma.Web.ApiSpec.CastAndValidate) - plug( - :skip_plug, - Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug when action in [:index, :show] - ) + plug(:skip_public_check when action in [:index, :show]) @unauthenticated_access %{fallback: :proceed_unauthenticated, scopes: []} @@ -132,7 +130,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do # Creates a scheduled status when `scheduled_at` param is present and it's far enough def create( %{ - assigns: %{user: user, token: %{app_id: app_id}}, + assigns: %{user: user}, body_params: %{status: _, scheduled_at: scheduled_at} = params } = conn, _ @@ -140,7 +138,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do when not is_nil(scheduled_at) do params = Map.put(params, :in_reply_to_status_id, params[:in_reply_to_id]) - |> add_application(app_id) + |> put_application(conn) attrs = %{ params: Map.new(params, fn {key, value} -> {to_string(key), value} end), @@ -163,14 +161,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do end # Creates a regular status - def create( - %{assigns: %{user: user, token: %{app_id: app_id}}, body_params: %{status: _} = params} = - conn, - _ - ) do + def create(%{assigns: %{user: user}, body_params: %{status: _} = params} = conn, _) do params = Map.put(params, :in_reply_to_status_id, params[:in_reply_to_id]) - |> add_application(app_id) + |> put_application(conn) with {:ok, activity} <- CommonAPI.post(user, params) do try_render(conn, "show.json", @@ -263,6 +257,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do def pin(%{assigns: %{user: user}} = conn, %{id: ap_id_or_id}) do with {:ok, activity} <- CommonAPI.pin(ap_id_or_id, user) do try_render(conn, "show.json", activity: activity, for: user, as: :activity) + else + {:error, :pinned_statuses_limit_reached} -> + {:error, "You have already pinned the maximum number of statuses"} + + {:error, :ownership_error} -> + {:error, :unprocessable_entity, "Someone else's status cannot be pinned"} + + {:error, :visibility_error} -> + {:error, :unprocessable_entity, "Non-public status cannot be pinned"} + + error -> + error end end @@ -423,7 +429,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do ) end - defp add_application(params, app_id) do - params |> Map.put(:application, Pleroma.Web.OAuth.App.get_app_by_id(app_id)) + defp put_application(params, %{assigns: %{token: %Token{user: %User{} = user} = token}} = _conn) do + if user.disclose_client do + %{client_name: client_name, website: website} = Repo.preload(token, :app).app + Map.put(params, :generator, %{type: "Application", name: client_name, url: website}) + else + Map.put(params, :generator, nil) + end end + + defp put_application(params, _), do: Map.put(params, :generator, nil) end