fix: fixed course update notification UI in notification tray (#35715)

This commit is contained in:
Muhammad Adeel Tajamul
2024-10-28 15:47:08 +05:00
committed by GitHub
parent e8cdb06410
commit ebe3dc5e12
2 changed files with 17 additions and 0 deletions

View File

@@ -974,3 +974,18 @@ class CourseUpdateNotificationTests(ModuleStoreTestCase):
assert Notification.objects.all().count() == 1
notification = Notification.objects.first()
assert notification.content == "<p><strong>content Sub content heading</strong></p>"
def test_if_html_unescapes(self):
"""
Tests if html unescapes when creating content of course update notification
"""
user = UserFactory()
CourseEnrollment.enroll(user=user, course_key=self.course.id)
assert Notification.objects.all().count() == 0
content = "<p>&lt;p&gt; &amp;nbsp;&lt;/p&gt;<br />"\
"&lt;p&gt;abcd&lt;/p&gt;<br />"\
"&lt;p&gt;&amp;nbsp;&lt;/p&gt;<br /></p>"
send_course_update_notification(self.course.id, content, self.user)
assert Notification.objects.all().count() == 1
notification = Notification.objects.first()
assert notification.content == "<p><strong>abcd</strong></p>"

View File

@@ -3,6 +3,7 @@ Common utility functions useful throughout the contentstore
"""
from __future__ import annotations
import configparser
import html
import logging
import re
from collections import defaultdict
@@ -2258,6 +2259,7 @@ def clean_html_body(html_body):
"""
Get html body, remove tags and limit to 500 characters
"""
html_body = html.unescape(html_body).strip()
html_body = BeautifulSoup(Truncator(html_body).chars(500, html=True), 'html.parser')
text_content = html_body.get_text(separator=" ").strip()
text_content = text_content.replace('\n', '').replace('\r', '')