Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85628671
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/mix/tasks/pleroma/frontend.ex b/lib/mix/tasks/pleroma/frontend.ex
index 819cd9f6a..229ef10bd 100644
--- a/lib/mix/tasks/pleroma/frontend.ex
+++ b/lib/mix/tasks/pleroma/frontend.ex
@@ -1,99 +1,108 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.Frontend do
use Mix.Task
import Mix.Pleroma
alias Pleroma.Frontend
@shortdoc "Manages bundled Pleroma frontends"
@moduledoc File.read!("docs/administration/CLI_tasks/frontend.md")
def run(["install", "none" | _args]) do
shell_info("Skipping frontend installation because none was requested")
"none"
end
def run(["install", name | args]) do
start_pleroma()
{options, [], []} =
OptionParser.parse(
args,
strict: [
ref: :string,
build_url: :string,
build_dir: :string,
- file: :string
+ file: :string,
+ admin: :boolean,
+ primary: :boolean
]
)
shell_info("Installing frontend #{name}...")
with %Frontend{} = fe <-
options
|> Keyword.put(:name, name)
|> opts_to_frontend()
|> Frontend.install() do
shell_info("Frontend #{fe.name} installed")
+
+ if get_frontend_type(options) do
+ run(["enable", name] ++ args)
+ end
else
error ->
shell_error("Failed to install frontend")
exit(inspect(error))
end
end
def run(["enable", name | args]) do
start_pleroma()
{options, [], []} =
OptionParser.parse(
args,
strict: [
ref: :string,
build_url: :string,
build_dir: :string,
file: :string,
admin: :boolean,
primary: :boolean
]
)
- frontend_type = get_frontend_type(options)
+ frontend_type = get_frontend_type(options) || :primary
shell_info("Enabling frontend #{name}...")
with %Frontend{} = fe <-
options
|> Keyword.put(:name, name)
|> opts_to_frontend()
|> Frontend.enable(frontend_type) do
shell_info("Frontend #{fe.name} enabled")
else
error ->
shell_error("Failed to enable frontend")
exit(inspect(error))
end
end
defp opts_to_frontend(opts) do
struct(Frontend, opts)
end
defp get_frontend_type(opts) do
case Enum.into(opts, %{}) do
%{admin: true, primary: true} ->
raise "Invalid command. Only one frontend type may be selected."
%{admin: true} ->
:admin
- _ ->
+ %{primary: true} ->
:primary
+
+ _ ->
+ nil
end
end
end
diff --git a/test/mix/tasks/pleroma/frontend_test.exs b/test/mix/tasks/pleroma/frontend_test.exs
index db6a8a4dd..3443f8958 100644
--- a/test/mix/tasks/pleroma/frontend_test.exs
+++ b/test/mix/tasks/pleroma/frontend_test.exs
@@ -1,110 +1,135 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.FrontendTest do
use Pleroma.DataCase
alias Mix.Tasks.Pleroma.Frontend
import ExUnit.CaptureIO, only: [capture_io: 1]
@dir "test/frontend_static_test"
setup do
File.mkdir_p!(@dir)
clear_config([:instance, :static_dir], @dir)
on_exit(fn ->
File.rm_rf(@dir)
end)
end
test "it downloads and unzips a known frontend" do
clear_config([:frontends, :available], %{
"pleroma" => %{
"ref" => "fantasy",
"name" => "pleroma",
"build_url" => "http://gensokyo.2hu/builds/${ref}"
}
})
Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} ->
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend_dist.zip")}
end)
capture_io(fn ->
Frontend.run(["install", "pleroma"])
end)
assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
end
+ test "it enables a frontend with the --primary flag" do
+ frontend = %Pleroma.Frontend{
+ ref: "fantasy",
+ name: "pleroma",
+ build_url: "http://gensokyo.2hu/builds/${ref}"
+ }
+
+ map = Pleroma.Frontend.to_map(frontend)
+ clear_config(:configurable_from_database, true)
+ clear_config([:frontends, :available], %{"pleroma" => map})
+
+ Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend_dist.zip")}
+ end)
+
+ capture_io(fn ->
+ Frontend.run(["install", "pleroma", "--primary"])
+ end)
+
+ assert Pleroma.Config.get([:frontends, :primary]) == map
+ end
+
test "it also works given a file" do
clear_config([:frontends, :available], %{
"pleroma" => %{
"ref" => "fantasy",
"name" => "pleroma",
"build_dir" => ""
}
})
folder = Path.join([@dir, "frontends", "pleroma", "fantasy"])
previously_existing = Path.join([folder, "temp"])
File.mkdir_p!(folder)
File.write!(previously_existing, "yey")
assert File.exists?(previously_existing)
capture_io(fn ->
Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"])
end)
assert File.exists?(Path.join([folder, "test.txt"]))
refute File.exists?(previously_existing)
end
test "it downloads and unzips unknown frontends" do
Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} ->
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
end)
capture_io(fn ->
Frontend.run([
"install",
"unknown",
"--ref",
"baka",
"--build-url",
"http://gensokyo.2hu/madeup.zip",
"--build-dir",
""
])
end)
assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
end
describe "enable" do
setup do
clear_config(:configurable_from_database, true)
end
test "enabling a primary frontend" do
capture_io(fn -> Frontend.run(["enable", "soapbox-fe"]) end)
primary = Pleroma.Config.get([:frontends, :primary])
assert primary["name"] == "soapbox-fe"
end
test "enabling an admin frontend" do
capture_io(fn -> Frontend.run(["enable", "soapbox-fe", "--admin"]) end)
primary = Pleroma.Config.get([:frontends, :admin])
assert primary["name"] == "soapbox-fe"
end
test "raise if configurable_from_database is disabled" do
clear_config(:configurable_from_database, false)
- assert_raise(RuntimeError, fn -> Frontend.run(["enable", "soapbox-fe"]) end)
+
+ assert_raise(RuntimeError, fn ->
+ capture_io(fn -> Frontend.run(["enable", "soapbox-fe"]) end)
+ end)
end
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Aug 8, 1:19 PM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1723498
Default Alt Text
(6 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment