Only allow MusicBrainz tagged file on a pod (#2083)

Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2607>
environments/review-docs-2083-yqf2yl/deployments/18772
Petitminion 2023-11-03 16:44:41 +01:00 zatwierdzone przez Marge
rodzic 169cd69a46
commit 2e3205a19d
3 zmienionych plików z 37 dodań i 0 usunięć

Wyświetl plik

@ -247,6 +247,15 @@ 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")
):
return fail_import(
upload,
"Uploading files without a MusicBrainz ID is not permitted in this pod",
detail="You can tag you files with MusicBrainz Picard",
)
final_metadata = collections.ChainMap(
additional_data, serializer.validated_data, internal_config

Wyświetl plik

@ -179,6 +179,7 @@ env = [
"DISABLE_PASSWORD_VALIDATORS=false",
"FUNKWHALE_PLUGINS=",
"MUSIC_DIRECTORY_PATH=/music",
"ONLY_ALLOW_MUSICBRAINZ_TAGGED_FILES=true",
]
[tool.coverage.run]

Wyświetl plik

@ -1400,3 +1400,30 @@ def test_fs_import(factories, cache, mocker, settings):
}
assert cache.get("fs-import:status") == "finished"
assert "Pruning dangling tracks" in cache.get("fs-import:logs")[-1]
def test_upload_checks_mbid_tag(temp_signal, factories, mocker):
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")
# mocker.spy(tasks, "get_track_from_import_metadata")
track = factories["music.Track"](album__attachment_cover=None, mbid=None)
path = os.path.join(DATA_DIR, "with_cover.opus")
upload = factories["music.Upload"](
track=None,
audio_file__from_path=path,
import_metadata={"funkwhale": {"track": {"uuid": str(track.uuid)}}},
)
mocker.patch("funkwhale_api.music.models.TrackActor.create_entries")
with temp_signal(signals.upload_import_status_updated) as handler:
tasks.process_upload(upload_id=upload.pk)
upload.refresh_from_db()
assert upload.import_status == "errored"
assert upload.import_details == {
"error_code": "Uploading files without a MusicBrainz ID is not permitted in this pod",
"detail": "You can tag you files with MusicBrainz Picard",
}