mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
More ID encoding handling fixes in libraries
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user