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

fix: image displaying in email content for comments #72

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading