From: Alexander Strizhakov Date: Sat, 11 Jan 2020 09:15:42 +0000 (+0300) Subject: Merge branch 'develop' into admin-be X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=1630ecaa20894c6e18b83ce1a830184d577150c3;p=akkoma Merge branch 'develop' into admin-be --- 1630ecaa20894c6e18b83ce1a830184d577150c3 diff --cc lib/pleroma/web/admin_api/admin_api_controller.ex index a13dd4775,c8abeff06..ce5411e8a --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@@ -88,7 -84,7 +88,7 @@@ defmodule Pleroma.Web.AdminAPI.AdminAPI plug( OAuthScopesPlug, %{scopes: ["read"], admin: true} -- when action in [:config_show, :migrate_to_db, :migrate_from_db, :list_log] ++ when action in [:config_show, :migrate_from_db, :list_log] ) plug( diff --cc test/web/admin_api/admin_api_controller_test.exs index aae9c872a,a3fbb6041..610fa5271 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@@ -1929,26 -1860,6 +1860,20 @@@ defmodule Pleroma.Web.AdminAPI.AdminAPI end describe "GET /api/pleroma/admin/config" do + clear_config([:configurable_from_database]) do + Pleroma.Config.put([:configurable_from_database], true) + end + - setup %{conn: conn} do - admin = insert(:user, is_admin: true) - - %{conn: assign(conn, :user, admin)} - end - + test "when configuration from database is off", %{conn: conn} do + initial = Pleroma.Config.get([:configurable_from_database]) + Pleroma.Config.put([:configurable_from_database], false) + on_exit(fn -> Pleroma.Config.put([:configurable_from_database], initial) end) + conn = get(conn, "/api/pleroma/admin/config") + + assert json_response(conn, 400) == + "To use this endpoint you need to enable configuration from database." + end + test "without any settings in db", %{conn: conn} do conn = get(conn, "/api/pleroma/admin/config") @@@ -1981,23 -1890,9 +1906,16 @@@ end end - test "POST /api/pleroma/admin/config error" do - admin = insert(:user, is_admin: true) - - conn = - build_conn() - |> assign(:user, admin) - |> post("/api/pleroma/admin/config", %{"configs" => []}) ++ test "POST /api/pleroma/admin/config error", %{conn: conn} do ++ conn = post(conn, "/api/pleroma/admin/config", %{"configs" => []}) + + assert json_response(conn, 400) == + "To use this endpoint you need to enable configuration from database." + end + describe "POST /api/pleroma/admin/config" do - setup %{conn: conn} do - admin = insert(:user, is_admin: true) - + setup do - temp_file = "config/test.exported_from_db.secret.exs" + http = Application.get_env(:pleroma, :http) on_exit(fn -> Application.delete_env(:pleroma, :key1) @@@ -2008,16 -1903,12 +1926,14 @@@ Application.delete_env(:pleroma, :keyaa2) Application.delete_env(:pleroma, Pleroma.Web.Endpoint.NotReal) Application.delete_env(:pleroma, Pleroma.Captcha.NotReal) - :ok = File.rm(temp_file) + Application.put_env(:pleroma, :http, http) + Application.put_env(:tesla, :adapter, Tesla.Mock) + :ok = File.rm("config/test.exported_from_db.secret.exs") end) - - %{conn: assign(conn, :user, admin)} end - clear_config([:instance, :dynamic_configuration]) do - Pleroma.Config.put([:instance, :dynamic_configuration], true) + clear_config([:configurable_from_database]) do + Pleroma.Config.put([:configurable_from_database], true) end @tag capture_log: true @@@ -2896,20 -2456,21 +2812,18 @@@ end describe "config mix tasks run" do - setup %{conn: conn} do - admin = insert(:user, is_admin: true) - + setup do - temp_file = "config/test.exported_from_db.secret.exs" - Mix.shell(Mix.Shell.Quiet) on_exit(fn -> Mix.shell(Mix.Shell.IO) - :ok = File.rm(temp_file) end) - %{conn: assign(conn, :user, admin)} + :ok end - clear_config([:instance, :dynamic_configuration]) do - Pleroma.Config.put([:instance, :dynamic_configuration], true) + clear_config([:configurable_from_database]) do + Pleroma.Config.put([:configurable_from_database], true) end clear_config([:feed, :post_title]) do @@@ -2917,26 -2478,15 +2831,28 @@@ end test "transfer settings to DB and to file", %{conn: conn} do - assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) == [] - ret_conn = get(conn, "/api/pleroma/admin/config/migrate_to_db") - assert json_response(ret_conn, 200) == %{} - assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) > 0 + on_exit(fn -> :ok = File.rm("config/test.exported_from_db.secret.exs") end) + assert Repo.all(Pleroma.Web.AdminAPI.Config) == [] + Mix.Tasks.Pleroma.Config.run(["migrate_to_db"]) + assert Repo.aggregate(Pleroma.Web.AdminAPI.Config, :count, :id) > 0 + + conn = get(conn, "/api/pleroma/admin/config/migrate_from_db") + + assert json_response(conn, 200) == %{} + assert Repo.all(Pleroma.Web.AdminAPI.Config) == [] + end + + test "returns error if configuration from database is off", %{conn: conn} do + initial = Pleroma.Config.get([:configurable_from_database]) + on_exit(fn -> Pleroma.Config.put([:configurable_from_database], initial) end) + Pleroma.Config.put([:configurable_from_database], false) + + conn = get(conn, "/api/pleroma/admin/config/migrate_from_db") - ret_conn = get(conn, "/api/pleroma/admin/config/migrate_from_db") + assert json_response(conn, 400) == + "To use this endpoint you need to enable configuration from database." + - assert json_response(ret_conn, 200) == %{} - assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) == [] ++ assert Repo.all(Pleroma.Web.AdminAPI.Config) == [] end end