Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85828896
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/pleroma/web/mastodon_api/controllers/announcement_controller.ex b/lib/pleroma/web/mastodon_api/controllers/announcement_controller.ex
index c51c38d5e..f3ec78265 100644
--- a/lib/pleroma/web/mastodon_api/controllers/announcement_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/announcement_controller.ex
@@ -1,80 +1,80 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.AnnouncementController do
use Pleroma.Web, :controller
import Pleroma.Web.ControllerHelper,
only: [
json_response: 3
]
alias Pleroma.Announcement
alias Pleroma.Web.Plugs.OAuthScopesPlug
plug(Pleroma.Web.ApiSpec.CastAndValidate)
# MastodonAPI specs do not have oauth requirements for showing
# announcements, but we have "private instance" options. When that
# is set, require read:accounts scope, symmetric to write:accounts
# for `mark_read`.
plug(
OAuthScopesPlug,
%{fallback: :proceed_unauthenticated, scopes: ["read:accounts"]}
when action in [:show, :index]
)
# Same as in MastodonAPI specs
plug(
OAuthScopesPlug,
%{fallback: :proceed_unauthenticated, scopes: ["write:accounts"]}
when action in [:mark_read]
)
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.AnnouncementOperation
@doc "GET /api/v1/announcements"
def index(%{assigns: %{user: user}} = conn, _params) do
render(conn, "index.json", announcements: all_visible(), user: user)
end
def index(conn, _params) do
render(conn, "index.json", announcements: all_visible(), user: nil)
end
defp all_visible do
Announcement.list_all()
end
@doc "POST /api/v1/announcements/:id/dismiss"
def mark_read(%{assigns: %{user: user}} = conn, %{id: id} = _params) do
with announcement when not is_nil(announcement) <- Announcement.get_by_id(id),
{:ok, _} <- Announcement.mark_read_by(announcement, user) do
json_response(conn, :ok, %{})
else
_ ->
{:error, :not_found}
end
end
- @doc "POST /api/v1/announcements/:id"
+ @doc "GET /api/v1/announcements/:id"
def show(%{assigns: %{user: user}} = conn, %{id: id} = _params) do
render_announcement_by_id(conn, id, user)
end
def show(conn, %{id: id} = _params) do
render_announcement_by_id(conn, id)
end
def render_announcement_by_id(conn, id, user \\ nil) do
with announcement when not is_nil(announcement) <- Announcement.get_by_id(id) do
render(conn, "show.json", announcement: announcement, user: user)
else
_ ->
{:error, :not_found}
end
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Oct 31, 12:44 PM (21 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1801416
Default Alt Text
(2 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline