feat: added portal page to join a cohort

Issue #271
This commit is contained in:
Anand Chitipothu
2021-11-30 08:29:24 +05:30
parent 1277cfed64
commit f1157895db
5 changed files with 142 additions and 0 deletions

View File

@@ -45,3 +45,28 @@ def save_current_lesson(course_name, lesson_name):
doc.current_lesson = lesson_name
doc.save(ignore_permissions=True)
return {"current_lesson": doc.current_lesson}
@frappe.whitelist()
def join_cohort(course, cohort, subgroup, invite_code):
"""Creates a Cohort Join Request for given user.
"""
course_doc = frappe.get_doc("LMS Course", course)
cohort_doc = course_doc and course_doc.get_cohort(cohort)
subgroup_doc = cohort_doc and cohort_doc.get_subgroup(subgroup)
if not subgroup_doc or subgroup_doc.invite_code != invite_code:
return {
"ok": False,
"error": "Invalid join link"
}
data = {
"doctype": "Cohort Join Request",
"cohort": cohort_doc.name,
"subgroup": subgroup_doc.name,
"email": frappe.session.user
}
doc = frappe.get_doc(data)
doc.insert(ignore_permissions=True)
return {"ok": True}

View File

@@ -213,6 +213,10 @@ class LMSCourse(Document):
def get_cohorts(self):
return find_all("Cohort", course=self.name, order_by="creation")
def get_cohort(self, cohort_slug):
name = frappe.get_value("Cohort", {"course": self.name, "slug": cohort_slug})
return name and frappe.get_doc("Cohort", name)
def is_cohort_staff(self, user_email):
"""Returns True if the user is either a mentor or a staff for one or more active cohorts of this course.
"""