List available frontends also when no static/frontends folder is present yet
authorIlja <pleroma@spectraltheorem.be>
Sat, 14 Aug 2021 18:42:12 +0000 (18:42 +0000)
committerHaelwenn <contact+git.pleroma.social@hacktivis.me>
Sat, 14 Aug 2021 18:42:12 +0000 (18:42 +0000)
* To see what front ends are installed, it ls static/frontends. When this folder doesn't exists yet, it will return an empty array.
* Installing still works since the folder is created during installation already

lib/pleroma/web/admin_api/controllers/frontend_controller.ex
test/pleroma/web/admin_api/controllers/frontend_controller_test.exs

index 722f51bd2e119183527ba053775db91ffd13b4fd..442e6a5a00b9fabdf2c1bf88ad43648b012444fa 100644 (file)
@@ -35,6 +35,12 @@ defmodule Pleroma.Web.AdminAPI.FrontendController do
   end
 
   defp installed do
-    File.ls!(Pleroma.Frontend.dir())
+    frontend_directory = Pleroma.Frontend.dir()
+
+    if File.exists?(frontend_directory) do
+      File.ls!(frontend_directory)
+    else
+      []
+    end
   end
 end
index bc827cc12ee48cb2f10905ca66864b29346ac7b9..200682ba92d6dde618c305b04a0aa87de3219a3a 100644 (file)
@@ -42,6 +42,20 @@ defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
 
       refute Enum.any?(response, fn frontend -> frontend["installed"] == true end)
     end
+
+    test "it lists available frontends when no frontend folder was created yet", %{conn: conn} do
+      File.rm_rf(@dir)
+
+      response =
+        conn
+        |> get("/api/pleroma/admin/frontends")
+        |> json_response_and_validate_schema(:ok)
+
+      assert Enum.map(response, & &1["name"]) ==
+               Enum.map(Config.get([:frontends, :available]), fn {_, map} -> map["name"] end)
+
+      refute Enum.any?(response, fn frontend -> frontend["installed"] == true end)
+    end
   end
 
   describe "POST /api/pleroma/admin/frontends/install" do