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

Include xml in frontend attribution options #4499

Merged
merged 5 commits into from
Jun 26, 2024

Conversation

madewithkode
Copy link
Collaborator

Fixes

Fixes #4430 by @midijohnny!

Description

Screenshot 2024-06-17 at 18 27 28

This PR seeks to add an extra Dublin-Core-Conforming XML attribution option on the frontend, allowing users to be able to credit creators in XML.

Testing Instructions

This change can be observed by visiting the detail page of any media item on Openverse, under the "Credit the creator" section, you should see an extra XML option.

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (just catalog/generate-docs for catalog
    PRs) or the media properties generator (just catalog/generate-docs media-props
    for the catalog or just api/generate-docs for the API) where applicable.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@madewithkode madewithkode requested a review from a team as a code owner June 17, 2024 17:35
@openverse-bot openverse-bot added 🧱 stack: frontend Related to the Nuxt frontend 🟩 priority: low Low priority and doesn't need to be rushed 🌟 goal: addition Addition of new feature 💻 aspect: code Concerns the software code in the repository 🕹 aspect: interface Concerns end-users' experience with the software 🧱 stack: api Related to the Django API labels Jun 17, 2024
@madewithkode madewithkode force-pushed the 4430_include_xml_in_frontend_attribution_options branch from b446fab to a9c2b40 Compare June 18, 2024 12:25
@madewithkode
Copy link
Collaborator Author

Hi @sarayourfriend your suggestions have been resolved. However, I see that playwright visual regression tests continue to fail, I'm not exactly sure how to go about updating them, I've looked at the docs referenced by the bot on playwright but it's not exactly clear how to come up with the new comparison screenshots e.t.c. I'd appreciate if I could get a step by step instruction on how to tackle this.

@dhruvkb
Copy link
Member

dhruvkb commented Jun 18, 2024

@madewithkode here's a hack I've used in the past which can avoid the need to run the VR tests locally.

Go to the workflow summary page https://github.com/WordPress/openverse/actions/runs/9564951682 and look for the artifacts named *_test_results. Download them. Then extract the files in the artifact ZIP that you downloaded and look at the previous and new versions of the file and the diff. If the new version of the file looks correct, replace the file in the repo with the files from the artifact ZIP.

@sarayourfriend
Copy link
Collaborator

sarayourfriend commented Jun 18, 2024

@madewithkode here are instructions for updating snapshots in tests: https://docs.openverse.org/frontend/guides/test.html#updating-snapshots. Run ./ov just frontend/run test:playwright visual-regression -u (leave off ./ov if you haven't set that up yet).

We should probably combine that document with the one the bot links in its comment. I've long struggled to know what the precise difference was between reference and guides in our docs, and it's often muddied things up a bit like it has here. Sorry for the confusion there.

Here's an issue to fix that problem with the docs: #4514

@madewithkode
Copy link
Collaborator Author

madewithkode commented Jun 19, 2024

Thanks @dhruvkb for the quick hack, going to try it out and hope it works, as running playwright locally appears to be a bit resource-intensive for me. @sarayourfriend Thanks for pointing to the actual documentation too and I totally agree that the information shared by the bot can really be improved to include the actual steps needed for updating snapshots. I might as well take up #4514 to fix this after this one is done.

@madewithkode madewithkode force-pushed the 4430_include_xml_in_frontend_attribution_options branch 4 times, most recently from 7306fda to fbfa4c3 Compare June 19, 2024 13:46
Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

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

This LGTM, thank you @madewithkode!

I do want to flag a concern for our designer @fcoveram: this change makes some of the tab labels occupy two lines on mobile instead of one. Here is an example:

https://github.com/WordPress/openverse/blob/4430_include_xml_in_frontend_attribution_options/frontend/test/playwright/visual-regression/pages/pages-single-result.spec.ts-snapshots/audio-ltr-from-search-results-with-additional-search-views-xs-linux.png

Do you think that looks okay, or should we change the design a bit, perhaps reducing the font size slightly on mobile or some other change? It doesn't have to happen in this PR in my opinion, but is something we could fix later.

Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

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

I have a bit of a small suggestion which will, unfortunately, necessitate new snapshots for Arabic. Mostly everything else looks fine and I would've approved the PR except for this change.

frontend/test/locales/ar.json Outdated Show resolved Hide resolved
@madewithkode madewithkode force-pushed the 4430_include_xml_in_frontend_attribution_options branch 3 times, most recently from 0238d00 to d2c080e Compare June 19, 2024 17:40
Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

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

There are a number of snapshots in the PR that are the same before and after, like the audio search and error pages, because they do not have the attribution box. The snapshot tests will likely still pass if these files are dropped from the PR.

I have a minor nit that seems okay to ignore.

Comment on lines 194 to 196
if (isXml) {
isPlaintext = true
}
Copy link
Member

Choose a reason for hiding this comment

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

This might just be me, but this conflation of XML with plain text causes a bit of mental gymnastics in the logic below. I feel like using isXml and isPlaintext separately would've been clearer.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we bypass the plaintext handling if we just use mediaItem.attribution, too, by the way?

Copy link
Member

Choose a reason for hiding this comment

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

That could work, and it would cut down on the code the frontend duplicates from the API, but I'm not sure about localisation though. The frontend is capable of localising the attribution text in a way the API is not.

Copy link
Collaborator

@sarayourfriend sarayourfriend Jun 20, 2024

Choose a reason for hiding this comment

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

Ah true 😕 In that case, should we undo the change from this comment before merging? #4499 (comment)

Copy link
Member

@dhruvkb dhruvkb Jun 20, 2024

Choose a reason for hiding this comment

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

