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() %} +
| 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 %} +
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, |