diff --git a/cellxgene_gateway/gateway.py b/cellxgene_gateway/gateway.py index 2bb9b3f..4075437 100644 --- a/cellxgene_gateway/gateway.py +++ b/cellxgene_gateway/gateway.py @@ -214,7 +214,10 @@ def do_view(path, source_name=None): match.status == CacheEntryStatus.loaded or match.status == CacheEntryStatus.loading ): - return match.serve_content(path) + if source.is_authorized(match.key.descriptor): + return match.serve_content(path) + else: + raise CellxgeneException("User not authorized to access this data", 403) elif match.status == CacheEntryStatus.error: raise ProcessException.from_cache_entry(match) diff --git a/cellxgene_gateway/items/file/fileitem_source.py b/cellxgene_gateway/items/file/fileitem_source.py index 4d236bc..4ade4b9 100644 --- a/cellxgene_gateway/items/file/fileitem_source.py +++ b/cellxgene_gateway/items/file/fileitem_source.py @@ -121,6 +121,9 @@ class FileItemSource(ItemSource): if self.is_h5ad_file(full_path): return self.shallowitem_from_descriptor(descriptor) + def is_authorized(self, descriptor): + return True + def lookup(self, indescriptor: str) -> LookupResult: descriptor = indescriptor.strip("/") if descriptor.endswith(self.annotation_file_suffix): diff --git a/cellxgene_gateway/items/item_source.py b/cellxgene_gateway/items/item_source.py index e49aaa9..eb778ff 100644 --- a/cellxgene_gateway/items/item_source.py +++ b/cellxgene_gateway/items/item_source.py @@ -40,6 +40,10 @@ class ItemSource(ABC): def update(self, item: Item) -> None: raise Exception('"update" unimplemented') + @abstractmethod + def is_authorized(self, descriptor: str) -> bool: + raise Exception('"is_authorized" unimplemented') + @abstractmethod def lookup(self, descriptor: str) -> LookupResult: raise Exception('"lookup" unimplemented') diff --git a/cellxgene_gateway/items/s3/s3item_source.py b/cellxgene_gateway/items/s3/s3item_source.py index 6f1ab26..39bfd62 100644 --- a/cellxgene_gateway/items/s3/s3item_source.py +++ b/cellxgene_gateway/items/s3/s3item_source.py @@ -113,6 +113,9 @@ class S3ItemSource(ItemSource): def update(self, item: S3Item) -> None: pass + def is_authorized(self, descriptor): + return True + def lookup_item(self, descriptor): full_path = self.url(descriptor) if self.is_h5ad_url(full_path): diff --git a/cellxgene_gateway/templates/cache_status.html b/cellxgene_gateway/templates/cache_status.html index 54e30c0..7360232 100644 --- a/cellxgene_gateway/templates/cache_status.html +++ b/cellxgene_gateway/templates/cache_status.html @@ -75,7 +75,9 @@ const el = $(this); const ts = el.text(); const dt = new Date(parseInt(ts * 1000)); - el.html(`${dt.toISOString()}
(${ts})`); + el.prepend(`${dt.toISOString()}
(`); + el.append(')'); + }); })