performant-software / Annotation-Studio

An online annotation platform for teaching and learning in the humanities.
http://www.annotationstudio.org
GNU General Public License v2.0
4 stars 1 forks source link

Fix incorrect metadata fetching on anthology documents #429

Closed camdendotlol closed 1 year ago

camdendotlol commented 1 year ago

What this PR does

This PR fixes the bug that was causing an empty filterLists object on exported documents. I identified that the issue was caused by these lines in the annotations controller:

if params[:document_id]
  loadOptions[:uri] = request.base_url + '/documents/' + params[:document_id]
end

This constructs the URL that is used in the database query to fetch related annotations. The problem was that there may be multiple versions of a document, e.g. a version saved at https://studio.covecollective.org/documents/portrait-of-mr-wh-the-adf1eb34-30b4-4467-93f0-e3c88f72ee70 and an anthology version at https://studio.covecollective.org/anthologies/wh-team-draft/documents/portrait-of-mr-wh-the-adf1eb34-30b4-4467-93f0-e3c88f72ee70. The above lines of code would always construct the first URL, so it would fetch incorrect or missing data.

This PR updates the statement to use the URL from the user's browser. It uses regex to replace the json stuff at the end to get the main URL of the document:

if params[:document_id]
  loadOptions[:uri] = request.url.sub(/\/annotations\/field\/.*.json$/, '')
end

There's probably a better way to do this than regex, but it works.

Testing

I've tested this myself with a local document, but we will need to test thoroughly on staging and probably again once it's deployed to production.

  1. Add a document to an anthology.
  2. Add a few annotations to the anthology, including tags and categories on some of them.
  3. Click the button to take a snapshot of the document: Screen Shot 2022-07-28 at 3 46 38 PM
  4. Click the "Download HTML" button just below that and Slack it to me.
  5. Visit https://staging.covecollective.org/documents. Search for and open the same document you edited above.
  6. There shouldn't be any visible annotations. Add a few (make sure they're different from the ones you added in step 2) with tags and categories.
  7. Repeat steps 4-5 and Slack me the file, making a note of which file is from which step.