Skip to content
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

Support annotation metadata in annotation PATCH-ing #8182

Merged
merged 1 commit into from
Oct 5, 2023

Conversation

marcospri
Copy link
Member

@marcospri marcospri commented Sep 14, 2023

Testing

  • Double check that editing an annotation still works as expected without any metadata

Create (if necessary) and edit an annotation in
https://hypothesis.instructure.com/courses/125/assignments/873

  • Note the annotation id an get the UUID version of it

The URL version is on the URL of the PATCH call to http://localhost:5000/api/annotations/ANNO_ID

  • Convert the ID to one usable in postgres
In [1]: from h.db.types import URLSafeUUID

In [2]: import uuid

In [3]: print(uuid.UUID(URLSafeUUID.url_safe_to_hex("_a6x_lI4Ee6Eai9rFQaNEg")))
fdaeb1fe-5238-11ee-846a-2f6b15068d12
  • Check the annotation in the DB
docker compose exec postgres psql -U postgres -c "select annotation.id, annotation.pk, annotation.user_id, text, data from annotation left outer join annotation_metadata on annotation_pk = annotation.pk where annotation.id::text = 'fdaeb1fe-5238-11ee-846a-2f6b15068d12';"
                  id                  | pk | user_id |         text         | data 
--------------------------------------+----+---------+----------------------+------
 fdaeb1fe-5238-11ee-846a-2f6b15068d12 |    |         | Test anno edited - 1 | 
(1 row)

edit the --data-raw parameter to include metadata_jwe with the JWE generated above, eg:

"metadata": {"assignment_id": 1}

  • Check the anno in the DB
docker compose exec postgres psql -U postgres -c "select annotation.id, annotation.pk, annotation.user_id, text, data from annotation left outer join annotation_metadata on annotation_pk = annotation.pk where annotation.id::text = 'fdaeb1fe-5238-11ee-846a-2f6b15068d12';"
                  id                  |  pk  | user_id |         text         |             data              
--------------------------------------+------+---------+----------------------+-------------------------------
 fdaeb1fe-5238-11ee-846a-2f6b15068d12 | 3053 |       7 | Test anno edited - 3 | {"lms": {"assignment_id": 1}}
(1 row)

Now the annotation has metadata and the PK and user_id values.

  • Curl again with other metadata and check the DB again:
docker compose exec postgres psql -U postgres -c "select annotation.id, annotation.pk, annotation.user_id, text, data from annotation left outer join annotation_metadata on annotation_pk = annotation.pk where annotation.id::text = 'fdaeb1fe-5238-11ee-846a-2f6b15068d12';"
                  id                  |  pk  | user_id |         text         |              data              
--------------------------------------+------+---------+----------------------+--------------------------------
 fdaeb1fe-5238-11ee-846a-2f6b15068d12 | 3053 |       7 | Test anno edited - 3 | {"lms": {"other": "metadata"}}
(1 row)

The metadata has been replaced and the pk and user_id remain the same.

@marcospri marcospri force-pushed the anno-creation-metadata branch 3 times, most recently from 923e99c to 4e01565 Compare September 29, 2023 10:06
Copy link
Contributor

@seanh seanh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Not much to this one. Does it need some tests?

@marcospri marcospri force-pushed the anno-creation-metadata branch 2 times, most recently from 5af567b to f389baf Compare October 5, 2023 05:45
@marcospri marcospri requested a review from seanh October 5, 2023 05:46
@marcospri
Copy link
Member Author

Not much to this one. Does it need some tests?

Yes, missed those before with the coverage issues, now I get yelled by make coverage 👍

@marcospri marcospri force-pushed the anno-creation-metadata branch 2 times, most recently from eaaa8d5 to 959a3ec Compare October 5, 2023 10:56
Base automatically changed from anno-creation-metadata to main October 5, 2023 11:01
@marcospri marcospri merged commit 5581bd3 into main Oct 5, 2023
6 checks passed
@marcospri marcospri deleted the anno-editing-metadata branch October 5, 2023 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants