From 4c969420f3fae60fdef579c8ddd733150cae716e Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Tue, 6 Sep 2022 11:19:11 +0530 Subject: [PATCH 1/5] feat: course moderator --- lms/hooks.py | 1 + lms/lms/utils.py | 12 ++++++++++ lms/patches.txt | 1 + .../v0_0/create_course_moderator_role.py | 11 +++++++++ lms/templates/courses_under_review.html | 20 ++++++++++++++++ lms/www/batch/learn.py | 4 ++-- lms/www/courses/course.py | 4 ++-- lms/www/dashboard/index.html | 23 ++++++++++++++++--- lms/www/dashboard/index.py | 3 ++- 9 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 lms/patches/v0_0/create_course_moderator_role.py create mode 100644 lms/templates/courses_under_review.html diff --git a/lms/hooks.py b/lms/hooks.py index 3e1e92d2..e45b76d4 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -192,6 +192,7 @@ jinja = { "lms.lms.utils.get_popular_courses", "lms.lms.utils.format_amount", "lms.lms.utils.first_lesson_exists", + "lms.lms.utils.get_courses_under_review", "lms.lms.utils.has_course_instructor_role" ], "filters": [] diff --git a/lms/lms/utils.py b/lms/lms/utils.py index 5fd64ca3..1eaf9ca3 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -440,3 +440,15 @@ def has_course_instructor_role(): "parent": frappe.session.user, "role": "Course Instructor" }, "name") + + +def has_course_moderator_role(): + return frappe.db.get_value("Has Role", { + "parent": frappe.session.user, + "role": "Course Moderator" + }, "name") + + +def get_courses_under_review(): + return "jan" + diff --git a/lms/patches.txt b/lms/patches.txt index f8a1d28a..8ea2108a 100644 --- a/lms/patches.txt +++ b/lms/patches.txt @@ -31,3 +31,4 @@ lms.patches.v0_0.quiz_submission_member lms.patches.v0_0.delete_old_module_docs #08-07-2022 lms.patches.v0_0.delete_course_web_forms #21-08-2022 lms.patches.v0_0.create_course_instructor_role #29-08-2022 +lms.patches.v0_0.create_course_moderator_role diff --git a/lms/patches/v0_0/create_course_moderator_role.py b/lms/patches/v0_0/create_course_moderator_role.py new file mode 100644 index 00000000..f7127c81 --- /dev/null +++ b/lms/patches/v0_0/create_course_moderator_role.py @@ -0,0 +1,11 @@ +import frappe + +def execute(): + if not frappe.db.exists("Role", "Course Moderator"): + role = frappe.get_doc({ + "doctype": "Role", + "role_name": "Course Moderator", + "home_page": "/dashboard", + "desk_access": 0 + }) + role.save(ignore_permissions=True) diff --git a/lms/templates/courses_under_review.html b/lms/templates/courses_under_review.html new file mode 100644 index 00000000..7b0fa109 --- /dev/null +++ b/lms/templates/courses_under_review.html @@ -0,0 +1,20 @@ +{% set courses = get_courses_under_review() %} + +{% if courses | length %} +
+ {% for course in courses %} + {{ widgets.CourseCard(course=course) }} + {% endfor %} +
+ +{% else %} +
+
+ +
+
+
{{ _("No courses created") }}
+
{{ _("Help others learn something new.") }}
+
+
+{% endif %} diff --git a/lms/www/batch/learn.py b/lms/www/batch/learn.py index b3f59b76..659654dc 100644 --- a/lms/www/batch/learn.py +++ b/lms/www/batch/learn.py @@ -1,6 +1,6 @@ import frappe from lms.www.utils import get_common_context, redirect_to_lesson -from lms.lms.utils import get_lesson_url, is_instructor, redirect_to_courses_list +from lms.lms.utils import get_lesson_url, has_course_moderator_role, is_instructor, redirect_to_courses_list from frappe.utils import cstr, flt def get_context(context): @@ -27,7 +27,7 @@ def get_context(context): context.lesson = frappe._dict() if frappe.form_dict.get("edit"): - if not is_instructor(context.course.name): + if not is_instructor(context.course.name) or has_course_moderator_role(): redirect_to_courses_list() context.lesson.edit_mode = True else: diff --git a/lms/www/courses/course.py b/lms/www/courses/course.py index fb83fd9b..4bf95a8e 100644 --- a/lms/www/courses/course.py +++ b/lms/www/courses/course.py @@ -1,6 +1,6 @@ import frappe from lms.lms.doctype.lms_settings.lms_settings import check_profile_restriction -from lms.lms.utils import get_membership, is_instructor, is_certified, get_evaluation_details, redirect_to_courses_list +from lms.lms.utils import get_membership, has_course_moderator_role, is_instructor, is_certified, get_evaluation_details, redirect_to_courses_list def get_context(context): context.no_cache = 1 @@ -28,7 +28,7 @@ def set_course_context(context, course_name): as_dict=True) if frappe.form_dict.get("edit"): - if not is_instructor(course.name): + if not is_instructor(course.name) or not has_course_moderator_role(): redirect_to_courses_list() course.edit_mode = True diff --git a/lms/www/dashboard/index.html b/lms/www/dashboard/index.html index fb93273d..c7d76e57 100644 --- a/lms/www/dashboard/index.html +++ b/lms/www/dashboard/index.html @@ -16,12 +16,23 @@