fix: stop sending accountId implicitly from the page client
The page client no longer resolves accountId from /v1/users/me. accountId is only sent when passed with --account-id, and a 403 for it now raises a clear error telling the user to omit it because the server scopes the listing to the caller's own account.
This commit is contained in:
+13
-11
@@ -336,6 +336,11 @@ class PointStore:
|
||||
query += " ORDER BY recipientId, registrationId"
|
||||
return [dict(row) for row in self.connection.execute(query, params)]
|
||||
|
||||
def webhooks_of(self, records: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
"""Webhooks of the accounts that own the given records."""
|
||||
owners = sorted({record["accountId"] for record in records if record.get("accountId")})
|
||||
return [webhook for owner in owners for webhook in self.webhooks(owner)]
|
||||
|
||||
def webhooks(self, account_id: str | None = None) -> list[dict[str, Any]]:
|
||||
if account_id:
|
||||
rows = self.connection.execute(
|
||||
@@ -432,8 +437,7 @@ def fetch_pages(
|
||||
) -> FetchSummary:
|
||||
"""Fetch one page (page_number given) or every page into the store.
|
||||
|
||||
A 403 for an explicit accountId (caller below POWER_USER) is retried once without
|
||||
it; the server then scopes the listing to the caller's own account.
|
||||
Without account_id the server scopes the listing to the caller's own account.
|
||||
"""
|
||||
summary = FetchSummary(account_id=account_id)
|
||||
seen: set[str] = set()
|
||||
@@ -443,24 +447,22 @@ def fetch_pages(
|
||||
data = service.page(
|
||||
page_number=current,
|
||||
page_size=page_size,
|
||||
account_id=summary.account_id,
|
||||
account_id=account_id,
|
||||
recipient_ids=recipient_ids,
|
||||
polygon=polygon,
|
||||
)
|
||||
except ApiError as exc:
|
||||
if exc.status_code == 403 and summary.account_id:
|
||||
LOGGER.warning(
|
||||
"accountId ile sorgu 403 verdi; accountId olmadan, sunucunun kendi hesabınıza "
|
||||
"daraltmasıyla yeniden deneniyor."
|
||||
)
|
||||
summary.account_id = None
|
||||
continue
|
||||
if exc.status_code == 403 and account_id:
|
||||
raise ConfigurationError(
|
||||
"accountId parametresi için en az POWER_USER yetkisi gerekir (HTTP 403). "
|
||||
"--account-id vermeyin; sistem hesabınızı kendisi tespit eder."
|
||||
) from exc
|
||||
raise
|
||||
registrations = [item for item in (data.get("registrations") or []) if isinstance(item, dict)]
|
||||
summary.total_records = int(data.get("totalRecords") or 0)
|
||||
summary.received += len(registrations)
|
||||
for registration in registrations:
|
||||
registration_id = store.upsert_registration(registration, summary.account_id)
|
||||
registration_id = store.upsert_registration(registration, account_id)
|
||||
if registration_id and registration_id not in seen:
|
||||
seen.add(registration_id)
|
||||
summary.registration_ids.append(registration_id)
|
||||
|
||||
Reference in New Issue
Block a user