-
Notifications
You must be signed in to change notification settings - Fork 0
feat: allow access tokens to enumerate groups #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
agent-p1p
wants to merge
5
commits into
master
Choose a base branch
from
pip/goggles-331
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
093fa92
feat: allow access tokens to enumerate groups
agent-p1p b6eab0d
fix: make group pagination snapshot-safe
agent-p1p 8f917b1
fix: prevent commit-order polling omissions
agent-p1p 9c3eee9
fix: keep group cursors opaque
agent-p1p faa1261
fix: remove group refs from cursors
agent-p1p File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """Opaque keyset cursor helpers for the group index API.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from datetime import datetime | ||
|
|
||
| from django.core import signing | ||
| from django.core.signing import BadSignature | ||
| from django.db.models import Q | ||
| from django.utils import timezone | ||
| from django.utils.dateparse import parse_datetime | ||
|
|
||
| CURSOR_SALT = "goggles-groups-v1-cursor" | ||
|
|
||
|
|
||
| class InvalidGroupListCursor(ValueError): | ||
| pass | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class GroupListCursor: | ||
| watermark: datetime | ||
| updated_at: datetime | ||
| group_id: int | ||
| updated_since: datetime | None | ||
|
|
||
| def keyset_filter(self) -> Q: | ||
| return Q(updated_at__lt=self.updated_at) | Q( | ||
| updated_at=self.updated_at, | ||
| pk__gt=self.group_id, | ||
| ) | ||
|
|
||
|
|
||
| def encode_group_list_cursor( | ||
| *, | ||
| watermark: datetime, | ||
| updated_at: datetime, | ||
| group_id: int, | ||
| updated_since: datetime | None, | ||
| ) -> str: | ||
| payload = { | ||
| "w": watermark.isoformat(), | ||
| "u": updated_at.isoformat(), | ||
| "i": group_id, | ||
| "a": updated_since.isoformat() if updated_since is not None else None, | ||
| } | ||
| return signing.dumps(payload, salt=CURSOR_SALT, compress=True) | ||
|
|
||
|
|
||
| def decode_group_list_cursor(raw_cursor: str) -> GroupListCursor: | ||
| if not raw_cursor: | ||
| raise InvalidGroupListCursor("cursor is required") | ||
| try: | ||
| payload = signing.loads(raw_cursor, salt=CURSOR_SALT) | ||
| if not isinstance(payload, dict): | ||
| raise InvalidGroupListCursor("cursor payload is invalid") | ||
| watermark = _parse_cursor_timestamp(payload.get("w")) | ||
| updated_at = _parse_cursor_timestamp(payload.get("u")) | ||
| group_id = payload.get("i") | ||
| updated_since = _parse_optional_cursor_timestamp(payload.get("a")) | ||
| if not isinstance(group_id, int) or group_id <= 0: | ||
| raise InvalidGroupListCursor("cursor group id is invalid") | ||
| return GroupListCursor( | ||
| watermark=watermark, | ||
| updated_at=updated_at, | ||
| group_id=group_id, | ||
| updated_since=updated_since, | ||
| ) | ||
| except InvalidGroupListCursor: | ||
| raise | ||
| except (BadSignature, TypeError, ValueError) as exc: | ||
| raise InvalidGroupListCursor("cursor is invalid") from exc | ||
|
|
||
|
|
||
| def _parse_cursor_timestamp(value) -> datetime: | ||
| if not isinstance(value, str) or not value: | ||
| raise InvalidGroupListCursor("cursor timestamp is invalid") | ||
| parsed = parse_datetime(value) | ||
| if parsed is None: | ||
| raise InvalidGroupListCursor("cursor timestamp is invalid") | ||
| if timezone.is_naive(parsed): | ||
| parsed = timezone.make_aware(parsed, timezone.get_current_timezone()) | ||
| return parsed | ||
|
|
||
|
|
||
| def _parse_optional_cursor_timestamp(value) -> datetime | None: | ||
| if value is None: | ||
| return None | ||
| return _parse_cursor_timestamp(value) |
17 changes: 17 additions & 0 deletions
17
forensics/migrations/0014_auditgroup_updated_at_id_index.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Generated by Django 6.0.7 on 2026-07-29 08:43 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('forensics', '0013_personalaccesstoken'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddIndex( | ||
| model_name='auditgroup', | ||
| index=models.Index(fields=['-updated_at', 'id'], name='forensics_a_updated_8f04c0_idx'), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.