From be23220e01304a5742446e035be7d4e9ebeb877b Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 29 Sep 2023 17:14:00 +0530 Subject: [PATCH 1/2] feat: lms student role --- lms/install.py | 14 ++++++++++++ .../job_opportunity/job_opportunity.json | 4 ++-- lms/lms/api.py | 10 ++++----- .../cohort_join_request.json | 14 +++++++++++- .../course_chapter/course_chapter.json | 4 ++-- .../doctype/course_lesson/course_lesson.json | 4 ++-- lms/lms/doctype/function/function.json | 7 +++--- lms/lms/doctype/industry/industry.json | 7 +++--- .../lms_enrollment/lms_enrollment.json | 13 ++++++++++- lms/lms/doctype/user_skill/user_skill.json | 7 +++--- lms/lms/test_utils.py | 2 +- lms/lms/utils.py | 2 +- lms/patches.txt | 3 ++- lms/patches/v1_0/create_student_role.py | 22 +++++++++++++++++++ 14 files changed, 88 insertions(+), 25 deletions(-) create mode 100644 lms/patches/v1_0/create_student_role.py diff --git a/lms/install.py b/lms/install.py index 5856b839..459d2c38 100644 --- a/lms/install.py +++ b/lms/install.py @@ -54,6 +54,7 @@ def create_lms_roles(): create_course_creator_role() create_moderator_role() create_evaluator_role() + create_lms_student_role() def delete_lms_roles(): @@ -106,6 +107,19 @@ def create_evaluator_role(): role.save() +def create_lms_student_role(): + if not frappe.db.exists("Role", "LMS Student"): + role = frappe.new_doc("Role") + role.update( + { + "role_name": "LMS Student", + "home_page": "", + "desk_access": 0, + } + ) + role.save() + + def set_default_certificate_print_format(): filters = { "doc_type": "LMS Certificate", diff --git a/lms/job/doctype/job_opportunity/job_opportunity.json b/lms/job/doctype/job_opportunity/job_opportunity.json index 7ac25e65..15bf16b3 100644 --- a/lms/job/doctype/job_opportunity/job_opportunity.json +++ b/lms/job/doctype/job_opportunity/job_opportunity.json @@ -116,7 +116,7 @@ "index_web_pages_for_search": 1, "links": [], "make_attachments_public": 1, - "modified": "2022-09-15 17:22:21.662675", + "modified": "2023-09-29 17:03:30.825021", "modified_by": "Administrator", "module": "Job", "name": "Job Opportunity", @@ -144,7 +144,7 @@ "print": 1, "read": 1, "report": 1, - "role": "All", + "role": "LMS Student", "select": 1, "share": 1, "write": 1 diff --git a/lms/lms/api.py b/lms/lms/api.py index 480809bc..1e68205c 100644 --- a/lms/lms/api.py +++ b/lms/lms/api.py @@ -40,7 +40,7 @@ def save_current_lesson(course_name, lesson_name): return doc = frappe.get_doc("LMS Enrollment", name) doc.current_lesson = lesson_name - doc.save(ignore_permissions=True) + doc.save() return {"current_lesson": doc.current_lesson} @@ -66,7 +66,7 @@ def join_cohort(course, cohort, subgroup, invite_code): return {"ok": True, "status": "record found"} else: doc = frappe.get_doc(data) - doc.insert(ignore_permissions=True) + doc.insert() return {"ok": True, "status": "record created"} @@ -82,7 +82,7 @@ def approve_cohort_join_request(join_request): return {"ok": False, "error": "Permission Deined"} r.status = "Accepted" - r.save(ignore_permissions=True) + r.save() return {"ok": True} @@ -98,7 +98,7 @@ def reject_cohort_join_request(join_request): return {"ok": False, "error": "Permission Deined"} r.status = "Rejected" - r.save(ignore_permissions=True) + r.save() return {"ok": True} @@ -115,7 +115,7 @@ def undo_reject_cohort_join_request(join_request): return {"ok": False, "error": "Permission Deined"} r.status = "Pending" - r.save(ignore_permissions=True) + r.save() return {"ok": True} diff --git a/lms/lms/doctype/cohort_join_request/cohort_join_request.json b/lms/lms/doctype/cohort_join_request/cohort_join_request.json index 8ecd4be3..587d988c 100644 --- a/lms/lms/doctype/cohort_join_request/cohort_join_request.json +++ b/lms/lms/doctype/cohort_join_request/cohort_join_request.json @@ -51,7 +51,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-12-16 15:06:03.985221", + "modified": "2023-09-29 17:08:18.950560", "modified_by": "Administrator", "module": "LMS", "name": "Cohort Join Request", @@ -68,9 +68,21 @@ "role": "System Manager", "share": 1, "write": 1 + }, + { + "create": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "LMS Student", + "share": 1, + "write": 1 } ], "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 } \ No newline at end of file diff --git a/lms/lms/doctype/course_chapter/course_chapter.json b/lms/lms/doctype/course_chapter/course_chapter.json index ee8544bf..ba73237f 100644 --- a/lms/lms/doctype/course_chapter/course_chapter.json +++ b/lms/lms/doctype/course_chapter/course_chapter.json @@ -59,7 +59,7 @@ "link_fieldname": "chapter" } ], - "modified": "2022-03-14 17:57:00.707416", + "modified": "2023-09-29 17:03:58.013819", "modified_by": "Administrator", "module": "LMS", "name": "Course Chapter", @@ -86,7 +86,7 @@ "print": 1, "read": 1, "report": 1, - "role": "All", + "role": "LMS Student", "select": 1, "share": 1, "write": 1 diff --git a/lms/lms/doctype/course_lesson/course_lesson.json b/lms/lms/doctype/course_lesson/course_lesson.json index 4bd3c65d..d5879b00 100644 --- a/lms/lms/doctype/course_lesson/course_lesson.json +++ b/lms/lms/doctype/course_lesson/course_lesson.json @@ -141,7 +141,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-09-27 15:45:54.738573", + "modified": "2023-09-29 17:04:19.252897", "modified_by": "Administrator", "module": "LMS", "name": "Course Lesson", @@ -169,7 +169,7 @@ "print": 1, "read": 1, "report": 1, - "role": "All", + "role": "LMS Student", "select": 1, "share": 1, "write": 1 diff --git a/lms/lms/doctype/function/function.json b/lms/lms/doctype/function/function.json index 918ceb3e..40bf752e 100644 --- a/lms/lms/doctype/function/function.json +++ b/lms/lms/doctype/function/function.json @@ -19,7 +19,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-12-21 09:34:35.018280", + "modified": "2023-09-29 17:04:58.167481", "modified_by": "Administrator", "module": "LMS", "name": "Function", @@ -44,11 +44,12 @@ "print": 1, "read": 1, "report": 1, - "role": "All", + "role": "LMS Student", "select": 1, "share": 1 } ], "sort_field": "modified", - "sort_order": "DESC" + "sort_order": "DESC", + "states": [] } \ No newline at end of file diff --git a/lms/lms/doctype/industry/industry.json b/lms/lms/doctype/industry/industry.json index 2ab23031..5bb770cb 100644 --- a/lms/lms/doctype/industry/industry.json +++ b/lms/lms/doctype/industry/industry.json @@ -19,7 +19,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-12-21 09:35:20.443192", + "modified": "2023-09-29 17:05:27.231982", "modified_by": "Administrator", "module": "LMS", "name": "Industry", @@ -44,11 +44,12 @@ "print": 1, "read": 1, "report": 1, - "role": "All", + "role": "LMS Student", "select": 1, "share": 1 } ], "sort_field": "modified", - "sort_order": "DESC" + "sort_order": "DESC", + "states": [] } \ No newline at end of file diff --git a/lms/lms/doctype/lms_enrollment/lms_enrollment.json b/lms/lms/doctype/lms_enrollment/lms_enrollment.json index 2ebf9161..a0d191e9 100644 --- a/lms/lms/doctype/lms_enrollment/lms_enrollment.json +++ b/lms/lms/doctype/lms_enrollment/lms_enrollment.json @@ -123,7 +123,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-08-24 17:52:35.487141", + "modified": "2023-09-29 17:07:38.695936", "modified_by": "Administrator", "module": "LMS", "name": "LMS Enrollment", @@ -140,6 +140,17 @@ "role": "System Manager", "share": 1, "write": 1 + }, + { + "create": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "LMS Student", + "share": 1, + "write": 1 } ], "quick_entry": 1, diff --git a/lms/lms/doctype/user_skill/user_skill.json b/lms/lms/doctype/user_skill/user_skill.json index ecc08a98..e047b414 100644 --- a/lms/lms/doctype/user_skill/user_skill.json +++ b/lms/lms/doctype/user_skill/user_skill.json @@ -19,7 +19,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-12-21 09:35:44.265910", + "modified": "2023-09-29 17:05:50.502696", "modified_by": "Administrator", "module": "LMS", "name": "User Skill", @@ -44,11 +44,12 @@ "print": 1, "read": 1, "report": 1, - "role": "All", + "role": "LMS Student", "select": 1, "share": 1 } ], "sort_field": "modified", - "sort_order": "DESC" + "sort_order": "DESC", + "states": [] } \ No newline at end of file diff --git a/lms/lms/test_utils.py b/lms/lms/test_utils.py index 3831c5a5..e2ed069d 100644 --- a/lms/lms/test_utils.py +++ b/lms/lms/test_utils.py @@ -72,4 +72,4 @@ def create_evaluation(user, course, date, rating, status): "status": status, } ) - evaluation.save(ignore_permissions=True) + evaluation.save() diff --git a/lms/lms/utils.py b/lms/lms/utils.py index dfefe26f..b3d4e1b9 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -585,7 +585,7 @@ def validate_image(path): if path and "/private" in path: file = frappe.get_doc("File", {"file_url": path}) file.is_private = 0 - file.save(ignore_permissions=True) + file.save() return file.file_url return path diff --git a/lms/patches.txt b/lms/patches.txt index ef457315..40a610ca 100644 --- a/lms/patches.txt +++ b/lms/patches.txt @@ -69,4 +69,5 @@ lms.patches.v1_0.rename_lms_class_to_lms_batch lms.patches.v1_0.rename_classes_in_navbar lms.patches.v1_0.publish_batches lms.patches.v1_0.publish_certificates -lms.patches.v1_0.change_naming_for_batch_course #14-09-2023 \ No newline at end of file +lms.patches.v1_0.change_naming_for_batch_course #14-09-2023 +lms.patches.v1_0.create_student_role \ No newline at end of file diff --git a/lms/patches/v1_0/create_student_role.py b/lms/patches/v1_0/create_student_role.py new file mode 100644 index 00000000..ec0f4e0a --- /dev/null +++ b/lms/patches/v1_0/create_student_role.py @@ -0,0 +1,22 @@ +import frappe +from lms.install import create_lms_student_role + + +def execute(): + create_lms_student_role() + + users = frappe.get_all( + "User", filters={"user_type": "Website User", "enabled": 1}, pluck="name" + ) + + for user in users: + filters = { + "parent": user, + "parenttype": "User", + "parentfield": "roles", + "role": "LMS Student", + } + if not frappe.db.exists("Has Role", filters): + doc = frappe.new_doc("Has Role") + doc.update(filters) + doc.save() From 80843ec44b31595c8b3fd0348797da517455ceb4 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 29 Sep 2023 18:59:08 +0530 Subject: [PATCH 2/2] feat: assign LMS Student role to all signups --- lms/overrides/user.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lms/overrides/user.py b/lms/overrides/user.py index a02db99e..bfc1f49b 100644 --- a/lms/overrides/user.py +++ b/lms/overrides/user.py @@ -235,13 +235,15 @@ def sign_up(email, full_name, verify_terms, user_category): user.flags.ignore_permissions = True user.flags.ignore_password_policy = True user.insert() - set_country_from_ip(None, user.name) # set default signup role as per Portal Settings default_role = frappe.db.get_value("Portal Settings", None, "default_role") if default_role: user.add_roles(default_role) + user.add_roles("LMS Student") + set_country_from_ip(None, user.name) + if user.flags.email_sent: return 1, _("Please check your email for verification") else: