-
Notifications
You must be signed in to change notification settings - Fork 461
Bulk checkpoint upsert api #10140
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
Closed
karenrasmussen
wants to merge
5
commits into
feat/checkpoint-merge-hook
from
feat/bulk-checkpoint-upsert-api
+468
−3
Closed
Bulk checkpoint upsert api #10140
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
43acd56
Add bulk API endpoint for upserting checkpoints
karenrasmussen b63098b
Validate and normalize reveal_date on checkpoint upsert
Elimpizza c502d47
format fix
Elimpizza 21adf43
Register the bulk checkpoint route in routes_test
Elimpizza 1d91f53
tests
Elimpizza 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,59 @@ | ||
| import json | ||
|
|
||
| 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 | ||
|
|
||
|
|
||
| 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")) | ||
|
|
||
|
|
||
| @api_config( | ||
| versions=["v1", "v2"], | ||
| route_name="api.bulk.checkpoint", | ||
| request_method="POST", | ||
| link_name="bulk.checkpoint", | ||
| description="Upsert checkpoints for hide and reveal", | ||
| permission=Permission.API.BULK_ACTION, | ||
| ) | ||
| def upsert_checkpoints(request): | ||
| data = BulkCheckpointSchema().validate(request.json) | ||
| authority = data["authority"] | ||
|
|
||
| checkpoint_service = request.find_service(CheckpointService) | ||
|
|
||
| if instructor_username := data.get("instructor_username"): | ||
| # Mark the instructor role in all groups included in this request, | ||
| # since a single sync can cover multiple groups (e.g. several course sections). | ||
| checkpoint_service.set_instructor_role( | ||
| authority=authority, | ||
| username=instructor_username, | ||
| group_authority_provided_ids=[ | ||
| item["group_authority_provided_id"] for item in data["checkpoints"] | ||
| ], | ||
| ) | ||
|
|
||
| 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, | ||
| } | ||
| ) | ||
|
|
||
| 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,35 @@ | ||
| { | ||
| "$schema": "https://json-schema.org/draft-07/schema", | ||
| "type": "object", | ||
| "title": "Bulk checkpoint upsert", | ||
| "properties": { | ||
| "authority": { | ||
| "type": "string" | ||
| }, | ||
| "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 | ||
| } | ||
| }, | ||
| "instructor_username": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This coalesce keeps the existing reveal_date whenever the incoming one is NULL. I think this should be a plain override instead:
{"reveal_date": parsed_reveal_date}