aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSean King <seanking2919@protonmail.com>2021-04-15 22:56:21 -0600
committerSean King <seanking2919@protonmail.com>2021-04-15 22:56:21 -0600
commit4f55d5123b9d2110ff803e8e9cd2c0f968bc63fc (patch)
tree5b654659899440e5ea90514a9e74b2bcebe24be1 /lib
parent152cb3074e855b0b20011eeb309d9ea5393821aa (diff)
downloadpleroma-4f55d5123b9d2110ff803e8e9cd2c0f968bc63fc.tar.gz
Remove MastoFE-related backend code and frontend pieces
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/masto_fe_controller.ex65
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/app_controller.ex5
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/auth_controller.ex108
-rw-r--r--lib/pleroma/web/o_auth/o_auth_controller.ex3
-rw-r--r--lib/pleroma/web/router.ex32
-rw-r--r--lib/pleroma/web/templates/masto_fe/index.html.eex35
-rw-r--r--lib/pleroma/web/views/masto_fe_view.ex91
7 files changed, 1 insertions, 338 deletions
diff --git a/lib/pleroma/web/masto_fe_controller.ex b/lib/pleroma/web/masto_fe_controller.ex
deleted file mode 100644
index e788ab37a..000000000
--- a/lib/pleroma/web/masto_fe_controller.ex
+++ /dev/null
@@ -1,65 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.MastoFEController do
- use Pleroma.Web, :controller
-
- alias Pleroma.User
- alias Pleroma.Web.MastodonAPI.AuthController
- alias Pleroma.Web.OAuth.Token
- alias Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
- alias Pleroma.Web.Plugs.OAuthScopesPlug
-
- plug(OAuthScopesPlug, %{scopes: ["write:accounts"]} when action == :put_settings)
-
- # Note: :index action handles attempt of unauthenticated access to private instance with redirect
- plug(:skip_plug, EnsurePublicOrAuthenticatedPlug when action == :index)
-
- plug(
- OAuthScopesPlug,
- %{scopes: ["read"], fallback: :proceed_unauthenticated}
- when action == :index
- )
-
- plug(
- :skip_plug,
- [OAuthScopesPlug, EnsurePublicOrAuthenticatedPlug] when action == :manifest
- )
-
- @doc "GET /web/*path"
- def index(conn, _params) do
- with %{assigns: %{user: %User{} = user, token: %Token{app_id: token_app_id} = token}} <- conn,
- {:ok, %{id: ^token_app_id}} <- AuthController.local_mastofe_app() do
- conn
- |> put_layout(false)
- |> render("index.html",
- token: token.token,
- user: user,
- custom_emojis: Pleroma.Emoji.get_all()
- )
- else
- _ ->
- conn
- |> put_session(:return_to, conn.request_path)
- |> redirect(to: "/web/login")
- end
- end
-
- @doc "GET /web/manifest.json"
- def manifest(conn, _params) do
- render(conn, "manifest.json")
- end
-
- @doc "PUT /api/web/settings: Backend-obscure settings blob for MastoFE, don't parse/reuse elsewhere"
- def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
- with {:ok, _} <- User.mastodon_settings_update(user, settings) do
- json(conn, %{})
- else
- e ->
- conn
- |> put_status(:internal_server_error)
- |> json(%{error: inspect(e)})
- end
- end
-end
diff --git a/lib/pleroma/web/mastodon_api/controllers/app_controller.ex b/lib/pleroma/web/mastodon_api/controllers/app_controller.ex
index dd3b39c77..70edbb085 100644
--- a/lib/pleroma/web/mastodon_api/controllers/app_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/app_controller.ex
@@ -26,9 +26,7 @@ defmodule Pleroma.Web.MastodonAPI.AppController do
)
plug(Pleroma.Web.ApiSpec.CastAndValidate)
-
- @local_mastodon_name "Mastodon-Local"
-
+
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.AppOperation
@doc "POST /api/v1/apps"
@@ -41,7 +39,6 @@ defmodule Pleroma.Web.MastodonAPI.AppController do
|> Map.put(:scopes, scopes)
with cs <- App.register_changeset(%App{}, app_attrs),
- false <- cs.changes[:client_name] == @local_mastodon_name,
{:ok, app} <- Repo.insert(cs) do
render(conn, "show.json", app: app)
end
diff --git a/lib/pleroma/web/mastodon_api/controllers/auth_controller.ex b/lib/pleroma/web/mastodon_api/controllers/auth_controller.ex
deleted file mode 100644
index eb6639fc5..000000000
--- a/lib/pleroma/web/mastodon_api/controllers/auth_controller.ex
+++ /dev/null
@@ -1,108 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.MastodonAPI.AuthController do
- use Pleroma.Web, :controller
-
- import Pleroma.Web.ControllerHelper, only: [json_response: 3]
-
- alias Pleroma.Helpers.AuthHelper
- alias Pleroma.Helpers.UriHelper
- alias Pleroma.User
- alias Pleroma.Web.OAuth.App
- alias Pleroma.Web.OAuth.Authorization
- alias Pleroma.Web.OAuth.Token
- alias Pleroma.Web.OAuth.Token.Strategy.Revoke, as: RevokeToken
- alias Pleroma.Web.TwitterAPI.TwitterAPI
-
- action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
-
- plug(Pleroma.Web.Plugs.RateLimiter, [name: :password_reset] when action == :password_reset)
-
- @local_mastodon_name "Mastodon-Local"
-
- @doc "GET /web/login"
- # Local Mastodon FE login callback action
- def login(conn, %{"code" => auth_token} = params) do
- with {:ok, app} <- local_mastofe_app(),
- {:ok, auth} <- Authorization.get_by_token(app, auth_token),
- {:ok, oauth_token} <- Token.exchange_token(app, auth) do
- redirect_to =
- conn
- |> local_mastodon_post_login_path()
- |> UriHelper.modify_uri_params(%{"access_token" => oauth_token.token})
-
- conn
- |> AuthHelper.put_session_token(oauth_token.token)
- |> redirect(to: redirect_to)
- else
- _ -> redirect_to_oauth_form(conn, params)
- end
- end
-
- def login(conn, params) do
- with %{assigns: %{user: %User{}, token: %Token{app_id: app_id}}} <- conn,
- {:ok, %{id: ^app_id}} <- local_mastofe_app() do
- redirect(conn, to: local_mastodon_post_login_path(conn))
- else
- _ -> redirect_to_oauth_form(conn, params)
- end
- end
-
- defp redirect_to_oauth_form(conn, _params) do
- with {:ok, app} <- local_mastofe_app() do
- path =
- o_auth_path(conn, :authorize,
- response_type: "code",
- client_id: app.client_id,
- redirect_uri: ".",
- scope: Enum.join(app.scopes, " ")
- )
-
- redirect(conn, to: path)
- end
- end
-
- @doc "DELETE /auth/sign_out"
- def logout(conn, _) do
- conn =
- with %{assigns: %{token: %Token{} = oauth_token}} <- conn,
- session_token = AuthHelper.get_session_token(conn),
- {:ok, %Token{token: ^session_token}} <- RevokeToken.revoke(oauth_token) do
- AuthHelper.delete_session_token(conn)
- else
- _ -> conn
- end
-
- redirect(conn, to: "/")
- end
-
- @doc "POST /auth/password"
- def password_reset(conn, params) do
- nickname_or_email = params["email"] || params["nickname"]
-
- TwitterAPI.password_reset(nickname_or_email)
-
- json_response(conn, :no_content, "")
- end
-
- defp local_mastodon_post_login_path(conn) do
- case get_session(conn, :return_to) do
- nil ->
- masto_fe_path(conn, :index, ["getting-started"])
-
- return_to ->
- delete_session(conn, :return_to)
- return_to
- end
- end
-
- @spec local_mastofe_app() :: {:ok, App.t()} | {:error, Ecto.Changeset.t()}
- def local_mastofe_app do
- App.get_or_make(
- %{client_name: @local_mastodon_name, redirect_uris: "."},
- ["read", "write", "follow", "push", "admin"]
- )
- end
-end
diff --git a/lib/pleroma/web/o_auth/o_auth_controller.ex b/lib/pleroma/web/o_auth/o_auth_controller.ex
index 215d97b3a..ae040c6eb 100644
--- a/lib/pleroma/web/o_auth/o_auth_controller.ex
+++ b/lib/pleroma/web/o_auth/o_auth_controller.ex
@@ -600,9 +600,6 @@ defmodule Pleroma.Web.OAuth.OAuthController do
end
end
- # Special case: Local MastodonFE
- defp redirect_uri(%Plug.Conn{} = conn, "."), do: auth_url(conn, :login)
-
defp redirect_uri(%Plug.Conn{}, redirect_uri), do: redirect_uri
defp get_session_registration_id(%Plug.Conn{} = conn), do: get_session(conn, :registration_id)
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index de0bd27d7..936053ee2 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -100,12 +100,6 @@ defmodule Pleroma.Web.Router do
plug(Pleroma.Web.Plugs.IdempotencyPlug)
end
- pipeline :mastodon_html do
- plug(:browser)
- plug(:authenticate)
- plug(:after_auth)
- end
-
pipeline :pleroma_html do
plug(:browser)
plug(:authenticate)
@@ -538,13 +532,6 @@ defmodule Pleroma.Web.Router do
get("/timelines/list/:list_id", TimelineController, :list)
end
- scope "/api/web", Pleroma.Web do
- pipe_through(:authenticated_api)
-
- # Backend-obscure settings blob for MastoFE, don't parse/reuse elsewhere
- put("/settings", MastoFEController, :put_settings)
- end
-
scope "/api/v1", Pleroma.Web.MastodonAPI do
pipe_through(:app_api)
@@ -745,25 +732,6 @@ defmodule Pleroma.Web.Router do
get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
end
- scope "/", Pleroma.Web do
- pipe_through(:api)
-
- get("/web/manifest.json", MastoFEController, :manifest)
- end
-
- scope "/", Pleroma.Web do
- pipe_through(:mastodon_html)
-
- get("/web/login", MastodonAPI.AuthController, :login)
- delete("/auth/sign_out", MastodonAPI.AuthController, :logout)
-
- post("/auth/password", MastodonAPI.AuthController, :password_reset)
-
- get("/web/*path", MastoFEController, :index)
-
- get("/embed/:id", EmbedController, :show)
- end
-
scope "/proxy/", Pleroma.Web.MediaProxy do
get("/preview/:sig/:url", MediaProxyController, :preview)
get("/preview/:sig/:url/:filename", MediaProxyController, :preview)
diff --git a/lib/pleroma/web/templates/masto_fe/index.html.eex b/lib/pleroma/web/templates/masto_fe/index.html.eex
deleted file mode 100644
index c330960fa..000000000
--- a/lib/pleroma/web/templates/masto_fe/index.html.eex
+++ /dev/null
@@ -1,35 +0,0 @@
-<!DOCTYPE html>
-<html lang='en'>
-<head>
-<meta charset='utf-8'>
-<meta content='width=device-width, initial-scale=1' name='viewport'>
-<title>
-<%= Config.get([:instance, :name]) %>
-</title>
-<link rel="icon" type="image/png" href="/favicon.png"/>
-<link rel="manifest" type="applicaton/manifest+json" href="<%= masto_fe_path(Pleroma.Web.Endpoint, :manifest) %>" />
-
-<meta name="theme-color" content="<%= Config.get([:manifest, :theme_color]) %>" />
-
-<script crossorigin='anonymous' src="/packs/locales.js"></script>
-<script crossorigin='anonymous' src="/packs/locales/glitch/en.js"></script>
-
-<link rel='preload' as='script' crossorigin='anonymous' href='/packs/features/getting_started.js'>
-<link rel='preload' as='script' crossorigin='anonymous' href='/packs/features/compose.js'>
-<link rel='preload' as='script' crossorigin='anonymous' href='/packs/features/home_timeline.js'>
-<link rel='preload' as='script' crossorigin='anonymous' href='/packs/features/notifications.js'>
-<script id='initial-state' type='application/json'><%= initial_state(@token, @user, @custom_emojis) %></script>
-
-<script src="/packs/core/common.js"></script>
-<link rel="stylesheet" media="all" href="/packs/core/common.css" />
-
-<script src="/packs/flavours/glitch/common.js"></script>
-<link rel="stylesheet" media="all" href="/packs/flavours/glitch/common.css" />
-
-<script src="/packs/flavours/glitch/home.js"></script>
-</head>
-<body class='app-body no-reduce-motion system-font'>
- <div class='app-holder' data-props='{&quot;locale&quot;:&quot;en&quot;}' id='mastodon'>
- </div>
-</body>
-</html>
diff --git a/lib/pleroma/web/views/masto_fe_view.ex b/lib/pleroma/web/views/masto_fe_view.ex
deleted file mode 100644
index b9055cb7f..000000000
--- a/lib/pleroma/web/views/masto_fe_view.ex
+++ /dev/null
@@ -1,91 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.MastoFEView do
- use Pleroma.Web, :view
- alias Pleroma.Config
- alias Pleroma.User
- alias Pleroma.Web.MastodonAPI.AccountView
- alias Pleroma.Web.MastodonAPI.CustomEmojiView
-
- def initial_state(token, user, custom_emojis) do
- limit = Config.get([:instance, :limit])
-
- %{
- meta: %{
- streaming_api_base_url: Pleroma.Web.Endpoint.websocket_url(),
- access_token: token,
- locale: "en",
- domain: Pleroma.Web.Endpoint.host(),
- admin: "1",
- me: "#{user.id}",
- unfollow_modal: false,
- boost_modal: false,
- delete_modal: true,
- auto_play_gif: false,
- display_sensitive_media: false,
- reduce_motion: false,
- max_toot_chars: limit,
- mascot: User.get_mascot(user)["url"]
- },
- poll_limits: Config.get([:instance, :poll_limits]),
- rights: %{
- delete_others_notice: present?(user.is_moderator),
- admin: present?(user.is_admin)
- },
- compose: %{
- me: "#{user.id}",
- default_privacy: user.default_scope,
- default_sensitive: false,
- allow_content_types: Config.get([:instance, :allowed_post_formats])
- },
- media_attachments: %{
- accept_content_types: [
- ".jpg",
- ".jpeg",
- ".png",
- ".gif",
- ".webm",
- ".mp4",
- ".m4v",
- "image\/jpeg",
- "image\/png",
- "image\/gif",
- "video\/webm",
- "video\/mp4"
- ]
- },
- settings: user.mastofe_settings || %{},
- push_subscription: nil,
- accounts: %{user.id => render(AccountView, "show.json", user: user, for: user)},
- custom_emojis: render(CustomEmojiView, "index.json", custom_emojis: custom_emojis),
- char_limit: limit
- }
- |> Jason.encode!()
- |> Phoenix.HTML.raw()
- end
-
- defp present?(nil), do: false
- defp present?(false), do: false
- defp present?(_), do: true
-
- def render("manifest.json", _params) do
- %{
- name: Config.get([:instance, :name]),
- description: Config.get([:instance, :description]),
- icons: Config.get([:manifest, :icons]),
- theme_color: Config.get([:manifest, :theme_color]),
- background_color: Config.get([:manifest, :background_color]),
- display: "standalone",
- scope: Pleroma.Web.base_url(),
- start_url: masto_fe_path(Pleroma.Web.Endpoint, :index, ["getting-started"]),
- categories: [
- "social"
- ],
- serviceworker: %{
- src: "/sw.js"
- }
- }
- end
-end