feat: truncated number of notifications in email (#35738)
This commit is contained in:
committed by
GitHub
parent
38e5745e06
commit
b55a17a9f7
@@ -12,19 +12,29 @@ from openedx.core.djangoapps.notifications.base_notification import COURSE_NOTIF
|
||||
EMAIL_DIGEST_SENT = "edx.notifications.email_digest"
|
||||
|
||||
|
||||
def send_user_email_digest_sent_event(user, cadence_type, notifications):
|
||||
def send_user_email_digest_sent_event(user, cadence_type, notifications, message_context):
|
||||
"""
|
||||
Sends tracker and segment email for user email digest
|
||||
"""
|
||||
notification_breakdown = {key: 0 for key in COURSE_NOTIFICATION_APPS.keys()}
|
||||
for notification in notifications:
|
||||
notification_breakdown[notification.app_name] += 1
|
||||
|
||||
truncated_count = {}
|
||||
email_content = message_context.get("email_content", [])
|
||||
for app in email_content:
|
||||
truncated_count[app.get("title", "")] = {
|
||||
"total": app.get("total", -1),
|
||||
"remaining_count": app.get("remaining_count", -1),
|
||||
}
|
||||
|
||||
event_data = {
|
||||
"username": user.username,
|
||||
"email": user.email,
|
||||
"cadence_type": cadence_type,
|
||||
"total_notifications_count": len(notifications),
|
||||
"count_breakdown": notification_breakdown,
|
||||
"truncated_count": truncated_count,
|
||||
"notification_ids": [notification.id for notification in notifications],
|
||||
"send_at": str(datetime.datetime.now())
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ def send_digest_email_to_user(user, cadence_type, start_date, end_date, course_l
|
||||
).personalize(recipient, course_language, message_context)
|
||||
message = add_headers_to_email_message(message, message_context)
|
||||
ace.send(message)
|
||||
send_user_email_digest_sent_event(user, cadence_type, notifications)
|
||||
send_user_email_digest_sent_event(user, cadence_type, notifications, message_context)
|
||||
logger.info(f'<Email Cadence> Email sent to {user.username} ==Temp Log==')
|
||||
|
||||
|
||||
|
||||
@@ -148,8 +148,18 @@ class TestContextFunctions(ModuleStoreTestCase):
|
||||
{'title': 'Updates', 'count': 1},
|
||||
]
|
||||
expected_email_content = [
|
||||
{'title': 'Discussion', 'help_text': '', 'help_text_url': '', 'notifications': [discussion_notification]},
|
||||
{'title': 'Updates', 'help_text': '', 'help_text_url': '', 'notifications': [update_notification]}
|
||||
{
|
||||
'title': 'Discussion', 'help_text': '', 'help_text_url': '',
|
||||
'notifications': [discussion_notification],
|
||||
'total': 1, 'show_remaining_count': False, 'remaining_count': 0,
|
||||
'url': 'http://learner-home-mfe/?showNotifications=true&app=discussion'
|
||||
},
|
||||
{
|
||||
'title': 'Updates', 'help_text': '', 'help_text_url': '',
|
||||
'notifications': [update_notification],
|
||||
'total': 1, 'show_remaining_count': False, 'remaining_count': 0,
|
||||
'url': 'http://learner-home-mfe/?showNotifications=true&app=updates'
|
||||
}
|
||||
]
|
||||
assert context['start_date'] == expected_start_date
|
||||
assert context['end_date'] == 'Sunday, Mar 24'
|
||||
|
||||
@@ -130,17 +130,29 @@ def create_email_digest_context(app_notifications_dict, username, start_date, en
|
||||
}
|
||||
for key, value in app_notifications_dict.items()
|
||||
])
|
||||
email_content = [
|
||||
{
|
||||
|
||||
email_content = []
|
||||
notifications_in_app = 5
|
||||
for key, value in app_notifications_dict.items():
|
||||
total = value['count']
|
||||
app_content = {
|
||||
'title': value['title'],
|
||||
'help_text': value.get('help_text', ''),
|
||||
'help_text_url': value.get('help_text_url', ''),
|
||||
'notifications': add_additional_attributes_to_notifications(
|
||||
value.get('notifications', []), courses_data=courses_data
|
||||
)
|
||||
),
|
||||
'total': total,
|
||||
'show_remaining_count': False,
|
||||
'remaining_count': 0,
|
||||
'url': f'{settings.LEARNER_HOME_MICROFRONTEND_URL}/?showNotifications=true&app={key}'
|
||||
}
|
||||
for key, value in app_notifications_dict.items()
|
||||
]
|
||||
if total > notifications_in_app:
|
||||
app_content['notifications'] = app_content['notifications'][:notifications_in_app]
|
||||
app_content['show_remaining_count'] = True
|
||||
app_content['remaining_count'] = total - notifications_in_app
|
||||
email_content.append(app_content)
|
||||
|
||||
context.update({
|
||||
"start_date": start_date_str,
|
||||
"end_date": end_date_str,
|
||||
@@ -295,6 +307,7 @@ def filter_notification_with_email_enabled_preferences(notifications, preference
|
||||
for notification in notifications:
|
||||
if notification.notification_type in enabled_course_prefs[notification.course_id]:
|
||||
filtered_notifications.append(notification)
|
||||
filtered_notifications.sort(key=lambda elem: elem.created, reverse=True)
|
||||
return filtered_notifications
|
||||
|
||||
|
||||
|
||||
@@ -56,5 +56,13 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</p>
|
||||
<p style="height: 0.75rem; margin: 0;" />
|
||||
<p style="height: 0.375rem; margin: 0;" />
|
||||
{% if notification_app.show_remaining_count %}
|
||||
<p style="margin: 0; height: 0.75rem; font-weight: 400; font-size: 14px; line-height: 24px;">
|
||||
<a href="{{notification_app.url}}" style="color: #00688d; margin: 0; float:right; text-decoration: none;">
|
||||
+ {{ notification_app.remaining_count }} more
|
||||
</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
<p style="height: 0.375rem; margin: 0;" />
|
||||
{% endfor %}
|
||||
|
||||
Reference in New Issue
Block a user