I don't a simple revert will be adequate. I'm personally not well versed with the i18n situation of the attribution box and feel like looking into what currently happens (and I expect should happen) will need a bit of time. Part of that's because I'm not entirely sure if XML, which is more geared towards machines than people, should even be translated.

I was only referring to the rich and plain text versions, which should be translated imo and using mediaItem.attribution is definitely not enough for the latter of those two types of attribution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@zackkrida suggested using just the license URL, and the DC standard recommendation matches that too:

Typically, rights information includes a statement about various property rights associated with the resource, including intellectual property rights. Recommended practice is to refer to a rights statement with a URI. If this is not possible or feasible, a literal value (name, label, or short text) may be provided.

Then we don't need to worry about i18n at all for this (ideal!).

Copy link
Member

Choose a reason for hiding this comment

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

@madewithkode would you be able to update this to use the license URL instead of the attribution text?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dhruvkb this would mean just switching <dc:rights>${mediaItem.attribution}</dc:rights> in the XML attribution snippet to reference the CC license URL as in <dc:rights>${mediaItem.license_url}</dc:rights> right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This has been updated.

Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

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

After reversing the snapshots that had not been changed, I feel like this PR is good to go.

Thanks for the contribution @madewithkode! This is a very valuable feature and your implementation has been very clear and thorough.

@fcoveram
Copy link
Contributor

I do want to flag a concern for our designer @fcoveram: this change makes some of the tab labels occupy two lines on mobile instead of one. Here is an example:

https://github.com/WordPress/openverse/blob/4430_include_xml_in_frontend_attribution_options/frontend/test/playwright/visual-regression/pages/pages-single-result.spec.ts-snapshots/audio-ltr-from-search-results-with-additional-search-views-xs-linux.png

Do you think that looks okay, or should we change the design a bit, perhaps reducing the font size slightly on mobile or some other change? It doesn't have to happen in this PR in my opinion, but is something we could fix later.

I would follow the common practice of replacing with a dropdown element. Tailwind addresses this pretty well.

@zackkrida
Copy link
Member

That's a great (and simple) idea, @fcoveram. I'll make a follow up issue for that!

@sarayourfriend sarayourfriend force-pushed the 4430_include_xml_in_frontend_attribution_options branch from 8d1062c to 2c5e141 Compare June 25, 2024 05:14
@sarayourfriend
Copy link
Collaborator

@madewithkode I pushed a change to revert some unneeded snapshot updates as well as to fix a bug I realised with unescaped elements in the title and other work meta data. Some works would have had broken XML due to unescaped XML (or XML-like) text. Take this work, for example, where the creator's included their email in their username: https://openverse.org/image/7be0e5cb-6308-4c11-b397-38baf2d0a4e7

The XML generated without escaping it (which is caused by setting isPlaintext = true), is as follows:

<attribution xmlns:dc="http://purl.org/dc/elements/1.1/">
	<dc:creator>Photographer: Richard Ling <wikipedia@rling.com></dc:creator>
	<dc:title>Grey Nurse Shark at Fish Rock Cave, NSW</dc:title>
	<dc:rights>https://creativecommons.org/licenses/by-sa/3.0/</dc:rights>
	<dc:identifier>https://commons.wikimedia.org/w/index.php?curid=130380</dc:identifier>
	<dc:type>StillImage</dc:type>
</attribution>

That won't pass XML validation. Fix was easy though, just removed the lines setting isPlaintext = true to enable the escaping (though really we should separate these concerns into more explicit variables, I think!).

I'm also rebasing and re-running the snapshot tests to fix the conflicts for you.

@sarayourfriend sarayourfriend force-pushed the 4430_include_xml_in_frontend_attribution_options branch from 2c5e141 to ab61eb1 Compare June 25, 2024 05:27
Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

LGTM!

@madewithkode
Copy link
Collaborator Author

@madewithkode I pushed a change to revert some unneeded snapshot updates as well as to fix a bug I realised with unescaped elements in the title and other work meta data. Some works would have had broken XML due to unescaped XML (or XML-like) text. Take this work, for example, where the creator's included their email in their username: https://openverse.org/image/7be0e5cb-6308-4c11-b397-38baf2d0a4e7

The XML generated without escaping it (which is caused by setting isPlaintext = true), is as follows:

<attribution xmlns:dc="http://purl.org/dc/elements/1.1/">
	<dc:creator>Photographer: Richard Ling <wikipedia@rling.com></dc:creator>
	<dc:title>Grey Nurse Shark at Fish Rock Cave, NSW</dc:title>
	<dc:rights>https://creativecommons.org/licenses/by-sa/3.0/</dc:rights>
	<dc:identifier>https://commons.wikimedia.org/w/index.php?curid=130380</dc:identifier>
	<dc:type>StillImage</dc:type>
</attribution>

That won't pass XML validation. Fix was easy though, just removed the lines setting isPlaintext = true to enable the escaping (though really we should separate these concerns into more explicit variables, I think!).

I'm also rebasing and re-running the snapshot tests to fix the conflicts for you.

Thank you for the changes and for spotting this edge case @sarayourfriend

@sarayourfriend sarayourfriend merged commit 049e7f8 into main Jun 26, 2024
45 checks passed
@sarayourfriend sarayourfriend deleted the 4430_include_xml_in_frontend_attribution_options branch June 26, 2024 04:14
@sarayourfriend
Copy link
Collaborator

Thanks for your hard work, @madewithkode 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🕹 aspect: interface Concerns end-users' experience with the software 🌟 goal: addition Addition of new feature 🟩 priority: low Low priority and doesn't need to be rushed 🧱 stack: api Related to the Django API 🧱 stack: frontend Related to the Nuxt frontend
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Attribution: XML/RDF/Turtle please.
6 participants