More ID encoding handling fixes in libraries

This commit is contained in:
davelopez
2023-03-29 08:55:53 +01:00
committed by Nicola Soranzo
parent 171d51e8f3
commit 5a3ee67fa0
6 changed files with 14 additions and 15 deletions
+1 -3
View File
@@ -255,9 +255,7 @@ class LibraryManager:
allowed_library_add_ids = prefetched_ids.get("allowed_library_add_ids", None) if prefetched_ids else None
allowed_library_modify_ids = prefetched_ids.get("allowed_library_modify_ids", None) if prefetched_ids else None
allowed_library_manage_ids = prefetched_ids.get("allowed_library_manage_ids", None) if prefetched_ids else None
library_dict = library.to_dict(
view="element", value_mapper={"id": trans.security.encode_id, "root_folder_id": trans.security.encode_id}
)
library_dict = library.to_dict(view="element")
library_dict["public"] = False if (restricted_library_ids and library.id in restricted_library_ids) else True
library_dict["create_time_pretty"] = pretty_print_time_interval(library.create_time, precise=True)
if not trans.user_is_admin:
-2
View File
@@ -5249,8 +5249,6 @@ class Library(Base, Dictifiable, HasName, Serializable):
We prepend an F to folders.
"""
rval = super().to_dict(view=view, value_mapper=value_mapper)
if "root_folder_id" in rval:
rval["root_folder_id"] = f"F{str(rval['root_folder_id'])}"
return rval
def get_active_folders(self, folder, folders=None):
+1 -1
View File
@@ -104,7 +104,7 @@ class EncodedLibraryFolderDatabaseIdField(str, BaseDatabaseIdField):
raise TypeError("String required")
if not v.startswith("F"):
raise TypeError("Invalid library folder ID. Folder IDs must start with an 'F'")
cls.ensure_valid(v)
cls.ensure_valid(v[1:])
return cls(v)
@classmethod
+1 -1
View File
@@ -2407,7 +2407,7 @@ class LibraryLegacySummary(Model):
title="Description",
description="A short text describing the contents of the Library.",
)
root_folder_id: LibraryFolderDatabaseIdField = Field(
root_folder_id: EncodedLibraryFolderDatabaseIdField = Field(
...,
title="Root Folder ID",
description="Encoded ID of the Library's base folder.",
@@ -74,13 +74,12 @@ class LibrariesService(ServiceBase, ConsumesModelStores):
for library in query:
library_dict = self.library_manager.get_library_dict(trans, library, prefetched_ids)
libraries.append(LibrarySummary(**library_dict))
return LibrarySummaryList.construct(__root__=libraries)
return LibrarySummaryList(__root__=libraries)
def show(self, trans, id: DecodedDatabaseIdField) -> LibrarySummary:
"""Returns detailed information about a library."""
library = self.library_manager.get(trans, id)
library_dict = self.library_manager.get_library_dict(trans, library)
return LibrarySummary.construct(**library_dict)
return self._to_summary(trans, library)
def create(self, trans, payload: CreateLibraryPayload) -> LibrarySummary:
"""Creates a new library.
@@ -328,11 +327,9 @@ class LibrariesService(ServiceBase, ConsumesModelStores):
trans.sa_session.refresh(library)
# Copy the permissions to the root folder
trans.app.security_agent.copy_library_permissions(trans, library, library.root_folder)
item = library.to_dict(
view="element", value_mapper={"id": trans.security.encode_id, "root_folder_id": trans.security.encode_id}
)
return LibraryLegacySummary.construct(**item)
item = library.to_dict(view="element")
return LibraryLegacySummary(**item)
def _to_summary(self, trans, library) -> LibrarySummary:
library_dict = self.library_manager.get_library_dict(trans, library)
return LibrarySummary.construct(**library_dict)
return LibrarySummary(**library_dict)
+6
View File
@@ -47,6 +47,12 @@ class TestLibrariesApi(ApiTestCase):
ld = self.library_populator.get_library_contents_with_path(library_summary["id"], "/my cool name")
assert ld
@requires_new_library
def test_index(self):
self.library_populator.new_library("TestIndexLibraries")
libraries = self.library_populator.get_libraries()
assert len(libraries) > 0
@requires_new_library
def test_delete(self):
library = self.library_populator.new_library("DeleteTestLibrary")