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

@@ -144,9 +144,8 @@ website_route_rules = [
{"from_route": "/courses/<course>/manage", "to_route": "cohorts"},
{"from_route": "/courses/<course>/cohorts/<cohort>", "to_route": "cohorts/cohort"},
{"from_route": "/courses/<course>/cohorts/<cohort>/<page>", "to_route": "cohorts/cohort"},
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>", "to_route": "cohorts/subgroup", "defaults": {"page": "info"}},
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>/students", "to_route": "cohorts/subgroup", "defaults": {"page": "students"}},
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>/join-requests", "to_route": "cohorts/subgroup", "defaults": {"page": "join-requests"}},
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>", "to_route": "cohorts/subgroup"},
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>/<page>", "to_route": "cohorts/subgroup"},
{"from_route": "/courses/<course>/join/<cohort>/<subgroup>/<invite_code>", "to_route": "cohorts/join"},
{"from_route": "/users", "to_route": "profiles/profile"}
]

View File

@@ -10,7 +10,7 @@ class Cohort(Document):
def get_subgroups(self, include_counts=False, sort_by=None):
names = frappe.get_all("Cohort Subgroup", filters={"cohort": self.name}, pluck="name")
subgroups = [frappe.get_doc("Cohort Subgroup", name) for name in names]
subgroups = [frappe.get_cached_doc("Cohort Subgroup", name) for name in names]
subgroups = sorted(subgroups, key=lambda sg: sg.title)
if include_counts:

View File

@@ -22,7 +22,8 @@
{% endif %}
<ul class="nav nav-tabs">
{{ render_navitem("Subgroups", "", page=page)}}
{% set num_subgroups = cohort.get_subgroups() | length %}
{{ render_navitem("Subgroups", "", page=page, count=num_subgroups) }}
{% for p in cohort.pages %}
{{ render_navitem(p.title, p.slug, page=page) }}
{% endfor %}
@@ -43,14 +44,10 @@
{% for sg in cohort.get_subgroups(include_counts=True) %}
<li class="list-group-item">
<div>
{% if is_admin %}
<a class="subgroup-title"
style="font-weight: 700; color: inherit;"
href="/courses/{{course.name}}/subgroups/{{cohort.slug}}/{{sg.slug}}"
>{{sg.title}}</a>
{% else %}
<span class="subgroup-title">{{sg.title}}</span>
{% endif %}
<a class="subgroup-title"
style="font-weight: 700; color: inherit;"
href="/courses/{{course.name}}/subgroups/{{cohort.slug}}/{{sg.slug}}"
>{{sg.title}}</a>
</div>
<div style="font-size: 0.8em;">
{{sg.num_mentors}} Mentors
@@ -72,7 +69,7 @@
>{{title}}
{% if count != -1 %}
<span
class="badge {{'badge-primary' if active else 'badge-secondary'}}"
class="badge {{'badge-primary' if link==page else 'badge-secondary'}}"
>{{count}}</span>
{% endif %}
</a>

View File

@@ -3,10 +3,6 @@ from . import utils
def get_context(context):
context.no_cache = 1
if frappe.session.user == "Guest":
frappe.local.flags.redirect_location = "/login?redirect-to=" + frappe.request.path
raise frappe.Redirect()
course = utils.get_course()
cohort = course and utils.get_cohort(course, frappe.form_dict["cohort"])
if not cohort:
@@ -18,9 +14,6 @@ def get_context(context):
is_mentor = mentor is not None
is_admin = cohort.is_admin(user) or "System Manager" in frappe.get_roles()
if not is_admin and not is_mentor :
frappe.throw("Permission Deined", frappe.PermissionError)
utils.add_nav(context, "All Courses", "/courses")
utils.add_nav(context, course.title, "/courses/" + course.name)
utils.add_nav(context, "Cohorts", "/courses/" + course.name + "/manage")

View File

@@ -5,29 +5,31 @@
<h2>{{subgroup.title}} <span class="badge badge-secondary">Subgroup</span></h2>
<ul class="nav nav-tabs">
{{ render_navitem("Info", "", -1, page=="info")}}
{{ render_navitem("Mentors", "/mentors", stats.mentors, page=="mentors")}}
{{ render_navitem("Students", "/students", stats.students, page=="students")}}
{{ render_navitem("Requests to join", "/join-requests", stats.join_requests, page=="join-requests")}}
</ul>
{% if is_admin %}
{{ render_navitem("Admin", "/admin", stats.join_requests, page=="admin")}}
{% endif %}
</ul>
<div class="my-5">
{% if page == "info" %}
{{ render_info() }}
{% elif page == "mentors" %}
{{ render_mentors() }}
{% elif page == "students" %}
{{ render_students() }}
{% elif page == "join-requests" %}
{% elif page == "admin" %}
{{ render_join_requests() }}
{% endif %}
</div>
{% endblock %}
{% macro render_info() %}
<h5>Invite Link</h5>
{% set link = subgroup.get_invite_link() %}
<p><a href="{{ link }}" id="invite-link">{{link}}</a>
<br>
<a class="btn btn-seconday btn-sm" id="copy-to-clipboard">Copy to Clipboard</a>
</p>
{% if is_admin %}
{% endif %}
{% endmacro %}
{% macro render_mentors() %}
<h5>Mentors</h5>
{% set mentors = subgroup.get_mentors() %}
{% if mentors %}
@@ -57,7 +59,14 @@
{% macro render_join_requests() %}
{% set join_requests = subgroup.get_join_requests() %}
<h5>Invite Link</h5>
{% set link = subgroup.get_invite_link() %}
<p><a href="{{ link }}" id="invite-link">{{link}}</a>
<br>
<a class="btn btn-seconday btn-sm" id="copy-to-clipboard">Copy to Clipboard</a>
</p>
{% set join_requests = subgroup.get_join_requests() %}
<h5>Pending Requests</h5>
{% if join_requests %}
<table class="table">

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())
}