Skip to content

Commit

Permalink
Merge pull request #6312 from hotosm/fix/displaying-images-in-email
Browse files Browse the repository at this point in the history
fix: image displaying in email content for comments
  • Loading branch information
ramyaragupathy authored Apr 9, 2024
2 parents 713027f + 93fbea0 commit 7d26e0c
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion backend/services/messaging/message_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
import time
import datetime
import bleach

from cachetools import TTLCache, cached
from typing import List
Expand Down Expand Up @@ -243,6 +244,34 @@ def send_message_after_comment(
task_link = MessageService.get_task_link(project_id, task_id)
project_link = MessageService.get_project_link(project_id, project_name)

# Clean comment and convert to html
allowed_tags = [
"a",
"b",
"blockquote",
"br",
"code",
"em",
"h1",
"h2",
"h3",
"img",
"i",
"li",
"ol",
"p",
"pre",
"strong",
"ul",
]
allowed_atrributes = {"a": ["href", "rel"], "img": ["src", "alt"]}
clean_comment = bleach.clean(
markdown(comment, output_format="html"),
tags=allowed_tags,
attributes=allowed_atrributes,
) # Bleach input to ensure no nefarious script tags etc
clean_comment = bleach.linkify(clean_comment)

messages = []
for username in usernames:
try:
Expand All @@ -260,7 +289,7 @@ def send_message_after_comment(
f"You were mentioned in a comment in {task_link} "
+ f"of Project {project_link}"
)
message.message = comment
message.message = clean_comment
messages.append(
dict(message=message, user=user, project_name=project_name)
)
Expand Down

0 comments on commit 7d26e0c

Please sign in to comment.