Migrated from old settings module to new one
This commit is contained in:
parent
3a6930457b
commit
e84f6d3ef4
20 changed files with 75 additions and 67 deletions
2
.iex.exs
2
.iex.exs
|
|
@ -11,7 +11,7 @@ alias Pinchflat.Tasks
|
|||
alias Pinchflat.Media
|
||||
alias Pinchflat.Profiles
|
||||
alias Pinchflat.Sources
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.Settings
|
||||
|
||||
alias Pinchflat.Downloading.MediaDownloader
|
||||
alias Pinchflat.YtDlp.Media, as: YtDlpMedia
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||
require Logger
|
||||
|
||||
alias Pinchflat.Repo
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.YtDlp.CommandRunner
|
||||
alias Pinchflat.Filesystem.FilesystemHelpers
|
||||
|
||||
|
|
@ -65,8 +65,6 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||
defp apply_default_settings do
|
||||
{:ok, yt_dlp_version} = CommandRunner.version()
|
||||
|
||||
SettingsBackup.fetch!(:onboarding, true)
|
||||
SettingsBackup.fetch!(:pro_enabled, false)
|
||||
SettingsBackup.set!(:yt_dlp_version, yt_dlp_version)
|
||||
Settings.set(yt_dlp_version: yt_dlp_version)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ defmodule Pinchflat.Settings.Setting do
|
|||
)a
|
||||
|
||||
schema "settings" do
|
||||
field :onboarding, :boolean, default: false
|
||||
field :onboarding, :boolean, default: true
|
||||
field :pro_enabled, :boolean, default: false
|
||||
field :yt_dlp_version, :string
|
||||
end
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ defmodule PinchflatWeb do
|
|||
import Plug.Conn
|
||||
import PinchflatWeb.Gettext
|
||||
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.Settings
|
||||
alias PinchflatWeb.Layouts
|
||||
|
||||
unquote(verified_routes())
|
||||
|
|
@ -58,7 +58,7 @@ defmodule PinchflatWeb do
|
|||
|
||||
use Phoenix.LiveView
|
||||
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.Settings
|
||||
|
||||
unquote(html_helpers())
|
||||
end
|
||||
|
|
@ -68,7 +68,7 @@ defmodule PinchflatWeb do
|
|||
quote do
|
||||
use Phoenix.LiveComponent
|
||||
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.Settings
|
||||
|
||||
unquote(html_helpers())
|
||||
end
|
||||
|
|
@ -82,7 +82,7 @@ defmodule PinchflatWeb do
|
|||
import Phoenix.Controller,
|
||||
only: [get_csrf_token: 0, view_module: 1, view_template: 1]
|
||||
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.Settings
|
||||
|
||||
# Include general helpers for rendering HTML
|
||||
unquote(html_helpers())
|
||||
|
|
@ -101,7 +101,7 @@ defmodule PinchflatWeb do
|
|||
import PinchflatWeb.CustomComponents.TableComponents
|
||||
import PinchflatWeb.CustomComponents.ButtonComponents
|
||||
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.Utils.StringUtils
|
||||
|
||||
# Shortcut for generating JS commands
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@
|
|||
Pinchflat v<%= Application.spec(:pinchflat)[:vsn] %>
|
||||
</span>
|
||||
<span class="group relative flex items-center gap-2.5 px-4 text-sm">
|
||||
yt-dlp <%= SettingsBackup.get!(:yt_dlp_version) %>
|
||||
yt-dlp <%= Settings.get!(:yt_dlp_version) %>
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ defmodule Pinchflat.UpgradeButtonLive do
|
|||
|> String.downcase()
|
||||
|
||||
if normalized_text == "got it!" do
|
||||
SettingsBackup.set!(:pro_enabled, true)
|
||||
Settings.set(pro_enabled: true)
|
||||
|
||||
{:noreply, update(socket, :button_disabled, fn _ -> false end)}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
<body
|
||||
x-data={"{
|
||||
sidebarVisible: false,
|
||||
proEnabled: #{SettingsBackup.get!(:pro_enabled)},
|
||||
onboarding: #{SettingsBackup.get!(:onboarding)}
|
||||
proEnabled: #{Settings.get!(:pro_enabled)},
|
||||
onboarding: #{Settings.get!(:onboarding)}
|
||||
}"}
|
||||
class="dark text-bodydark bg-boxdark-2"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileController do
|
|||
case Profiles.create_media_profile(media_profile_params) do
|
||||
{:ok, media_profile} ->
|
||||
redirect_location =
|
||||
if SettingsBackup.get!(:onboarding), do: ~p"/?onboarding=1", else: ~p"/media_profiles/#{media_profile}"
|
||||
if Settings.get!(:onboarding), do: ~p"/?onboarding=1", else: ~p"/media_profiles/#{media_profile}"
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Media profile created successfully.")
|
||||
|
|
@ -89,7 +89,7 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileController do
|
|||
end
|
||||
|
||||
defp get_onboarding_layout do
|
||||
if SettingsBackup.get!(:onboarding) do
|
||||
if Settings.get!(:onboarding) do
|
||||
{Layouts, :onboarding}
|
||||
else
|
||||
{Layouts, :app}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<div class="mb-6 flex gap-3 flex-row items-center">
|
||||
<.link :if={!SettingsBackup.get!(:onboarding)} href={~p"/media_profiles"}>
|
||||
<.link :if={!Settings.get!(:onboarding)} href={~p"/media_profiles"}>
|
||||
<.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
|
||||
</.link>
|
||||
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">New Media Profile</h2>
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ defmodule PinchflatWeb.Pages.PageController do
|
|||
done_onboarding = params["onboarding"] == "0"
|
||||
force_onboarding = params["onboarding"] == "1"
|
||||
|
||||
if done_onboarding, do: SettingsBackup.set!(:onboarding, false)
|
||||
if done_onboarding, do: Settings.set(onboarding: false)
|
||||
|
||||
if force_onboarding || SettingsBackup.get!(:onboarding) do
|
||||
if force_onboarding || Settings.get!(:onboarding) do
|
||||
render_onboarding_page(conn)
|
||||
else
|
||||
render_home_page(conn)
|
||||
|
|
@ -30,7 +30,7 @@ defmodule PinchflatWeb.Pages.PageController do
|
|||
end
|
||||
|
||||
defp render_onboarding_page(conn) do
|
||||
SettingsBackup.set!(:onboarding, true)
|
||||
Settings.set(onboarding: true)
|
||||
|
||||
conn
|
||||
|> render(:onboarding_checklist,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ defmodule PinchflatWeb.Sources.SourceController do
|
|||
case Sources.create_source(source_params) do
|
||||
{:ok, source} ->
|
||||
redirect_location =
|
||||
if SettingsBackup.get!(:onboarding), do: ~p"/?onboarding=1", else: ~p"/sources/#{source}"
|
||||
if Settings.get!(:onboarding), do: ~p"/?onboarding=1", else: ~p"/sources/#{source}"
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Source created successfully.")
|
||||
|
|
@ -159,7 +159,7 @@ defmodule PinchflatWeb.Sources.SourceController do
|
|||
end
|
||||
|
||||
defp get_onboarding_layout do
|
||||
if SettingsBackup.get!(:onboarding) do
|
||||
if Settings.get!(:onboarding) do
|
||||
{Layouts, :onboarding}
|
||||
else
|
||||
{Layouts, :app}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<div class="mb-6 flex gap-3 flex-row items-center">
|
||||
<.link :if={!SettingsBackup.get!(:onboarding)} href={~p"/sources"}>
|
||||
<.link :if={!Settings.get!(:onboarding)} href={~p"/sources"}>
|
||||
<.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
|
||||
</.link>
|
||||
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">New Source</h2>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
defmodule Pinchflat.Repo.Migrations.CreateSettingsBackup do
|
||||
defmodule Pinchflat.Repo.Migrations.CreateSettings do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
defmodule Pinchflat.Repo.Migrations.RenameSettingsBackupTable do
|
||||
defmodule Pinchflat.Repo.Migrations.RenameSettingsTable do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
|
|
|
|||
29
priv/repo/migrations/20240404174144_create_new_settings.exs
Normal file
29
priv/repo/migrations/20240404174144_create_new_settings.exs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
defmodule Pinchflat.Repo.Migrations.CreateNewSettings do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
create table(:settings) do
|
||||
add :onboarding, :boolean, default: true, null: false
|
||||
add :pro_enabled, :boolean, default: false, null: false
|
||||
add :yt_dlp_version, :string
|
||||
end
|
||||
|
||||
# Make an initial record because this will be the only one ever inserted
|
||||
execute "INSERT INTO settings (onboarding, pro_enabled, yt_dlp_version) VALUES (true, false, NULL)"
|
||||
|
||||
# Set the value of onboarding to the previous version set in `settings_backup`
|
||||
execute """
|
||||
UPDATE settings
|
||||
SET onboarding = COALESCE((SELECT value = 'true' FROM settings_backup WHERE name = 'onboarding'), true)
|
||||
"""
|
||||
|
||||
execute """
|
||||
UPDATE settings
|
||||
SET pro_enabled = COALESCE((SELECT value = 'true' FROM settings_backup WHERE name = 'pro_enabled'), false)
|
||||
"""
|
||||
end
|
||||
|
||||
def down do
|
||||
drop table(:settings)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
defmodule Pinchflat.Repo.Migrations.CreateSettings do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
create table(:settings) do
|
||||
add :onboarding, :boolean, default: false, null: false
|
||||
add :pro_enabled, :boolean, default: false, null: false
|
||||
add :yt_dlp_version, :string
|
||||
end
|
||||
|
||||
# Make an initial record because this will be the only one ever inserted
|
||||
execute "INSERT INTO settings (onboarding, pro_enabled, yt_dlp_version) VALUES (false, false, NULL)"
|
||||
end
|
||||
|
||||
def down do
|
||||
drop table(:settings)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,25 +1,24 @@
|
|||
defmodule Pinchflat.Boot.PreJobStartupTasksTest do
|
||||
use Pinchflat.DataCase
|
||||
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.SettingsBackup.SettingBackup
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.Boot.PreJobStartupTasks
|
||||
|
||||
# TODO: write tests for things like cookie file creation
|
||||
|
||||
describe "apply_default_settings" do
|
||||
setup do
|
||||
Repo.delete_all(SettingBackup)
|
||||
Settings.set(yt_dlp_version: nil)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "sets default settings" do
|
||||
assert_raise Ecto.NoResultsError, fn -> SettingsBackup.get!(:onboarding) end
|
||||
assert_raise Ecto.NoResultsError, fn -> SettingsBackup.get!(:pro_enabled) end
|
||||
assert Settings.get!(:yt_dlp_version) == nil
|
||||
|
||||
PreJobStartupTasks.start_link()
|
||||
|
||||
assert SettingsBackup.get!(:onboarding)
|
||||
refute SettingsBackup.get!(:pro_enabled)
|
||||
assert Settings.get!(:yt_dlp_version)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ defmodule PinchflatWeb.MediaProfileControllerTest do
|
|||
import Pinchflat.ProfilesFixtures
|
||||
|
||||
alias Pinchflat.Repo
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.Settings
|
||||
|
||||
@create_attrs %{name: "some name", output_path_template: "output_template.{{ ext }}"}
|
||||
@update_attrs %{
|
||||
|
|
@ -16,7 +16,7 @@ defmodule PinchflatWeb.MediaProfileControllerTest do
|
|||
@invalid_attrs %{name: nil, output_path_template: nil}
|
||||
|
||||
setup do
|
||||
SettingsBackup.set!(:onboarding, false)
|
||||
Settings.set(onboarding: false)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
|
@ -35,7 +35,7 @@ defmodule PinchflatWeb.MediaProfileControllerTest do
|
|||
end
|
||||
|
||||
test "renders correct layout when onboarding", %{conn: conn} do
|
||||
SettingsBackup.set!(:onboarding, true)
|
||||
Settings.set(onboarding: true)
|
||||
conn = get(conn, ~p"/media_profiles/new")
|
||||
|
||||
refute html_response(conn, 200) =~ "MENU"
|
||||
|
|
@ -59,14 +59,14 @@ defmodule PinchflatWeb.MediaProfileControllerTest do
|
|||
end
|
||||
|
||||
test "redirects to onboarding when onboarding", %{conn: conn} do
|
||||
SettingsBackup.set!(:onboarding, true)
|
||||
Settings.set(onboarding: true)
|
||||
conn = post(conn, ~p"/media_profiles", media_profile: @create_attrs)
|
||||
|
||||
assert redirected_to(conn) == ~p"/?onboarding=1"
|
||||
end
|
||||
|
||||
test "renders correct layout on error when onboarding", %{conn: conn} do
|
||||
SettingsBackup.set!(:onboarding, true)
|
||||
Settings.set(onboarding: true)
|
||||
conn = post(conn, ~p"/media_profiles", media_profile: @invalid_attrs)
|
||||
|
||||
refute html_response(conn, 200) =~ "MENU"
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
defmodule PinchflatWeb.PageControllerTest do
|
||||
use PinchflatWeb.ConnCase
|
||||
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.Settings
|
||||
|
||||
describe "GET / when testing onboarding" do
|
||||
test "sets the onboarding setting to true when onboarding", %{conn: conn} do
|
||||
_conn = get(conn, ~p"/")
|
||||
assert SettingsBackup.get!(:onboarding)
|
||||
assert Settings.get!(:onboarding)
|
||||
end
|
||||
|
||||
test "displays the onboarding page when onboarding is forced", %{conn: conn} do
|
||||
SettingsBackup.set!(:onboarding, false)
|
||||
Settings.set(onboarding: false)
|
||||
|
||||
conn = get(conn, ~p"/?onboarding=1")
|
||||
assert html_response(conn, 200) =~ "Welcome to Pinchflat"
|
||||
|
|
@ -18,14 +18,14 @@ defmodule PinchflatWeb.PageControllerTest do
|
|||
|
||||
test "sets the onboarding setting to false if you pass the corrent query param", %{conn: conn} do
|
||||
conn = get(conn, ~p"/")
|
||||
assert SettingsBackup.get!(:onboarding)
|
||||
assert Settings.get!(:onboarding)
|
||||
|
||||
_conn = get(conn, ~p"/?onboarding=0")
|
||||
refute SettingsBackup.get!(:onboarding)
|
||||
refute Settings.get!(:onboarding)
|
||||
end
|
||||
|
||||
test "displays the home page when not onboarding", %{conn: conn} do
|
||||
SettingsBackup.set!(:onboarding, false)
|
||||
Settings.set(onboarding: false)
|
||||
|
||||
conn = get(conn, ~p"/")
|
||||
assert html_response(conn, 200) =~ "MENU"
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ defmodule PinchflatWeb.SourceControllerTest do
|
|||
import Pinchflat.ProfilesFixtures
|
||||
|
||||
alias Pinchflat.Repo
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.Downloading.MediaDownloadWorker
|
||||
alias Pinchflat.SlowIndexing.MediaCollectionIndexingWorker
|
||||
|
||||
setup do
|
||||
media_profile = media_profile_fixture()
|
||||
SettingsBackup.set!(:onboarding, false)
|
||||
Settings.set(onboarding: false)
|
||||
|
||||
{
|
||||
:ok,
|
||||
|
|
@ -47,7 +47,7 @@ defmodule PinchflatWeb.SourceControllerTest do
|
|||
end
|
||||
|
||||
test "renders correct layout when onboarding", %{conn: conn} do
|
||||
SettingsBackup.set!(:onboarding, true)
|
||||
Settings.set(onboarding: true)
|
||||
conn = get(conn, ~p"/sources/new")
|
||||
|
||||
refute html_response(conn, 200) =~ "MENU"
|
||||
|
|
@ -74,14 +74,14 @@ defmodule PinchflatWeb.SourceControllerTest do
|
|||
test "redirects to onboarding when onboarding", %{conn: conn, create_attrs: create_attrs} do
|
||||
expect(YtDlpRunnerMock, :run, 1, &runner_function_mock/3)
|
||||
|
||||
SettingsBackup.set!(:onboarding, true)
|
||||
Settings.set(onboarding: true)
|
||||
conn = post(conn, ~p"/sources", source: create_attrs)
|
||||
|
||||
assert redirected_to(conn) == ~p"/?onboarding=1"
|
||||
end
|
||||
|
||||
test "renders correct layout on error when onboarding", %{conn: conn, invalid_attrs: invalid_attrs} do
|
||||
SettingsBackup.set!(:onboarding, true)
|
||||
Settings.set(onboarding: true)
|
||||
conn = post(conn, ~p"/sources", source: invalid_attrs)
|
||||
|
||||
refute html_response(conn, 200) =~ "MENU"
|
||||
|
|
|
|||
Loading…
Reference in a new issue