Skip to content

Commit

Permalink
fix: fixed course update notification UI in notification tray (#35715)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadadeeltajamul authored Oct 28, 2024
1 parent e8cdb06 commit ebe3dc5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cms/djangoapps/contentstore/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,3 +974,18 @@ def test_if_content_is_plain_text(self):
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>"
2 changes: 2 additions & 0 deletions cms/djangoapps/contentstore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from __future__ import annotations
import configparser
import html
import logging
import re
from collections import defaultdict
Expand Down Expand Up @@ -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', '')
Expand Down

0 comments on commit ebe3dc5

Please sign in to comment.