feat: added undo of rejected join requests

Also improved the dispaly of timestamp, showing the diff now.

Issue #271
This commit is contained in:
Anand Chitipothu
2021-12-04 22:47:23 +05:30
parent e0c73e26ee
commit fb447a30e4
2 changed files with 65 additions and 3 deletions

View File

@@ -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}

View File

@@ -60,6 +60,7 @@
{% macro render_join_requests() %}
{% set join_requests = subgroup.get_join_requests() %}
<h5>Pending Requests</h5>
{% if join_requests %}
<table class="table">
<tr>
@@ -68,10 +69,10 @@
<th>Email</th>
<th>Actions</th>
</tr>
{% for r in subgroup.get_join_requests() %}
{% for r in join_requests %}
<tr>
<td>{{loop.index}}</td>
<td>{{r.creation}}</td>
<td class="timestamp">{{r.creation}}</td>
<td>{{r.email}}</td>
<td
data-name="{{r.name}}"
@@ -81,7 +82,33 @@
{% endfor %}
</table>
{% else %}
<em>There are no pending join requests.</em>
<p><em>There are no pending join requests.</em></p>
{% endif %}
{% set rejected_requests = subgroup.get_join_requests(status="Rejected") %}
<h5>Rejected Requests</h5>
{% if rejected_requests %}
<table class="table">
<tr>
<th>#</th>
<th>When</th>
<th>Email</th>
<th>Actions</th>
</tr>
{% for r in rejected_requests %}
<tr>
<td>{{loop.index}}</td>
<td class="timestamp">{{r.creation}}</td>
<td>{{r.email}}</td>
<td
data-name="{{r.name}}"
data-email="{{r.email}}">
<a class="action-undo" href="#">Undo</a></td>
</tr>
{% endfor %}
</table>
{% else %}
<p><em>There are no rejected requests.</em></p>
{% 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 <strong>${email}</strong>?`, 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,