-
Notifications
You must be signed in to change notification settings - Fork 463
[HnR:4] Bulk checkpoint upsert API + reveal response fields #10150
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
Merged
karenrasmussen
merged 13 commits into
feat/checkpoint-merge-hook
from
checkpoint-reveal-response-fields
Jul 6, 2026
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0990fe4
Add bulk API endpoint for upserting checkpoints
karenrasmussen 163e31c
Validate and normalize reveal_date on checkpoint upsert
Elimpizza 5c463eb
format fix
Elimpizza 1a55103
Register the bulk checkpoint route in routes_test
Elimpizza 13760fd
tests
Elimpizza 86be302
Add checkpoint reveal endpoint and generalize user role setting
karenrasmussen a40e90c
Fix format
karenrasmussen 4a0f321
Add revealed and reveal_date fields to checkpoint responses
karenrasmussen 69c37df
Fix tests
karenrasmussen 1b658aa
TDD (testcase for authority violation)
Elimpizza 4d28fa1
(TDD: fix authority trusting issue)
Elimpizza ef5e080
Compare reveal_date against naive UTC in _is_revealed
Elimpizza 4e1f083
Address comments
karenrasmussen 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,116 @@ | ||
| import json | ||
| from datetime import datetime | ||
|
|
||
| from importlib_resources import files | ||
| from pyramid.response import Response | ||
|
|
||
| from h.schemas.base import JSONSchema | ||
| from h.security import Permission | ||
| from h.services.checkpoint import CheckpointService | ||
| from h.views.api.config import api_config | ||
|
|
||
|
|
||
| def _is_revealed(checkpoint): | ||
| return ( | ||
| checkpoint is not None | ||
| and checkpoint.reveal_date is not None | ||
| and checkpoint.reveal_date <= datetime.utcnow() # noqa: DTZ003 | ||
| ) | ||
|
|
||
|
|
||
| def _reveal_date_isoformat(checkpoint): | ||
| if checkpoint and checkpoint.reveal_date: | ||
| return checkpoint.reveal_date.isoformat() | ||
| return None | ||
|
|
||
|
|
||
| class BulkCheckpointSchema(JSONSchema): | ||
| _SCHEMA_FILE = files("h.views.api.bulk") / "checkpoint_schema.json" | ||
| schema_version = 7 | ||
| schema = json.loads(_SCHEMA_FILE.read_text(encoding="utf-8")) | ||
|
|
||
|
|
||
| class BulkCheckpointRevealSchema(JSONSchema): | ||
| _SCHEMA_FILE = files("h.views.api.bulk") / "checkpoint_reveal_schema.json" | ||
| schema_version = 7 | ||
| schema = json.loads(_SCHEMA_FILE.read_text(encoding="utf-8")) | ||
|
|
||
|
|
||
| @api_config( | ||
| versions=["v1", "v2"], | ||
| route_name="api.bulk.checkpoint", | ||
| request_method="POST", | ||
| link_name="bulk.checkpoint", | ||
| description="Upsert checkpoints", | ||
| permission=Permission.API.BULK_ACTION, | ||
| ) | ||
| def upsert_checkpoints(request): | ||
| data = BulkCheckpointSchema().validate(request.json) | ||
| authority = request.identity.auth_client.authority | ||
|
|
||
| checkpoint_service = request.find_service(CheckpointService) | ||
|
|
||
| group_authority_provided_ids = [ | ||
| item["group_authority_provided_id"] for item in data["checkpoints"] | ||
| ] | ||
|
|
||
| if user_data := data.get("user"): | ||
| checkpoint_service.set_user_role( | ||
| authority=authority, | ||
| username=user_data["username"], | ||
| role=user_data["role"], | ||
| group_authority_provided_ids=group_authority_provided_ids, | ||
| ) | ||
|
|
||
| results = [] | ||
| for item in data["checkpoints"]: | ||
| checkpoint = checkpoint_service.upsert_checkpoint( | ||
| authority=authority, | ||
| group_authority_provided_id=item["group_authority_provided_id"], | ||
| document_uri=item["document_uri"], | ||
| reveal_date=item.get("reveal_date"), | ||
| ) | ||
| results.append( | ||
| { | ||
| "group_authority_provided_id": item["group_authority_provided_id"], | ||
| "document_uri": item["document_uri"], | ||
| "created": checkpoint is not None, | ||
| "revealed": _is_revealed(checkpoint), | ||
| "reveal_date": _reveal_date_isoformat(checkpoint), | ||
| } | ||
| ) | ||
|
|
||
| return Response(json=results, status=200) | ||
|
|
||
|
|
||
| @api_config( | ||
| versions=["v1", "v2"], | ||
| route_name="api.bulk.checkpoint.reveal", | ||
| request_method="POST", | ||
| link_name="bulk.checkpoint.reveal", | ||
| description="Reveal checkpoints, making annotations visible immediately", | ||
| permission=Permission.API.BULK_ACTION, | ||
| ) | ||
| def reveal_checkpoints(request): | ||
| data = BulkCheckpointRevealSchema().validate(request.json) | ||
| authority = request.identity.auth_client.authority | ||
|
|
||
| checkpoint_service = request.find_service(CheckpointService) | ||
|
|
||
| results = [] | ||
| for item in data["checkpoints"]: | ||
| checkpoint = checkpoint_service.reveal_checkpoints( | ||
| authority=authority, | ||
| group_authority_provided_id=item["group_authority_provided_id"], | ||
| document_uri=item["document_uri"], | ||
| ) | ||
| results.append( | ||
| { | ||
| "group_authority_provided_id": item["group_authority_provided_id"], | ||
| "document_uri": item["document_uri"], | ||
| "revealed": checkpoint is not None, | ||
| "reveal_date": _reveal_date_isoformat(checkpoint), | ||
| } | ||
| ) | ||
|
|
||
| return Response(json=results, status=200) |
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,29 @@ | ||
| { | ||
| "$schema": "https://json-schema.org/draft-07/schema", | ||
| "type": "object", | ||
| "title": "Bulk checkpoint reveal", | ||
| "properties": { | ||
| "authority": { | ||
| "type": "string" | ||
| }, | ||
|
karenrasmussen marked this conversation as resolved.
Outdated
|
||
| "checkpoints": { | ||
| "type": "array", | ||
| "minItems": 1, | ||
| "items": { | ||
| "type": "object", | ||
| "properties": { | ||
| "group_authority_provided_id": { | ||
| "type": "string" | ||
| }, | ||
| "document_uri": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": ["group_authority_provided_id", "document_uri"], | ||
| "additionalProperties": false | ||
| } | ||
| } | ||
| }, | ||
| "required": ["authority", "checkpoints"], | ||
| "additionalProperties": false | ||
| } | ||
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,46 @@ | ||
| { | ||
| "$schema": "https://json-schema.org/draft-07/schema", | ||
| "type": "object", | ||
| "title": "Bulk checkpoint upsert", | ||
| "properties": { | ||
| "authority": { | ||
| "type": "string" | ||
| }, | ||
|
karenrasmussen marked this conversation as resolved.
Outdated
|
||
| "checkpoints": { | ||
| "type": "array", | ||
| "minItems": 1, | ||
| "items": { | ||
| "type": "object", | ||
| "properties": { | ||
| "group_authority_provided_id": { | ||
| "type": "string" | ||
| }, | ||
| "document_uri": { | ||
| "type": "string" | ||
| }, | ||
| "reveal_date": { | ||
| "type": ["string", "null"] | ||
| } | ||
| }, | ||
| "required": ["group_authority_provided_id", "document_uri"], | ||
| "additionalProperties": false | ||
| } | ||
| }, | ||
| "user": { | ||
| "type": "object", | ||
| "properties": { | ||
| "username": { | ||
| "type": "string" | ||
| }, | ||
| "role": { | ||
| "type": "string", | ||
| "enum": ["instructor", "student"] | ||
| } | ||
| }, | ||
| "required": ["username", "role"], | ||
| "additionalProperties": false | ||
| } | ||
| }, | ||
| "required": ["authority", "checkpoints"], | ||
| "additionalProperties": false | ||
| } | ||
Oops, something went wrong.
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.