Add an endpoint for deleting emoji packs
authorEkaterina Vaartis <vaartis@cock.li>
Mon, 12 Aug 2019 15:03:59 +0000 (18:03 +0300)
committerEkaterina Vaartis <vaartis@cock.li>
Wed, 18 Sep 2019 21:16:33 +0000 (00:16 +0300)
lib/pleroma/web/emoji_api/emoji_api_controller.ex
lib/pleroma/web/router.ex
test/web/emoji_api_controller_test.exs

index f2b1e8a8dbe0c45df10d62572c259112706151ff..49d970277185b3e6ab09f4d4c2a3d933d3513892 100644 (file)
@@ -210,4 +210,16 @@ keeping it in cache for #{div(cache_ms, 1000)}s")
         conn |> put_status(:internal_server_error) |> text(e)
     end
   end
+
+  def delete(conn, %{"name" => name}) do
+    pack_dir = Path.join(@emoji_dir_path, name)
+
+    case File.rm_rf(pack_dir) do
+      {:ok, _} ->
+        conn |> text("ok")
+
+      {:error, _} ->
+        conn |> put_status(:internal_server_error) |> text("Couldn't delete the pack #{name}")
+    end
+  end
 end
index 1c781d750eebcbe5347c186c6a3fa2703eeb357a..4df0ca3c36f493882ec52668a06d44699fe1a595 100644 (file)
@@ -218,6 +218,7 @@ defmodule Pleroma.Web.Router do
       # Modifying packs
       pipe_through([:admin_api, :oauth_write])
 
+      delete("/delete/:name", EmojiAPIController, :delete)
       post("/download_from", EmojiAPIController, :download_from)
     end
 
index c037883ee15f3572dc2c37f19a52a50e826d6830..13a34d38d201caa27b3381fef85f826d467345aa 100644 (file)
@@ -42,7 +42,7 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
     assert Enum.find(arch, fn {n, _} -> n == 'blank.png' end)
   end
 
-  test "downloading a shared pack from another instance via download_from" do
+  test "downloading a shared pack from another instance via download_from, deleting it" do
     on_exit(fn ->
       File.rm_rf!("test/instance_static/emoji/test_pack2")
     end)
@@ -94,5 +94,12 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
 
     assert File.exists?("test/instance_static/emoji/test_pack2/pack.yml")
     assert File.exists?("test/instance_static/emoji/test_pack2/blank.png")
+
+    assert conn
+           |> assign(:user, admin)
+           |> delete(emoji_api_path(conn, :delete, "test_pack2"))
+           |> response(200) == "ok"
+
+    refute File.exists?("test/instance_static/emoji/test_pack2")
   end
 end