Skip to content

Conversation

@vtran99
Copy link
Contributor

@vtran99 vtran99 commented Oct 15, 2024

Request to add a placeholder to display the personal data picture in email.

def render(cls, regform, registration):
picture_data = registration.get_personal_data_picture()
if not picture_data:
return _('NO PICTURE')
Copy link
Member

Choose a reason for hiding this comment

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

That looks quite ugly, especially w/ the uppercase.

Two potential options:

  • Returning an empty string
  • Returning a placeholder image (like the one with the initial we use e.g. in meeting participant lists)

Comment on lines 43 to 44
url = url_for('event_registration.registration_picture', picture_data.locator.file,
_external=True, token=registration.uuid)
Copy link
Member

Choose a reason for hiding this comment

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

I thought we agreed to use the cid and attach the image to the email? External image references in emails are generally a bad idea.

@vtran99
Copy link
Contributor Author

vtran99 commented Oct 16, 2024

I updated the code using cid, but for the preview it doesn't work as attachments can't be done.
Do you have a solution for it ?

@vtran99 vtran99 requested a review from ThiefMaster October 16, 2024 11:13
css_sanitizer = IndicoCSSSanitizer(allowed_css_properties=BLEACH_ALLOWED_STYLES_HTML)
return bleach.clean(string, tags=BLEACH_ALLOWED_TAGS_HTML, attributes=BLEACH_ALLOWED_ATTRIBUTES_HTML,
css_sanitizer=css_sanitizer)
protocols=BLEACH_ALLOWED_PROTOCOLS_HTML, css_sanitizer=css_sanitizer)
Copy link
Member

Choose a reason for hiding this comment

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

That should not be applied globally, but only when sending emails that require it (ie make it a default-false arg of this function).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to define the 'sanitise_html' with default arg:
app.add_template_filter(lambda s: Markup(sanitize_html(s or '', default_protocols=False)), 'sanitize_html')
but when I use the filter
{{ email_body | sanitize_html(True) }}
got error:
"setup_jinja..() takes 1 positional argument but 2 were given"

Could you please help ?

Copy link
Member

Choose a reason for hiding this comment

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

app.add_template_filter(lambda s, **kwargs: Markup(sanitize_html(s or '', **kwargs)), 'sanitize_html')

And then just add , *, allow_cid=False to the argument list of sanitize_html and depending on that arg use the default protocols or default protocols + cid

Copy link
Contributor Author

@vtran99 vtran99 Oct 16, 2024

Choose a reason for hiding this comment

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

same error: "setup_jinja..() takes 1 positional argument but 2 were given"
when calling the filter with arg:
app.add_template_filter(lambda s, **kwargs: Markup(sanitize_html(s or '', **kwargs)), 'sanitize_html')
def sanitize_html(string, *, allow_cid=False):
{{ email_body | sanitize_html(True) }}

Copy link
Member

Choose a reason for hiding this comment

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

You are passing it as a positional arg, but it should be a keyword arg...

'text-decoration', 'text-indent', 'text-shadow', 'text-transform', 'unicode-bidi', 'visibility', 'vertical-align',
'width', 'widows', 'white-space', 'word-spacing', 'word-wrap', 'z-index'
]
BLEACH_ALLOWED_PROTOCOLS_HTML = ['cid'] # used for embedded image
Copy link
Member

Choose a reason for hiding this comment

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

This will most likely break the current list of allowed protocols since you're only passing cid but no http/https now.

@ThiefMaster
Copy link
Member

I updated the code using cid, but for the preview it doesn't work as attachments can't be done.
Do you have a solution for it ?

Damn, forgot about the preview... One solution could be to use a base64 data url for this placeholder while rendering the preview. Or use your original solution for the preview and the cid only when generating the actual mail.

@vtran99
Copy link
Contributor Author

vtran99 commented Oct 16, 2024

To render differently the picture in preview, I need to know the context "preview".
I see 3 ways to do it:

  1. check directly flask.request in PicturePlaceHolder.render();
  2. add context preview when calling replace_placeholder of email_body, then add '**kwargs' to all placeholders 'render':
email_body = replace_placeholders('registration-email', request.form['body'], regform=self.regform,
                                  registration=registration, preview=True)

def render(cls, regform, registration, **kwargs):
       if kwargs['preview']...
  1. get new placeholders for 'registration-email-preview' with a PicturePreviewPlaceHolder:
email_body = replace_placeholders('registration-email-preview', request.form['body'], regform=self.regform,
                                  registration=registration)
@signals.core.get_placeholders.connect_via('registration-email-preview')
def _get_registration_placeholders_preview(sender, regform, registration, **kwargs):
	yield PicturePreviewPlaceHolder
	yield ...

What would be your suggestion ?

@ThiefMaster
Copy link
Member

i had option 2 in mind, but i somehow thought we already accept kwargs and thus would not need to modify every placeholder... maybe checking if request.endpoint == 'event_registration.email_registrants_preview' (so kind of option 1) is not too ugly

@vtran99
Copy link
Contributor Author

vtran99 commented Oct 16, 2024

One last point:
in picture rendering, you use a fixed max-height/width = 250px, we would like to have a different value.
Can I use a parameter in config for that value ?
(same for REGISTRATION_PICTURE_THUMBNAIL_SIZE which is in a constants.py file)

@ThiefMaster
Copy link
Member

constant in python sure, but I don't think having an indico.conf setting for this would really make sense - it's SO specific and probably you guys are the only ones who would change this...

@vtran99 vtran99 requested a review from ThiefMaster October 16, 2024 17:23
@ThiefMaster ThiefMaster force-pushed the Add_email_placeholder_for_picture branch from 506289a to 3ca0fb5 Compare October 30, 2024 14:26
@ThiefMaster ThiefMaster added this to the v3.3 milestone Oct 30, 2024
@ThiefMaster ThiefMaster merged commit 11c5081 into indico:master Oct 30, 2024
@ThiefMaster ThiefMaster deleted the Add_email_placeholder_for_picture branch October 30, 2024 14:53
OmeGak pushed a commit to UNOG-Indico/indico-core that referenced this pull request Nov 5, 2024
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