diff --git a/school/lms/api.py b/school/lms/api.py index 46518a76..a25f35ea 100644 --- a/school/lms/api.py +++ b/school/lms/api.py @@ -108,3 +108,24 @@ def reject_cohort_join_request(join_request): r.status = "Rejected" r.save(ignore_permissions=True) return {"ok": True} + + +@frappe.whitelist() +def undo_reject_cohort_join_request(join_request): + r = frappe.get_doc("Cohort Join Request", join_request) + sg = r and frappe.get_doc("Cohort Subgroup", r.subgroup) + # keeping Pending as well to consider the case of duplicate requests + if not sg or r.status not in ["Pending", "Rejected"]: + return { + "ok": False, + "error": "Invalid Join Request" + } + if not sg.is_manager(frappe.session.user): + return { + "ok": False, + "error": "Permission Deined" + } + + r.status = "Pending" + r.save(ignore_permissions=True) + return {"ok": True} diff --git a/school/www/cohorts/subgroup.html b/school/www/cohorts/subgroup.html index ea9be393..08c511fc 100644 --- a/school/www/cohorts/subgroup.html +++ b/school/www/cohorts/subgroup.html @@ -60,6 +60,7 @@ {% macro render_join_requests() %} {% set join_requests = subgroup.get_join_requests() %} +
Pending Requests
{% if join_requests %} @@ -68,10 +69,10 @@ - {% for r in subgroup.get_join_requests() %} + {% for r in join_requests %} - +
Email Actions
{{loop.index}}{{r.creation}}{{r.creation}} {{r.email}} {% else %} - There are no pending join requests. +

There are no pending join requests.

+ {% endif %} + {% set rejected_requests = subgroup.get_join_requests(status="Rejected") %} + +
Rejected Requests
+ {% if rejected_requests %} + + + + + + + + {% for r in rejected_requests %} + + + + + + + {% endfor %} +
#WhenEmailActions
{{loop.index}}{{r.creation}}{{r.email}} + Undo
+ {% else %} +

There are no rejected requests.

{% endif %} {% endmacro %} @@ -116,6 +143,12 @@ $(function() { }); }); + $(".timestamp"). each(function() { + var t = moment($(this).text()); + var dt = t.from(moment.now()); + $(this).text(dt); + }); + $(".action-approve").click(function() { var name = $(this).parent().data("name"); var email = $(this).parent().data("email"); @@ -136,6 +169,14 @@ $(function() { }); }); + $(".action-undo").click(function() { + var name = $(this).parent().data("name"); + var email = $(this).parent().data("email"); + frappe.confirm(`Are you sure to undo the rejection of ${email}?`, function() { + run_action("school.lms.api.undo_reject_cohort_join_request", name); + }); + }); + function run_action(method, join_request) { frappe.call(method, { join_request: join_request,