alias Pleroma.Config
alias Pleroma.Web.Plugs.OAuthScopesPlug
- alias Pleroma.Workers.FrontendInstallerWorker
plug(Pleroma.Web.ApiSpec.CastAndValidate)
plug(OAuthScopesPlug, %{scopes: ["write"], admin: true} when action == :install)
end
def install(%{body_params: params} = conn, _params) do
- FrontendInstallerWorker.install(params.name, Map.delete(params, :name))
+ Pleroma.Frontend.install(params.name, Map.delete(params, :name))
index(conn, %{})
end
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Workers.FrontendInstallerWorker do
- use Oban.Worker, queue: :frontend_installer, max_attempts: 1
-
- alias Oban.Job
- alias Pleroma.Frontend
-
- def install(name, opts \\ []) do
- %{"name" => name, "opts" => Map.new(opts)}
- |> new()
- |> Oban.insert()
- end
-
- def perform(%Job{args: %{"name" => name, "opts" => opts}}) do
- opts = Keyword.new(opts, fn {key, value} -> {String.to_existing_atom(key), value} end)
- Frontend.install(name, opts)
- end
-end
defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
use Pleroma.Web.ConnCase
- use Oban.Testing, repo: Pleroma.Repo
import Pleroma.Factory
alias Pleroma.Config
- alias Pleroma.Tests.ObanHelpers
- alias Pleroma.Workers.FrontendInstallerWorker
@dir "test/frontend_static_test"
|> post("/api/pleroma/admin/frontends", %{name: "pleroma"})
|> json_response_and_validate_schema(:ok)
- assert_enqueued(
- worker: FrontendInstallerWorker,
- args: %{"name" => "pleroma", "opts" => %{}}
- )
-
- ObanHelpers.perform(all_enqueued(worker: FrontendInstallerWorker))
-
assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
response =
})
|> json_response_and_validate_schema(:ok)
- assert_enqueued(
- worker: FrontendInstallerWorker,
- args: %{
- "name" => "pleroma",
- "opts" => %{"file" => "test/fixtures/tesla_mock/frontend.zip"}
- }
- )
-
- ObanHelpers.perform(all_enqueued(worker: FrontendInstallerWorker))
-
assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
end
})
|> json_response_and_validate_schema(:ok)
- ObanHelpers.perform(all_enqueued(worker: FrontendInstallerWorker))
-
assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
end
end