feat: made all the cohort pages public

There is some info on the page that is only accessible to mentors and
admins and not shown to other users.
This commit is contained in:
Anand Chitipothu
2021-12-05 01:04:46 +05:30
parent fe31a64175
commit 7001ddc96f
6 changed files with 41 additions and 37 deletions

View File

@@ -4,9 +4,6 @@ from . import utils
def get_context(context):
context.no_cache = 1
course = utils.get_course()
if frappe.session.user == "Guest":
frappe.local.flags.redirect_location = "/login?redirect-to=" + frappe.request.path
raise frappe.Redirect()
cohort = utils.get_cohort(course, frappe.form_dict['cohort'])
subgroup = utils.get_subgroup(cohort, frappe.form_dict['subgroup'])
@@ -15,6 +12,13 @@ def get_context(context):
context.template = "www/404.html"
return
page = frappe.form_dict.get("page")
is_admin = subgroup.is_manager(frappe.session.user) or "System Manager" in frappe.get_roles()
if page not in ["mentors", "students", "admin"] or (page == "admin" and not is_admin):
frappe.local.flags.redirect_location = subgroup.get_url() + "/mentors"
raise frappe.Redirect
utils.add_nav(context, "All Courses", "/courses")
utils.add_nav(context, course.title, f"/courses/{course.name}")
utils.add_nav(context, "Cohorts", f"/courses/{course.name}/manage")
@@ -24,10 +28,12 @@ def get_context(context):
context.cohort = cohort
context.subgroup = subgroup
context.stats = get_stats(subgroup)
context.page = frappe.form_dict["page"]
context.page = page
context.is_admin = is_admin
def get_stats(subgroup):
return {
"join_requests": len(subgroup.get_join_requests()),
"students": len(subgroup.get_students())
"students": len(subgroup.get_students()),
"mentors": len(subgroup.get_mentors())
}