From 29f2c226cbbf38e98ecbbf61c93c8c35c83972f4 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 12 Dec 2024 15:40:25 -0500 Subject: [PATCH] omics/tables: Fix missing links for Globus-downloadable files for some deployment configurations The link display wrongly depended on the PUBLIC_DATA_ROOT setting being set. But it should only matter whether File.public is non-empty. This patch changes the File.relpublic property (and also File.relpath to match) making those independent of any settings. The somewhat complicating factor is that the DB only stores the relative paths but if OMICS_DATA_ROOT / PUBLIC_DATA_ROOT are set then mibios.umrad.PathField will always prepend the root dir and we have to conditionally run relative_to() to get the relative path back. Leaving the default settings as-is even if OMICS_DATA_ROOT as ./ is not a good choice. The production deployment should leave both default settings; in both cases getting back the relative paths works. This closes #60. --- mibios/glamr/tables.py | 1 + mibios/omics/models.py | 20 ++++++++++++++------ mibios/omics/settings.py | 5 ++--- mibios/omics/tables.py | 14 +++++++------- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/mibios/glamr/tables.py b/mibios/glamr/tables.py index a03f9913..5f3914ac 100644 --- a/mibios/glamr/tables.py +++ b/mibios/glamr/tables.py @@ -294,6 +294,7 @@ def order_storage_size(self, qs, is_descending): class FileTable(OmicsFileTable): + """ List files belonging to a sample """ class Meta: model = omics_models.File fields = ['download_url', 'filetype', 'size', 'modtime'] diff --git a/mibios/omics/models.py b/mibios/omics/models.py index cda6504f..27f1132c 100644 --- a/mibios/omics/models.py +++ b/mibios/omics/models.py @@ -1033,7 +1033,12 @@ def public_root(self): @property def relpath(self): """ The path relative to the common path prefix """ - return self.path.relative_to(self.root) + if self.root: + return self.path.relative_to(self.root) + elif self.path.is_absolute(): + raise ValueError('path is absolute abnd no root configured') + else: + return self.path @property def relpublic(self): @@ -1042,12 +1047,15 @@ def relpublic(self): This property may be exposed on a public page. - Returns None if no public path is set or if the common prefix is not - configured. + Returns None if no public path is set. """ - if self.public_root is None or self.public is None: - return None - return self.public.relative_to(self.public_root) + if self.public_root: + return self.public.relative_to(self.public_root) + elif self.public and self.public.is_absolute(): + raise ValueError('public path is absolute and no root configured') + else: + # is a rel path or None + return self.public def compute_public_path(self): """ diff --git a/mibios/omics/settings.py b/mibios/omics/settings.py index c71d04d9..cc374ac1 100644 --- a/mibios/omics/settings.py +++ b/mibios/omics/settings.py @@ -62,9 +62,8 @@ def get_db_settings(db_dir='.', db_infix=''): """ root Globus url for file app, publicly shared directory """ PUBLIC_DATA_ROOT = None -""" path to publicly accessible directory on staging server, this needs to be -set even on other deployments so that relative paths to the public files can be -computed """ +""" path to root of publicly accessible directory tree on staging server, leave +at None on other deployments """ OMICS_CHECKOUT_FILE = None """ path to the file checkout listing """ diff --git a/mibios/omics/tables.py b/mibios/omics/tables.py index 3ee5ba26..c8bcc6c7 100644 --- a/mibios/omics/tables.py +++ b/mibios/omics/tables.py @@ -30,14 +30,14 @@ class Meta: def render_download_url(self, value, record): if record.public: - path = record.public.relative_to(File.get_public_prefix()) - if value: - return format_html('{}', value, path) - else: - return f'{path} (unavailable)' + path = record.relpublic else: - path = record.path.relative_to(File.get_path_prefix()) - return str(path) + path = record.relpath + + if value: + return format_html('{}', value, path) + else: + return f'{"" if record.public else "*"}{path}' def order_download_url(self, queryset, is_descending): qs = queryset.annotate(path0=Coalesce('public', 'path'))