Skip to content

Fix images URL in newsletters#10761

Merged
andreslucena merged 1 commit intodecidim:developfrom
Quentinchampenois:fix/images_in_newsletter
Mar 13, 2024
Merged

Fix images URL in newsletters#10761
andreslucena merged 1 commit intodecidim:developfrom
Quentinchampenois:fix/images_in_newsletter

Conversation

@Quentinchampenois
Copy link
Copy Markdown
Contributor

@Quentinchampenois Quentinchampenois commented Apr 24, 2023

🎩 What? Why?

Please describe your pull request.

Images uploaded with the WYSWYG editor are not accessible out of the application like images uploaded in newsletter.

At the moment, EditorImagesController#create returns the path of the newly uploaded image. Source will be correctly resolved from the application, however we should return a full URL for external resources like newsletter.

This PR allows to rewrite source url in img HTML tags of newsletters content on the fly. Uploaded images url will be stored as relative path in database, and organization host with protocol will be interpolated on each image of the content just before being sent.

📌 Related Issues

Link your PR to an issue

Testing

Describe the best way to test or validate your PR.

  1. Upload a new image in newsletter content editor
  2. Send newsletter
  3. Verify HTML and see full URL in img src

♥️ Thank you!

@Quentinchampenois Quentinchampenois marked this pull request as ready for review April 24, 2023 15:31
@alecslupu alecslupu requested a review from a team April 25, 2023 10:28
Copy link
Copy Markdown
Contributor

@ahukkanen ahukkanen left a comment

Choose a reason for hiding this comment

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

Nice PR and thanks a lot for your contribution!

I see one potential problem with this approach because the values are persisted to the database for all records (not only newsletters), see my comment below.

I was thinking that could we instead do some pre-processing on the email template, like finding all the <img> tags in it and injecting the organization hostname and protocol in front of the image paths instead?

We already perform some pre-processing on the generated email through premailer, so I think we could apply similar logic here.

Or alternatively we could maybe utilize the Decidim's content parsers / renderers and replace the images with some placeholders. But I'd imagine that involving a lot more work than the approach mentioned above.

@Quentinchampenois
Copy link
Copy Markdown
Contributor Author

Thank you for the review !

I will take a look on how to rewrite relative URLs in img tags on the fly before sending

I convert this PR to draft and reopen it once implemented

@Quentinchampenois Quentinchampenois marked this pull request as draft June 7, 2023 07:45
@Quentinchampenois Quentinchampenois marked this pull request as ready for review June 7, 2023 14:16
@Quentinchampenois Quentinchampenois changed the title Return full image url in editor images controller Rewrite images relative path to full URL in newsletters Jun 7, 2023
Copy link
Copy Markdown
Member

@andreslucena andreslucena left a comment

Choose a reason for hiding this comment

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

I tried it out locally and i t works as expected!

I have to admin that I've seen this bug in some newsletters from https://canodrom.barcelona/ but I didn't have the time to invest on the fix... Great to see it fixed already 👏🏽 👏🏽

Sorry for the delay in checking this out. I only have some really minors cosmetic changes and this should be ready to be merged.

We would also need a final check from Antti, but that can be done once you do these last set of changes.

Can you also make a merge with develop just to be sure that everything is alright in the specs? I've done locally and it seems like it was OK.

@andreslucena andreslucena added module: admin type: fix PRs that implement a fix for a bug labels Oct 15, 2023
@andreslucena andreslucena self-assigned this Oct 23, 2023
@Quentinchampenois
Copy link
Copy Markdown
Contributor Author

Hello, I planned to apply changes during the week !

@andreslucena
Copy link
Copy Markdown
Member

Hello, I planned to apply changes during the week !

Perfect! Let me know when this is ready for another round

@Quentinchampenois Quentinchampenois changed the title Rewrite images relative path to full URL in newsletters Fix images URL in newsletters Oct 24, 2023
@Quentinchampenois
Copy link
Copy Markdown
Contributor Author

I applied your suggestions, to be more easy to read I forced push to cleanup git history

The unique commit contains your change request @andreslucena and also @ahukkanen's changes request
Feel free to ask for other changes, this is now ready for another review

Thanks !

About the failing spec "Link PR Format / Check PR title", I think this is not directly related to the title but to the labels right ?

@andreslucena
Copy link
Copy Markdown
Member

About the failing spec "Link PR Format / Check PR title", I think this is not directly related to the title but to the labels right ?

Yes, it is! You can ignore that, it's a new action that we're still ironing out.

andreslucena
andreslucena previously approved these changes Oct 25, 2023
Copy link
Copy Markdown
Member

@andreslucena andreslucena left a comment

Choose a reason for hiding this comment

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

One final look and this looks good 👏🏽 👏🏽

As @ahukkanen made a first review some time ago, we'll wait a couple of weeks until he has availability to review and merge this. If you don't have time let me know and we'll merge this as is so we can (finally) close this long standing PR.

Thanks for your patience @Quentinchampenois!

@andreslucena
Copy link
Copy Markdown
Member

@Quentinchampenois sorry for the delay on this PR. May I ask you a final merge with develop 🙏🏽 ? We have been changing the checks and linters and this should be done just to be sure that we're not adding new offences in develop.

Let me know if you don't have the bandwidth, I can create another PR based on this one. Thanks for your help and patience in this issue.

@Quentinchampenois Quentinchampenois force-pushed the fix/images_in_newsletter branch from 4407cd6 to 937fa0a Compare March 12, 2024 15:02
@andreslucena andreslucena dismissed ahukkanen’s stale review March 13, 2024 10:54

Antti did not have time to review it in these months so I'll take it out of his hands

Copy link
Copy Markdown
Member

@andreslucena andreslucena left a comment

Choose a reason for hiding this comment

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

Just tried it out one last time and it works great. Code-wise is 💯

Thanks for taking care of this issue @Quentinchampenois 👏🏽 👏🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: admin type: fix PRs that implement a fix for a bug

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

Images uploaded in newsletter content are missing

4 participants