fix: notification on quiz update and mention

This commit is contained in:
Jannat Patel
2026-01-07 14:28:56 +05:30
parent ea94813d94
commit 45e98b9ddc
12 changed files with 384 additions and 152 deletions
+28 -8
View File
@@ -2,18 +2,21 @@
<div class="mb-4">
<div v-if="label" class="text-xs text-ink-gray-5 mb-2">
{{ __(label) }}
<span class="text-ink-red-3">*</span>
<span v-if="required" class="text-ink-red-3">*</span>
</div>
<FileUploader
v-if="!modelValue"
:fileTypes="['image/*']"
:validateFile="validateFile"
@success="(file: File) => saveImage(file)"
:fileTypes="[fileType]"
:validateFile="(file: File) => validateFile(file, true, type)"
@success="(file: File) => saveFile(file)"
>
<template v-slot="{ file, progress, uploading, openFileSelector }">
<div class="flex items-center">
<div class="border rounded-md w-fit py-7 px-20">
<Image class="size-5 stroke-1 text-ink-gray-7" />
<component
:is="props.type === 'image' ? Image : Video"
class="size-5 stroke-1 text-ink-gray-7"
/>
</div>
<div class="ml-4">
<Button @click="openFileSelector">
@@ -28,7 +31,15 @@
</FileUploader>
<div v-else class="mb-4">
<div class="flex items-center">
<img :src="modelValue" class="border rounded-md w-44 h-auto" />
<img
v-if="type == 'image'"
:src="modelValue"
class="border rounded-md w-44 h-auto"
/>
<video v-else controls class="border rounded-md w-44 h-auto">
<source :src="modelValue" />
{{ __('Your browser does not support the video tag.') }}
</video>
<div class="ml-4">
<Button @click="removeImage()">
{{ __('Remove') }}
@@ -47,7 +58,8 @@
<script setup lang="ts">
import { validateFile } from '@/utils'
import { Button, FileUploader } from 'frappe-ui'
import { Image } from 'lucide-vue-next'
import { Image, Video } from 'lucide-vue-next'
import { computed } from 'vue'
const emit = defineEmits<{
(e: 'update:modelValue', value: string): void
@@ -58,15 +70,23 @@ const props = withDefaults(
modelValue: string
label?: string
description?: string
type: 'image' | 'video'
required?: boolean
}>(),
{
modelValue: '',
label: '',
description: '',
type: 'image',
required: true,
}
)
const saveImage = (file: any) => {
const fileType = computed(() => {
return props.type === 'image' ? 'image/*' : 'video/*'
})
const saveFile = (file: any) => {
emit('update:modelValue', file.file_url)
}
@@ -55,7 +55,7 @@
</div>
</div>
</div>
<div v-else-if class="text-ink-red-3">
<div v-else class="text-ink-red-3">
{{ __('No slots available for the selected course.') }}
</div>
</div>
+49 -101
View File
@@ -202,60 +202,12 @@
/>
</div>
<div class="space-y-5">
<div>
<div class="text-xs text-ink-gray-5">
{{ __('Meta Image') }}
</div>
<FileUploader
v-if="!batch.image"
:fileTypes="['image/*']"
:validateFile="validateFile"
@success="(file) => saveImage(file)"
>
<template
v-slot="{ file, progress, uploading, openFileSelector }"
>
<div class="flex items-center">
<div
class="border rounded-md w-fit py-5 px-5 md:px-20 cursor-pointer"
@click="openFileSelector"
>
<Image class="size-5 stroke-1 text-ink-gray-7" />
</div>
<div class="ml-4">
<Button @click="openFileSelector">
{{ __('Upload') }}
</Button>
<div class="mt-1 text-ink-gray-5 text-sm leading-5">
{{
__('Appears when the batch URL is shared on socials')
}}
</div>
</div>
</div>
</template>
</FileUploader>
<div v-else class="mb-4">
<div class="flex items-center">
<img
:src="batch.image.file_url"
class="border rounded-md w-40"
/>
<div class="ml-4">
<Button @click="removeImage()">
{{ __('Remove') }}
</Button>
<div class="mt-2 text-ink-gray-5 text-sm">
{{
__(
'Appears when the batch URL is shared on any online platform'
)
}}
</div>
</div>
</div>
</div>
</div>
<Uploader
v-model="batch.video_link"
:label="__('Preview Video')"
type="video"
:required="false"
/>
</div>
</div>
</div>
@@ -292,6 +244,12 @@
{{ __('Meta Tags') }}
</div>
<div class="space-y-5">
<Uploader
v-model="batch.meta_image"
:label="__('Meta Image')"
type="image"
:required="false"
/>
<FormControl
v-model="meta.description"
:label="__('Meta Description')"
@@ -345,8 +303,8 @@ import {
openSettings,
sanitizeHTML,
updateMetaInfo,
validateFile,
} from '@/utils'
import Uploader from '@/components/Controls/Uploader.vue'
const router = useRouter()
const user = inject('$user')
@@ -380,11 +338,12 @@ const batch = reactive({
category: '',
allow_self_enrollment: false,
certification: false,
image: null,
meta_image: null,
paid_batch: false,
currency: '',
amount: 0,
zoom_account: '',
video_link: '',
})
const meta = reactive({
@@ -428,7 +387,8 @@ const newBatch = createResource({
return {
doc: {
doctype: 'LMS Batch',
meta_image: batch.image?.file_url,
meta_image: batch.image,
video_link: batch.video_link,
instructors: instructors.value.map((instructor) => ({
instructor: instructor,
})),
@@ -447,39 +407,48 @@ const batchDetail = createResource({
}
},
onSuccess(data) {
Object.keys(data).forEach((key) => {
if (key == 'instructors') {
data.instructors.forEach((instructor) => {
instructors.value.push(instructor.instructor)
})
} else if (['start_time', 'end_time'].includes(key)) {
let [hours, minutes, seconds] = data[key].split(':')
hours = hours.length == 1 ? '0' + hours : hours
batch[key] = `${hours}:${minutes}`
} else if (Object.hasOwn(batch, key)) batch[key] = data[key]
})
let checkboxes = [
'published',
'paid_batch',
'allow_self_enrollment',
'certification',
]
for (let idx in checkboxes) {
let key = checkboxes[idx]
batch[key] = batch[key] ? true : false
}
if (data.meta_image) imageResource.reload({ image: data.meta_image })
updateBatchData(data)
},
})
const updateBatchData = (data) => {
Object.keys(data).forEach((key) => {
if (key == 'instructors') {
data.instructors.forEach((instructor) => {
instructors.value.push(instructor.instructor)
})
} else if (['start_time', 'end_time'].includes(key)) {
batch[key] = formatTime(data[key])
} else if (Object.hasOwn(batch, key)) batch[key] = data[key]
})
let checkboxes = [
'published',
'paid_batch',
'allow_self_enrollment',
'certification',
]
for (let idx in checkboxes) {
let key = checkboxes[idx]
batch[key] = batch[key] ? true : false
}
}
const formatTime = (timeStr) => {
let [hours, minutes, seconds] = timeStr.split(':')
hours = hours.length == 1 ? '0' + hours : hours
return `${hours}:${minutes}`
}
const editBatch = createResource({
url: 'frappe.client.set_value',
makeParams(values) {
console.log(batch.meta_image, batch.video_link)
return {
doctype: 'LMS Batch',
name: props.batchName,
fieldname: {
meta_image: batch.image?.file_url,
meta_image: batch.meta_image,
video_link: batch.video_link,
instructors: instructors.value.map((instructor) => ({
instructor: instructor,
})),
@@ -489,19 +458,6 @@ const editBatch = createResource({
},
})
const imageResource = createResource({
url: 'lms.lms.api.get_file_info',
makeParams(values) {
return {
file_url: values.image,
}
},
auto: false,
onSuccess(data) {
batch.image = data
},
})
const validateFields = () => {
batch.description = sanitizeHTML(batch.description)
batch.batch_details = sanitizeHTML(batch.batch_details)
@@ -603,14 +559,6 @@ const trashBatch = (close) => {
})
}
const saveImage = (file) => {
batch.image = file
}
const removeImage = () => {
batch.image = null
}
const breadcrumbs = computed(() => {
let crumbs = [
{
+91 -17
View File
@@ -23,14 +23,19 @@
v-if="notifications?.length"
v-for="log in notifications"
:key="log.name"
class="flex space-x-2 p-2 rounded-md"
class="flex space-x-2 px-2 py-4"
:class="{
'cursor-pointer': log.link,
'items-center': !showDetails(log) && !isMention(log),
}"
@click="navigateToPage(log)"
>
<Avatar :image="log.user_image" size="2xl" :label="log.full_name" />
<div class="space-y-2">
<Avatar
:image="log.from_user_details.user_image"
size="xl"
:label="log.from_user_details.full_name"
/>
<div class="space-y-2 w-full">
<div class="flex items-center justify-between">
<div class="flex items-center">
<div class="text-ink-gray-9" v-html="log.subject"></div>
@@ -42,7 +47,7 @@
<Button
variant="ghost"
v-if="!log.read"
@click.stop="(e) => handleMarkAsRead(e, log.name)"
@click.stop="(e) => handleMarkAsRead(log.name)"
>
<template #icon>
<X class="h-4 w-4 text-ink-gray-7 stroke-1.5" />
@@ -51,19 +56,39 @@
</div>
</div>
<div
v-if="log.document_type == 'LMS Course' && log.document_details"
class="flex space-x-5 border border-outline-gray-2 p-2 rounded-md"
v-if="isMention(log)"
v-html="log.email_content"
class="bg-surface-gray-2 rounded-md px-3 py-2"
></div>
<div
v-else-if="showDetails(log)"
class="flex items-stretch border border-outline-gray-2 space-x-2 rounded-md"
>
<iframe
v-if="log.document_details.video_link"
v-if="
log.document_type == 'LMS Course' &&
log.document_details.video_link
"
:src="`https://www.youtube.com/embed/${log.document_details.video_link}`"
class="rounded-md w-64"
class="rounded-l-md w-72"
/>
<div class="">
<video
v-else-if="
log.document_type == 'LMS Batch' &&
log.document_details.video_link
"
:src="log.document_details.video_link"
class="rounded-l-md w-72"
/>
<div class="p-3">
<div
class="bg-surface-violet-1 w-fit py-1 px-1.5 rounded-full text-ink-violet-1 text-sm mb-2"
>
{{ __('New Course') }}
{{
log.document_type === 'LMS Course'
? __('New Course')
: __('New Batch')
}}
</div>
<div class="font-semibold mb-1">
{{ __(log.document_details.title) }}
@@ -71,7 +96,31 @@
<div class="leading-5">
{{ __(log.document_details.short_introduction) }}
</div>
<div class="mt-5 space-y-2">
<div
v-if="log.document_details.start_date"
class="flex items-center space-x-2 text-sm mt-5"
>
<Calendar class="size-3 stroke-1.5" />
<span>
{{
dayjs(log.document_details.start_date).format('DD MMM YYYY')
}}
</span>
</div>
<div
v-if="log.document_details.start_time"
class="flex items-center space-x-2 text-sm mt-2"
>
<Clock class="size-3 stroke-1.5" />
<span>
{{ formatTime(log.document_details.start_time) }}
{{ log.document_details.timezone }}
</span>
</div>
<div
v-if="log.document_details.instructors.length > 1"
class="space-y-2 mt-5"
>
<div
v-for="instructor in log.document_details.instructors"
class="flex items-center space-x-2"
@@ -81,7 +130,7 @@
:image="instructor.user_image"
:label="instructor.full_name"
/>
<span class="text-ink-gray-7 text-sm">
<span class="font-medium text-sm">
{{ instructor.full_name }}
</span>
</div>
@@ -109,7 +158,8 @@ import {
import { sessionStore } from '../stores/session'
import { computed, inject, ref, onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import { X } from 'lucide-vue-next'
import { Calendar, Clock, X } from 'lucide-vue-next'
import { formatTime } from '@/utils/'
const { brand } = sessionStore()
const user = inject('$user')
@@ -189,13 +239,37 @@ const navigateToPage = (log) => {
params: { courseName: link[3] },
})
} else if (link[2] == 'batches') {
router.push({
name: 'Batch',
params: { batchName: link[3] },
})
if (link[3] == 'details') {
router.push({
name: 'BatchDetail',
params: { batchName: link[4] },
})
} else {
router.push({
name: 'Batch',
params: { batchName: link[3] },
})
}
}
}
const isMention = (log) => {
if (log.type == 'Mention') {
return true
}
if (log.subject.includes('mentioned you')) {
return true
}
return false
}
const showDetails = (log) => {
return (
['LMS Course', 'LMS Batch'].includes(log.document_type) &&
log.document_details
)
}
onUnmounted(() => {
socket.off('publish_lms_notifications')
})
+8 -4
View File
@@ -618,15 +618,19 @@ export function singularize(word) {
)
}
export const validateFile = async (file, showToast = true) => {
export const validateFile = async (
file,
showToast = true,
fileType = 'image'
) => {
const error = (msg) => {
if (showToast) toast.error(msg)
console.error(msg)
return msg
}
if (!file.type.startsWith('image/')) {
return error(__('Only image file is allowed.'))
console.log(file.type, fileType)
if (!file.type.startsWith(`${fileType}/`)) {
return error(__(`Only ${fileType} file is allowed.`))
}
if (file.type === 'image/svg+xml') {
+51 -6
View File
@@ -1238,25 +1238,51 @@ def get_notifications(filters):
notifications = frappe.get_all(
"Notification Log",
filters,
["subject", "from_user", "link", "read", "name", "creation", "document_type", "document_name"],
[
"subject",
"from_user",
"link",
"read",
"name",
"creation",
"document_type",
"document_name",
"type",
"email_content",
],
order_by="creation desc",
)
for notification in notifications:
notification = update_user_details(notification)
notification = update_document_details(notification)
notification = update_user_details(notification)
return notifications
def update_user_details(notification):
from_user_details = frappe.db.get_value(
"User", notification.from_user, ["full_name", "user_image"], as_dict=1
)
notification.update(from_user_details)
if (
notification.document_details
and len(notification.document_details.get("instructors", []))
and not is_mention(notification)
):
from_user_details = notification.document_details["instructors"][0]
else:
from_user_details = frappe.db.get_value(
"User", notification.from_user, ["full_name", "user_image"], as_dict=1
)
notification["from_user_details"] = from_user_details
return notification
def is_mention(notification):
if notification.type == "Mention":
return True
if "mentioned you" in notification.subject.lower():
return True
return False
def update_document_details(notification):
if notification.document_type == "LMS Course":
details = frappe.db.get_value(
@@ -1265,6 +1291,25 @@ def update_document_details(notification):
instructors = get_instructors("LMS Course", notification.document_name)
details["instructors"] = instructors
notification["document_details"] = details
elif notification.document_type == "LMS Batch":
details = frappe.db.get_value(
"LMS Batch",
notification.document_name,
[
"title",
"description as short_introduction",
"video_link",
"start_date",
"end_date",
"start_time",
"timezone",
],
as_dict=1,
)
instructors = get_instructors("LMS Batch", notification.document_name)
details["instructors"] = instructors
notification["document_details"] = details
return notification
+7 -1
View File
@@ -26,6 +26,7 @@
"description",
"column_break_hlqw",
"instructors",
"video_link",
"zoom_account",
"section_break_rgfj",
"medium",
@@ -361,6 +362,11 @@
"fieldtype": "Link",
"label": "Zoom Account",
"options": "LMS Zoom Settings"
},
{
"fieldname": "video_link",
"fieldtype": "Attach",
"label": "Preview Video"
}
],
"grid_page_length": 50,
@@ -383,7 +389,7 @@
"link_fieldname": "payment_for_document"
}
],
"modified": "2025-12-23 11:27:00.424331",
"modified": "2026-01-06 18:54:22.216656",
"modified_by": "sayali@frappe.io",
"module": "LMS",
"name": "LMS Batch",
+80
View File
@@ -8,12 +8,14 @@ from datetime import timedelta
import frappe
import requests
from frappe import _
from frappe.desk.doctype.notification_log.notification_log import make_notification_logs
from frappe.model.document import Document
from frappe.utils import add_days, cint, format_datetime, get_time, nowdate
from lms.lms.utils import (
generate_slug,
get_assignment_details,
get_instructors,
get_lesson_index,
get_lesson_url,
get_quiz_details,
@@ -33,6 +35,10 @@ class LMSBatch(Document):
self.validate_timetable()
self.validate_evaluation_end_date()
def on_update(self):
if self.has_value_changed("published") and self.published:
frappe.enqueue(send_notification_for_published_batch, batch=self, now=True)
def autoname(self):
if not self.name:
self.name = generate_slug(self.title, "LMS Batch")
@@ -123,6 +129,80 @@ class LMSBatch(Document):
update_payment_record("LMS Batch", self.name)
def send_notification_for_published_batch(batch):
send_notification = frappe.db.get_single_value("LMS Settings", "send_notification_for_published_batches")
if not send_notification:
return
if not batch.published:
return
if send_notification == "Email":
send_email_notification_for_published_batch(batch)
else:
send_system_notification_for_published_batch(batch)
def send_email_notification_for_published_batch(batch):
brand_name = frappe.db.get_single_value("Website Settings", "app_name")
brand_logo = frappe.db.get_single_value("Website Settings", "banner_image")
subject = _("A new course has been published on {0}").format(brand_name)
template = "published_batch_notification"
students = frappe.get_all("User", {"enabled": 1}, pluck="name")
instructors = get_instructors("LMS Batch", batch.name)
args = {
"brand_logo": brand_logo,
"brand_name": brand_name,
"title": batch.title,
"short_introduction": batch.description,
"start_date": batch.start_date,
"end_date": batch.end_date,
"start_time": batch.start_time,
"medium": batch.medium,
"timezone": batch.timezone,
"instructors": instructors,
"batch_url": f"{frappe.utils.get_url()}/lms/batches/details/{batch.name}",
}
frappe.sendmail(
recipients=instructors,
bcc=students,
subject=subject,
template=template,
args=args,
)
""" frappe.sendmail(
recipients=["jannat@frappe.io"],
subject=subject,
template=template,
args=args,
) """
def send_system_notification_for_published_batch(batch):
students = frappe.get_all("User", {"enabled": 1}, pluck="name")
instructors = frappe.get_all("Course Instructor", {"parent": batch.name}, pluck="instructor")
instructor_name = frappe.db.get_value("User", instructors[0], "full_name")
notification = frappe._dict(
{
"subject": _("{0} has published a new batch {1}").format(
frappe.bold(instructor_name), frappe.bold(batch.title)
),
"email_content": _(
"A new batch '{0}' has been published that might interest you. Check it out!"
).format(batch.title),
"document_type": "LMS Batch",
"document_name": batch.name,
"from_user": instructors[0] if instructors else None,
"type": "Alert",
"link": f"/lms/batches/details/{batch.name}",
}
)
make_notification_logs(notification, students)
@frappe.whitelist()
def create_live_class(
batch_name,
+4 -7
View File
@@ -134,10 +134,8 @@ class LMSCourse(Document):
def send_notification_for_published_courses():
send_notification_for_published_courses = frappe.db.get_single_value(
"LMS Settings", "send_notification_for_published_courses"
)
if not send_notification_for_published_courses:
send_notification = frappe.db.get_single_value("LMS Settings", "send_notification_for_published_courses")
if not send_notification:
return
courses_published_today = frappe.get_all(
@@ -145,13 +143,13 @@ def send_notification_for_published_courses():
{
"published_on": today(),
},
["name", "title", "video_link", "short_introduction"],
["name", "title", "short_introduction"],
)
if not courses_published_today:
return
if send_notification_for_published_courses == "Email":
if send_notification == "Email":
send_email_notification_for_published_courses(courses_published_today)
else:
send_system_notification_for_published_courses(courses_published_today)
@@ -170,7 +168,6 @@ def send_email_notification_for_published_courses(courses):
args = {
"brand_logo": brand_logo,
"brand_name": brand_name,
"preview_video": f"https://www.youtube.com/embed/{course.video_link}",
"title": course.title,
"short_introduction": course.short_introduction,
"instructors": instructors,
@@ -54,15 +54,15 @@ class LMSQuizSubmission(Document):
notification = frappe._dict(
{
"subject": _("You have got a score of {0} for the quiz {1}").format(
self.score, self.quiz_title
(frappe.bold(self.score)), frappe.bold(self.quiz_title)
),
"email_content": _(
"There has been an update on your submission. You have got a score of {0} for the quiz {1}"
).format(self.score, self.quiz_title),
).format(frappe.bold(self.score), frappe.bold(self.quiz_title)),
"document_type": self.doctype,
"document_name": self.name,
"for_user": self.member,
"from_user": "Administrator",
"from_user": frappe.session.user,
"type": "Alert",
"link": "",
}
+8 -4
View File
@@ -444,12 +444,16 @@ def notify_mentions_on_portal(doc, topic):
if topic.reference_doctype == "Course Lesson":
course = frappe.db.get_value("Course Lesson", topic.reference_docname, "course")
subject = _("{0} mentioned you in a comment in {1}").format(from_user_name, topic.title)
subject = _("{0} mentioned you in a comment in {1}").format(
frappe.bold(from_user_name), frappe.bold(topic.title)
)
link = get_lesson_url(course, get_lesson_index(topic.reference_docname))
else:
batch_title = frappe.db.get_value("LMS Batch", topic.reference_docname, "title")
subject = _("{0} mentioned you in a comment in {1}").format(from_user_name, batch_title)
link = f"/batches/{topic.reference_docname}"
subject = _("{0} mentioned you in a comment in {1}").format(
frappe.bold(from_user_name), frappe.bold(batch_title)
)
link = f"/lms/batches/{topic.reference_docname}"
for user in mentions:
notification = frappe._dict(
@@ -460,7 +464,7 @@ def notify_mentions_on_portal(doc, topic):
"document_name": topic.reference_docname,
"for_user": user,
"from_user": doc.owner,
"type": "Alert",
"type": "Mention",
"link": link,
}
)
@@ -0,0 +1,54 @@
<div style="width: 70%; margin: 0 auto;">
<img src="{{ brand_logo }}" style="width: 30px; height: 30px;" />
<p style="font-size: 16px; font-weight: 600;">
{{ _("Hello Learner") }},
</p>
<p>
{{ _("A new batch has been published on ")}} {{ brand_name }} {{ _("that might interest you!") }} {{ _("Here are the details:") }}
</p>
<div style="background-color: #F8F8F8; border-radius: 12px; padding: 12px; margin-bottom: 6px;">
<div style="font-weight: 600; margin-bottom: 6px; font-size: 15px;">
{{ title }}
</div>
<div>
{{ short_introduction }}
</div>
<div style="margin-top: 20px; font-size: 13px;">
{% if end_date %}
<span>
{{ _("From ") }} {{ frappe.utils.format_date(start_date, "dd MMM YYYY") }} {{ _(" to ") }} {{ frappe.utils.format_date(end_date, "dd MMM YYYY") }}
</span>
{% else %}
<span>
{{ frappe.utils.format_date(start_date, "dd MMM YYYY") }}
</span>
{% endif %}
</div>
<div style="color: #525252; margin-top: 4px; font-size: 13px;">
<span>
{{ _("Time: ") }} {{ frappe.utils.format_time(start_time, "HH:mm a") }} {{ timezone }}
</span>
</div>
<div style="margin-top: 20px;">
{% for instructor in instructors %}
<div style="display: flex; align-items: center; margin-bottom: 5px;">
{% if instructor.user_image %}
<img src="{{ instructor.user_image }}" style="width: 20px; height: 20px; border-radius: 50%; margin-right: 5px;" />
{% else %}
<div style="width: 20px; height: 20px; border-radius: 50%; background-color: #ccc; display: flex; align-items: center; justify-content: center; margin-right: 5px;">
<span style="font-size: 12px; color: #fff;">
{{ instructor.full_name.split("")[0] | upper }}
</span>
</div>
{% endif %}
<div>
{{ instructor.full_name }}
</div>
</div>
{% endfor %}
</div>
</div>
<a href="{{ batch_url }}" style="display: inline-block; padding: 4px 8px; background-color: #171717; color: #fff; text-decoration: none; cursor: pointer; border-radius: 8px; margin-top: 10px;">
{{ _("Checkout the batch") }}
</a>
</div>