mirror of
https://github.com/frappe/lms.git
synced 2026-05-02 13:39:31 +03:00
fix: do not accept json as input for certificate request event
(cherry picked from commit d3a4c211db)
# Conflicts:
# lms/lms/doctype/lms_certificate_request/lms_certificate_request.py
This commit is contained in:
@@ -162,7 +162,8 @@ def is_certified(course):
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_certificate(course: str):
|
||||
if is_certified(course):
|
||||
certificate = is_certified(course)
|
||||
if certificate:
|
||||
return frappe.db.get_value(
|
||||
"LMS Certificate", certificate, ["name", "course", "template"], as_dict=True
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ frappe.ui.form.on("LMS Certificate Request", {
|
||||
frappe.call({
|
||||
method: "lms.lms.doctype.lms_certificate_request.lms_certificate_request.setup_calendar_event",
|
||||
args: {
|
||||
eval: frm.doc,
|
||||
eval_name: frm.doc.name,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -161,38 +161,58 @@ def schedule_evals():
|
||||
},
|
||||
["name", "member", "member_name", "evaluator", "date", "start_time", "end_time"],
|
||||
)
|
||||
for eval in evals:
|
||||
setup_calendar_event(eval)
|
||||
for evaluation in evals:
|
||||
setup_calendar_event(evaluation.name)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def setup_calendar_event(eval: str):
|
||||
if isinstance(eval, str):
|
||||
eval = frappe._dict(json.loads(eval))
|
||||
def setup_calendar_event(eval_name: str):
|
||||
evaluation = frappe.db.get_value(
|
||||
"LMS Certificate Request",
|
||||
eval_name,
|
||||
["name", "member", "member_name", "evaluator", "date", "start_time", "end_time"],
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
<<<<<<< HEAD
|
||||
calendar = frappe.db.get_value("Google Calendar", {"user": eval.evaluator, "enable": 1}, "name")
|
||||
=======
|
||||
is_member = evaluation.member == frappe.session.user
|
||||
roles = frappe.get_roles(frappe.session.user)
|
||||
is_admin = "Moderator" in roles or "Batch Evaluator" in roles
|
||||
|
||||
if not is_member and not is_admin:
|
||||
frappe.throw(
|
||||
_("You do not have permission to set up calendar events for this evaluation."),
|
||||
frappe.PermissionError,
|
||||
)
|
||||
|
||||
calendar = frappe.db.get_value("Google Calendar", {"user": evaluation.evaluator, "enable": 1}, "name")
|
||||
>>>>>>> d3a4c211 (fix: do not accept json as input for certificate request event)
|
||||
|
||||
if calendar:
|
||||
event = create_event(eval)
|
||||
add_participants(eval, event)
|
||||
update_meeting_details(eval, event, calendar)
|
||||
event = create_event(evaluation)
|
||||
add_participants(evaluation, event)
|
||||
update_meeting_details(evaluation, event, calendar)
|
||||
|
||||
|
||||
def create_event(eval: dict):
|
||||
def create_event(evaluation: dict):
|
||||
event = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Event",
|
||||
"subject": f"Evaluation of {eval.member_name}",
|
||||
"starts_on": f"{eval.date} {eval.start_time}",
|
||||
"ends_on": f"{eval.date} {eval.end_time}",
|
||||
"subject": f"Evaluation of {evaluation.member_name}",
|
||||
"starts_on": f"{evaluation.date} {evaluation.start_time}",
|
||||
"ends_on": f"{evaluation.date} {evaluation.end_time}",
|
||||
"reference_doctype": "LMS Certificate Request",
|
||||
"reference_docname": evaluation.name,
|
||||
}
|
||||
)
|
||||
event.save()
|
||||
return event
|
||||
|
||||
|
||||
def add_participants(eval: dict, event: Document):
|
||||
participants = [eval.member, eval.evaluator]
|
||||
def add_participants(evaluation: dict, event: Document):
|
||||
participants = [evaluation.member, evaluation.evaluator]
|
||||
for participant in participants:
|
||||
contact_name = frappe.db.get_value("Contact", {"email_id": participant}, "name")
|
||||
frappe.get_doc(
|
||||
@@ -208,7 +228,7 @@ def add_participants(eval: dict, event: Document):
|
||||
).save()
|
||||
|
||||
|
||||
def update_meeting_details(eval: dict, event: Document, calendar: str):
|
||||
def update_meeting_details(evaluation: dict, event: Document, calendar: str):
|
||||
event.reload()
|
||||
event.update(
|
||||
{
|
||||
@@ -220,7 +240,9 @@ def update_meeting_details(eval: dict, event: Document, calendar: str):
|
||||
|
||||
event.save()
|
||||
event.reload()
|
||||
frappe.db.set_value("LMS Certificate Request", eval.name, "google_meet_link", event.google_meet_link)
|
||||
frappe.db.set_value(
|
||||
"LMS Certificate Request", evaluation.name, "google_meet_link", event.google_meet_link
|
||||
)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
|
||||
Reference in New Issue
Block a user