make sure upload get moove to built-in libs
This commit is contained in:
parent
c28e0e3460
commit
0c2be3e576
|
@ -38,6 +38,9 @@ def migrate_libraries_to_playlist(apps, schema_editor):
|
|||
Actor = apps.get_model("federation", "Actor")
|
||||
Channel = apps.get_model("audio", "Channel")
|
||||
|
||||
to_instance_libs = []
|
||||
to_public_libs = []
|
||||
to_me_libs = []
|
||||
for library in Library.objects.all():
|
||||
if (
|
||||
not federation_utils.is_local(library.actor.fid)
|
||||
|
@ -86,6 +89,15 @@ def migrate_libraries_to_playlist(apps, schema_editor):
|
|||
with transaction.atomic():
|
||||
insert_tracks_to_playlist(apps, playlist, uploads)
|
||||
|
||||
if library.privacy_level == "me":
|
||||
to_me_libs.append(library)
|
||||
if library.privacy_level == "instance":
|
||||
to_instance_libs.append(library)
|
||||
if library.privacy_level == "everyone":
|
||||
to_public_libs.append(library)
|
||||
|
||||
library.privacy_level = "me"
|
||||
library.save()
|
||||
except Exception as e:
|
||||
print(f"An error occurred during library.playlist creation : {e}")
|
||||
continue
|
||||
|
@ -113,6 +125,35 @@ def migrate_libraries_to_playlist(apps, schema_editor):
|
|||
library.uploads.all().update(library=build_in_lib)
|
||||
library.delete
|
||||
|
||||
if privacy_level == "everyone":
|
||||
for lib in to_public_libs:
|
||||
lib.uploads.all().update(library=build_in_lib)
|
||||
if privacy_level == "instance":
|
||||
for lib in to_instance_libs:
|
||||
lib.uploads.all().update(library=build_in_lib)
|
||||
if privacy_level == "me":
|
||||
for lib in to_me_libs:
|
||||
lib.uploads.all().update(library=build_in_lib)
|
||||
|
||||
|
||||
def check_succefull_migration(apps, schema_editor):
|
||||
Actor = apps.get_model("federation", "Actor")
|
||||
Playlist = apps.get_model("playlists", "Playlist")
|
||||
|
||||
for actor in Actor.objects.all():
|
||||
not_build_in_libs = len(actor.playlists.all()) + len(
|
||||
actor.libraries.filter(channel__isnull=False)
|
||||
)
|
||||
if len(actor.libraries.all()) - 2 != not_build_in_libs:
|
||||
raise Exception(
|
||||
"Incoherent library database state, check for errors in log and share them to the funkwhale team. Migration was abordted to prevent data loss"
|
||||
)
|
||||
for playlist in Playlist.objects.all():
|
||||
if playlist.library.privacy_level != "me":
|
||||
raise Exception(
|
||||
"Incoherent playlist database state, check for errors in log and share them to the funkwhale team. Migration was abordted to prevent data loss"
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
|
@ -132,4 +173,7 @@ class Migration(migrations.Migration):
|
|||
migrations.RunPython(
|
||||
migrate_libraries_to_playlist, reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
migrations.RunPython(
|
||||
check_succefull_migration, reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
]
|
||||
|
|
|
@ -46,13 +46,11 @@ There is no other reason to share the playlit.library to remote.
|
|||
- [x] library and playlist scan delay are long (24h), force on ap update
|
||||
- [x] make sure only owned upload are added to the playlist.library
|
||||
- [x] update the "drop library" migrations to use the playlist.library instead of user follow
|
||||
- [ ] make sure user get the new libraries created after library drop
|
||||
- [x] make sure user get the new libraries created after library drop
|
||||
- [x] update the federation api : when we receive a fetch for a library the upload serializer need to know which lib (playlist lib or user lib)
|
||||
- [x] Support library.playlist_uploads in library scan -> add playlist_uploads in items in library federation viewset
|
||||
- [x] investigate library scan bug : don't delete old content of the lib (local cache?): we need to empty the playlist before the scan(not ideal but less work)
|
||||
- [ ] if the user change the upload to another built-in lib, make sure the upload is not delete (we would loose the playlist_library relation) but only updated.
|
||||
- [ ] enforce actor.libraries to only have three entries.
|
||||
- [ ] enforce upload.playlist_libraries to always be private
|
||||
- [x] check actor has only have three built-in libs and upload.playlist_libraries is private after migration
|
||||
|
||||
### Follow up
|
||||
|
||||
|
@ -62,3 +60,4 @@ There is no other reason to share the playlit.library to remote.
|
|||
- [ ] Playlist discovery : add the playlist to my playlist collection = follow request to playlist
|
||||
- [ ] Playlist Track activity (to avoid having to refetch the whole playlist)
|
||||
- [ ] Document : The user that want to federate need to activate remote activities in it's user settings. Even if the library is public the playlist activities will not be sended to remote -> We need to implement a followers activity setting (#2362)
|
||||
- [ ] allow users to change the upload to another built-in lib, make sure the upload is not delete (we would loose the playlist_library relation) but only updated
|
||||
|
|
Loading…
Reference in New Issue