Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions mp_api/client/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,23 @@ def _query_resource(
suffix = infix if suffix == "core" else suffix
suffix = suffix.replace("_", "-")

# Check if user has access to GNoMe
has_gnome_access = bool(
self._submit_requests(
url=urljoin(self.endpoint, "materials/summary/"),
criteria={
"batch_id": "gnome_r2scan_statics",
"_fields": "material_id",
},
use_document_model=False,
num_chunks=1,
chunk_size=1,
timeout=timeout,
)
.get("meta", {})
.get("total_doc", 0)
)

# Paginate over all entries in the bucket.
# TODO: change when a subset of entries needed from DB
if "tasks" in suffix:
Expand All @@ -493,6 +510,11 @@ def _query_resource(
bucket_suffix = "build"
prefix = f"collections/{db_version}/{suffix}"

# only include prefixes accessible to user
# i.e. append `batch_id=others/core` to `prefix`
if not has_gnome_access:
prefix += "/batch_id=others"

bucket = f"materialsproject-{bucket_suffix}"
paginator = self.s3_client.get_paginator("list_objects_v2")
pages = paginator.paginate(Bucket=bucket, Prefix=prefix)
Expand Down