From 179c53695efeb65a4fd057ae0582efc1a993e745 Mon Sep 17 00:00:00 2001 From: Petitminion Date: Mon, 6 Nov 2023 00:00:39 +0100 Subject: [PATCH] make setting dynamic Part-of: --- api/config/settings/common.py | 7 ------- .../music/dynamic_preferences_registry.py | 15 +++++++++++++++ api/funkwhale_api/music/tasks.py | 6 ++---- api/pyproject.toml | 1 - api/tests/conftest.py | 5 ----- api/tests/music/test_tasks.py | 3 ++- api/tests/test_import_audio_file.py | 2 +- front/src/views/admin/Settings.vue | 2 ++ 8 files changed, 22 insertions(+), 19 deletions(-) diff --git a/api/config/settings/common.py b/api/config/settings/common.py index 651ea96c8..de4117edc 100644 --- a/api/config/settings/common.py +++ b/api/config/settings/common.py @@ -1484,10 +1484,3 @@ Typesense hostname. Defaults to `localhost` on non-Docker deployments and to `ty Docker deployments. """ TYPESENSE_NUM_TYPO = env("TYPESENSE_NUM_TYPO", default=5) - -ONLY_ALLOW_MUSICBRAINZ_TAGGED_FILES = env( - "ONLY_ALLOW_MUSICBRAINZ_TAGGED_FILES", default=False -) -""" -If True, files without a Musicbrainz id will not be uploaded. -""" diff --git a/api/funkwhale_api/music/dynamic_preferences_registry.py b/api/funkwhale_api/music/dynamic_preferences_registry.py index 13d5ae56a..f459586d7 100644 --- a/api/funkwhale_api/music/dynamic_preferences_registry.py +++ b/api/funkwhale_api/music/dynamic_preferences_registry.py @@ -32,3 +32,18 @@ class MusicCacheDuration(types.IntPreference): "will be erased and retranscoded on the next listening." ) field_kwargs = {"required": False} + + +@global_preferences_registry.register +class MbidTaggedContent(types.BooleanPreference): + show_in_api = True + section = music + name = "only_allow_musicbrainz_tagged_files" + verbose_name = "Only allow Musicbrainz tagged files" + help_text = ( + "Only Musicbrainz tagged files will be allowed to be uploaded on the server. " + "If files where uploaded before this settings will not affect them. " + "To clean the db from files not following mb tags use the funkwhale cli " + "or use quality filters" + ) + default = False diff --git a/api/funkwhale_api/music/tasks.py b/api/funkwhale_api/music/tasks.py index 13baf36ca..f50ac8be3 100644 --- a/api/funkwhale_api/music/tasks.py +++ b/api/funkwhale_api/music/tasks.py @@ -247,10 +247,8 @@ def process_upload(upload, update_denormalization=True): return fail_import( upload, "invalid_metadata", detail=detail, file_metadata=metadata_dump ) - if ( - settings.ONLY_ALLOW_MUSICBRAINZ_TAGGED_FILES is True - and not serializer.validated_data.get("mbid") - ): + check_mbid = preferences.get("music__only_allow_musicbrainz_tagged_files") + if check_mbid is True and not serializer.validated_data.get("mbid"): return fail_import( upload, "Uploading files without a MusicBrainz ID is not permitted in this pod", diff --git a/api/pyproject.toml b/api/pyproject.toml index 075e0e427..ab2d6a47c 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -179,7 +179,6 @@ env = [ "DISABLE_PASSWORD_VALIDATORS=false", "FUNKWHALE_PLUGINS=", "MUSIC_DIRECTORY_PATH=/music", - "ONLY_ALLOW_MUSICBRAINZ_TAGGED_FILES=true", ] [tool.coverage.run] diff --git a/api/tests/conftest.py b/api/tests/conftest.py index 99d943b20..d241db5a7 100644 --- a/api/tests/conftest.py +++ b/api/tests/conftest.py @@ -429,8 +429,3 @@ def clear_license_cache(db): @pytest.fixture def faker(): return factory.Faker._get_faker() - - -@pytest.fixture() -def dont_check_mbid(settings): - settings.ONLY_ALLOW_MUSICBRAINZ_TAGGED_FILES = False diff --git a/api/tests/music/test_tasks.py b/api/tests/music/test_tasks.py index d9b07d937..d742bebb4 100644 --- a/api/tests/music/test_tasks.py +++ b/api/tests/music/test_tasks.py @@ -1402,7 +1402,8 @@ def test_fs_import(factories, cache, mocker, settings): assert "Pruning dangling tracks" in cache.get("fs-import:logs")[-1] -def test_upload_checks_mbid_tag(temp_signal, factories, mocker): +def test_upload_checks_mbid_tag(temp_signal, factories, mocker, preferences): + preferences["music__only_allow_musicbrainz_tagged_files"] = True mocker.patch("funkwhale_api.federation.routes.outbox.dispatch") mocker.patch("funkwhale_api.music.tasks.populate_album_cover") mocker.patch("funkwhale_api.music.metadata.Metadata.get_picture") diff --git a/api/tests/test_import_audio_file.py b/api/tests/test_import_audio_file.py index f096788f1..398b7aaa1 100644 --- a/api/tests/test_import_audio_file.py +++ b/api/tests/test_import_audio_file.py @@ -364,7 +364,7 @@ def test_handle_modified_update_existing_path_if_found_and_attributed_to( update_track_metadata.assert_not_called() -def test_import_files(factories, capsys, dont_check_mbid): +def test_import_files(factories, capsys): # smoke test to ensure the command run properly library = factories["music.Library"](actor__local=True) call_command( diff --git a/front/src/views/admin/Settings.vue b/front/src/views/admin/Settings.vue index 34889c866..2f3495bf6 100644 --- a/front/src/views/admin/Settings.vue +++ b/front/src/views/admin/Settings.vue @@ -57,6 +57,8 @@ const groups = computed(() => [ settings: [ { name: 'music__transcoding_enabled' }, { name: 'music__transcoding_cache_duration' } + { name: 'music__only_allow_musicbrainz_tagged_files' }, + ] }, {