2018-12-23 21:04:54 +01:00
|
|
|
# Pleroma: A lightweight social networking server
|
2018-12-31 16:41:47 +01:00
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 21:04:54 +01:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2017-09-06 19:06:25 +02:00
|
|
|
defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|
|
|
use Pleroma.Web, :controller
|
2019-07-28 22:30:10 +02:00
|
|
|
|
2017-11-19 02:22:07 +01:00
|
|
|
require Logger
|
2017-09-06 19:06:25 +02:00
|
|
|
|
2019-10-06 10:43:49 +02:00
|
|
|
alias Pleroma.Plugs.OAuthScopesPlug
|
2019-09-15 17:22:08 +02:00
|
|
|
@unauthenticated_access %{fallback: :proceed_unauthenticated, scopes: []}
|
|
|
|
|
2019-09-17 21:19:39 +02:00
|
|
|
# Note: :index action handles attempt of unauthenticated access to private instance with redirect
|
2019-09-15 17:22:08 +02:00
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
2019-09-17 21:19:39 +02:00
|
|
|
Map.merge(@unauthenticated_access, %{scopes: ["read"], skip_instance_privacy_check: true})
|
|
|
|
when action == :index
|
2019-09-15 17:22:08 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
|
|
|
%{scopes: ["read"]} when action in [:suggestions, :verify_app_credentials]
|
|
|
|
)
|
|
|
|
|
2019-10-02 19:42:40 +02:00
|
|
|
plug(OAuthScopesPlug, %{scopes: ["write:accounts"]} when action == :put_settings)
|
2019-09-15 17:22:08 +02:00
|
|
|
|
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
2019-10-02 19:42:40 +02:00
|
|
|
%{@unauthenticated_access | scopes: ["read:statuses"]} when action == :get_poll
|
2019-09-15 17:22:08 +02:00
|
|
|
)
|
|
|
|
|
2019-10-02 19:42:40 +02:00
|
|
|
plug(OAuthScopesPlug, %{scopes: ["write:statuses"]} when action == :poll_vote)
|
2019-09-15 17:22:08 +02:00
|
|
|
|
2019-10-02 19:42:40 +02:00
|
|
|
plug(OAuthScopesPlug, %{scopes: ["read:favourites"]} when action == :favourites)
|
2019-09-15 17:22:08 +02:00
|
|
|
|
|
|
|
plug(OAuthScopesPlug, %{scopes: ["write:media"]} when action in [:upload, :update_media])
|
|
|
|
|
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
2019-10-02 19:42:40 +02:00
|
|
|
%{scopes: ["follow", "read:blocks"]} when action == :blocks
|
2019-09-15 17:22:08 +02:00
|
|
|
)
|
|
|
|
|
2019-10-02 19:42:40 +02:00
|
|
|
# To do: POST /api/v1/follows is not present in Mastodon; consider removing the action
|
2019-09-08 14:00:03 +02:00
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
2019-10-02 19:42:40 +02:00
|
|
|
%{scopes: ["follow", "write:follows"]} when action == :follows
|
2019-09-08 14:00:03 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
plug(OAuthScopesPlug, %{scopes: ["follow", "read:mutes"]} when action == :mutes)
|
2019-09-15 17:22:08 +02:00
|
|
|
|
2019-10-02 19:42:40 +02:00
|
|
|
# Note: scope not present in Mastodon: read:bookmarks
|
2019-09-15 17:22:08 +02:00
|
|
|
plug(OAuthScopesPlug, %{scopes: ["read:bookmarks"]} when action == :bookmarks)
|
|
|
|
|
2019-09-17 21:19:39 +02:00
|
|
|
# An extra safety measure for possible actions not guarded by OAuth permissions specification
|
|
|
|
plug(
|
|
|
|
Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
|
|
|
|
when action not in [
|
|
|
|
:create_app,
|
|
|
|
:index,
|
|
|
|
:login,
|
|
|
|
:logout,
|
|
|
|
:password_reset,
|
|
|
|
:masto_instance,
|
|
|
|
:peers,
|
|
|
|
:custom_emojis
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2019-07-16 23:44:50 +02:00
|
|
|
plug(RateLimiter, :password_reset when action == :password_reset)
|
2019-06-11 09:28:39 +02:00
|
|
|
|
2019-02-07 20:14:06 +01:00
|
|
|
@local_mastodon_name "Mastodon-Local"
|
2018-07-14 03:04:37 +02:00
|
|
|
|
2019-08-26 14:16:40 +02:00
|
|
|
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
|
2018-06-03 19:28:11 +02:00
|
|
|
|
2019-09-06 20:50:00 +02:00
|
|
|
# Stubs for unimplemented mastodon api
|
|
|
|
#
|
2017-09-09 19:19:13 +02:00
|
|
|
def empty_array(conn, _) do
|
|
|
|
Logger.debug("Unimplemented, returning an empty array")
|
|
|
|
json(conn, [])
|
|
|
|
end
|
2017-11-10 14:24:39 +01:00
|
|
|
|
2018-03-09 19:56:21 +01:00
|
|
|
def empty_object(conn, _) do
|
|
|
|
Logger.debug("Unimplemented, returning an empty object")
|
|
|
|
json(conn, %{})
|
|
|
|
end
|
2017-09-06 19:06:25 +02:00
|
|
|
end
|