From a0255e174370b27590277e180571c89029aefe70 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Wed, 11 Oct 2023 12:58:07 +0530 Subject: [PATCH 01/21] feat: send email to batch students --- .../doctype/lms_assignment/lms_assignment.py | 4 ++-- lms/lms/doctype/lms_course/lms_course.py | 2 +- lms/lms/doctype/lms_quiz/lms_quiz.py | 8 +++++-- lms/lms/utils.py | 22 +++++++++++++++---- lms/www/assignments/assignment.py | 4 ++-- lms/www/batch/quiz.py | 4 ++-- lms/www/batch/quiz_list.py | 4 ++-- lms/www/courses/course.py | 2 +- lms/www/courses/create.py | 2 +- lms/www/courses/index.py | 7 ++++-- 10 files changed, 40 insertions(+), 19 deletions(-) diff --git a/lms/lms/doctype/lms_assignment/lms_assignment.py b/lms/lms/doctype/lms_assignment/lms_assignment.py index 647833de..b4aaedbf 100644 --- a/lms/lms/doctype/lms_assignment/lms_assignment.py +++ b/lms/lms/doctype/lms_assignment/lms_assignment.py @@ -3,7 +3,7 @@ import frappe from frappe.model.document import Document -from lms.lms.utils import can_create_courses +from lms.lms.utils import has_course_moderator_role, has_course_instructor_role class LMSAssignment(Document): @@ -12,7 +12,7 @@ class LMSAssignment(Document): @frappe.whitelist() def save_assignment(assignment, title, type, question): - if not can_create_courses(): + if not has_course_moderator_role() or not has_course_instructor_role(): return if assignment: diff --git a/lms/lms/doctype/lms_course/lms_course.py b/lms/lms/doctype/lms_course/lms_course.py index 74ccc51a..9065b639 100644 --- a/lms/lms/doctype/lms_course/lms_course.py +++ b/lms/lms/doctype/lms_course/lms_course.py @@ -216,7 +216,7 @@ def save_course( course_price=None, currency=None, ): - if not can_create_courses(): + if not can_create_courses(course): return if course: diff --git a/lms/lms/doctype/lms_quiz/lms_quiz.py b/lms/lms/doctype/lms_quiz/lms_quiz.py index 9cb5789c..e6794843 100644 --- a/lms/lms/doctype/lms_quiz/lms_quiz.py +++ b/lms/lms/doctype/lms_quiz/lms_quiz.py @@ -6,7 +6,11 @@ import frappe from frappe import _ from frappe.model.document import Document from frappe.utils import cstr -from lms.lms.utils import generate_slug, has_course_moderator_role, can_create_courses +from lms.lms.utils import ( + generate_slug, + has_course_moderator_role, + has_course_instructor_role, +) class LMSQuiz(Document): @@ -148,7 +152,7 @@ def quiz_summary(quiz, results): def save_quiz( quiz_title, max_attempts=1, quiz=None, show_answers=1, show_submission_history=0 ): - if not can_create_courses(): + if not has_course_moderator_role() or not has_course_instructor_role(): return values = { diff --git a/lms/lms/utils.py b/lms/lms/utils.py index b3d4e1b9..f7dbe489 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -521,21 +521,35 @@ def has_course_instructor_role(member=None): ) -def can_create_courses(member=None): +def can_create_courses(course, member=None): if not member: member = frappe.session.user + instructors = frappe.get_all( + "Course Instructor", + { + "parent": course, + }, + pluck="instructor", + ) + if frappe.session.user == "Guest": return False - if has_course_instructor_role(member) or has_course_moderator_role(member): + if has_course_moderator_role(member): + return True + + if has_course_instructor_role(member) and member in instructors: return True portal_course_creation = frappe.db.get_single_value( "LMS Settings", "portal_course_creation" ) - return portal_course_creation == "Anyone" + if portal_course_creation == "Anyone" and member in instructors: + return True + + return False def has_course_moderator_role(member=None): @@ -727,7 +741,7 @@ def get_chart_data(chart_name, timespan, timegrain, from_date, to_date): } -@frappe.whitelist() +@frappe.whitelist(allow_guest=True) def get_course_completion_data(): all_membership = frappe.db.count("LMS Enrollment") completed = frappe.db.count("LMS Enrollment", {"progress": ["like", "%100%"]}) diff --git a/lms/www/assignments/assignment.py b/lms/www/assignments/assignment.py index 9b1c299d..ec8cc543 100644 --- a/lms/www/assignments/assignment.py +++ b/lms/www/assignments/assignment.py @@ -1,12 +1,12 @@ import frappe from frappe import _ -from lms.lms.utils import can_create_courses +from lms.lms.utils import has_course_moderator_role, has_course_instructor_role def get_context(context): context.no_cache = 1 - if not can_create_courses(): + if not has_course_moderator_role() or not has_course_instructor_role(): message = "You do not have permission to access this page." if frappe.session.user == "Guest": message = "Please login to access this page." diff --git a/lms/www/batch/quiz.py b/lms/www/batch/quiz.py index f88aaef5..52d0634f 100644 --- a/lms/www/batch/quiz.py +++ b/lms/www/batch/quiz.py @@ -1,13 +1,13 @@ import frappe from frappe.utils import cstr from frappe import _ -from lms.lms.utils import can_create_courses +from lms.lms.utils import has_course_instructor_role, has_course_moderator_role def get_context(context): context.no_cache = 1 - if not can_create_courses(): + if not has_course_moderator_role() or not has_course_instructor_role(): message = "You do not have permission to access this page." if frappe.session.user == "Guest": message = "Please login to access this page." diff --git a/lms/www/batch/quiz_list.py b/lms/www/batch/quiz_list.py index ae8df7fc..ee4321a7 100644 --- a/lms/www/batch/quiz_list.py +++ b/lms/www/batch/quiz_list.py @@ -1,12 +1,12 @@ import frappe -from lms.lms.utils import can_create_courses, has_course_moderator_role +from lms.lms.utils import has_course_instructor_role, has_course_moderator_role from frappe import _ def get_context(context): context.no_cache = 1 - if not can_create_courses(): + if not has_course_moderator_role() or not has_course_instructor_role(): message = "You do not have permission to access this page." if frappe.session.user == "Guest": message = "Please login to access this page." diff --git a/lms/www/courses/course.py b/lms/www/courses/course.py index b4aa476c..b64395eb 100644 --- a/lms/www/courses/course.py +++ b/lms/www/courses/course.py @@ -23,7 +23,7 @@ def get_context(context): redirect_to_courses_list() if course_name == "new-course": - if not can_create_courses(): + if not can_create_courses(course_name): message = "You do not have permission to access this page." if frappe.session.user == "Guest": message = "Please login to access this page." diff --git a/lms/www/courses/create.py b/lms/www/courses/create.py index 901ce1f2..7b83f3f5 100644 --- a/lms/www/courses/create.py +++ b/lms/www/courses/create.py @@ -15,7 +15,7 @@ def get_context(context): except KeyError: redirect_to_courses_list() - if not can_create_courses(): + if not can_create_courses(course_name): message = "You do not have permission to access this page." if frappe.session.user == "Guest": message = "Please login to access this page." diff --git a/lms/www/courses/index.py b/lms/www/courses/index.py index d887e1ca..62474be0 100644 --- a/lms/www/courses/index.py +++ b/lms/www/courses/index.py @@ -1,7 +1,6 @@ import frappe from frappe import _ from lms.lms.utils import ( - can_create_courses, check_profile_restriction, get_restriction_details, has_course_moderator_role, @@ -21,7 +20,11 @@ def get_context(context): context.created_courses = get_authored_courses(None, False) context.review_courses = get_courses_under_review() context.restriction = check_profile_restriction() - context.show_creators_section = can_create_courses() + + portal_course_creation = frappe.db.get_single_value( + "LMS Settings", "portal_course_creation" + ) + context.show_creators_section = True if portal_course_creation == "Anyone" else False context.show_review_section = ( has_course_moderator_role() and frappe.session.user != "Guest" ) From f3d6ad6c849fa20f1c9a1d9f34274b7a5e3495c5 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Wed, 11 Oct 2023 13:40:07 +0530 Subject: [PATCH 02/21] fix: course permissions --- lms/www/courses/index.py | 9 ++++++++- lms/www/courses/outline.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lms/www/courses/index.py b/lms/www/courses/index.py index 62474be0..7df2a960 100644 --- a/lms/www/courses/index.py +++ b/lms/www/courses/index.py @@ -7,6 +7,7 @@ from lms.lms.utils import ( get_courses_under_review, get_average_rating, check_multicurrency, + has_course_instructor_role, ) from lms.overrides.user import get_enrolled_courses, get_authored_courses @@ -24,7 +25,13 @@ def get_context(context): portal_course_creation = frappe.db.get_single_value( "LMS Settings", "portal_course_creation" ) - context.show_creators_section = True if portal_course_creation == "Anyone" else False + context.show_creators_section = ( + True + if portal_course_creation == "Anyone" + or has_course_moderator_role() + or has_course_instructor_role() + else False + ) context.show_review_section = ( has_course_moderator_role() and frappe.session.user != "Guest" ) diff --git a/lms/www/courses/outline.py b/lms/www/courses/outline.py index ad8f18d9..f01a71af 100644 --- a/lms/www/courses/outline.py +++ b/lms/www/courses/outline.py @@ -10,7 +10,7 @@ def get_context(context): if not frappe.db.exists("LMS Course", course_name): redirect_to_courses_list() - if not can_create_courses(): + if not can_create_courses(course_name): message = "You do not have permission to access this page." if frappe.session.user == "Guest": message = "Please login to access this page." From a7dbdd844b2a9d2e13752edb1c90f211b95bd8c3 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 12 Oct 2023 21:20:36 +0530 Subject: [PATCH 03/21] feat: batch customisations --- .github/workflows/ci.yml | 2 +- lms/lms/doctype/lms_batch/lms_batch.js | 110 ++++++++++++------ lms/lms/doctype/lms_batch/lms_batch.json | 18 ++- .../doctype/lms_timetable_legend/__init__.py | 0 .../lms_timetable_legend.js | 8 ++ .../lms_timetable_legend.json | 52 +++++++++ .../lms_timetable_legend.py | 9 ++ .../test_lms_timetable_legend.py | 9 ++ .../lms_timetable_template.js | 14 +++ .../lms_timetable_template.json | 11 +- lms/www/batches/batch.html | 4 +- lms/www/batches/batch.js | 30 +++-- lms/www/batches/batch.py | 28 ++--- 13 files changed, 226 insertions(+), 69 deletions(-) create mode 100644 lms/lms/doctype/lms_timetable_legend/__init__.py create mode 100644 lms/lms/doctype/lms_timetable_legend/lms_timetable_legend.js create mode 100644 lms/lms/doctype/lms_timetable_legend/lms_timetable_legend.json create mode 100644 lms/lms/doctype/lms_timetable_legend/lms_timetable_legend.py create mode 100644 lms/lms/doctype/lms_timetable_legend/test_lms_timetable_legend.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aafbfa01..1c0c28c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: ports: - 12000:6379 mariadb: - image: anandology/mariadb-utf8mb4:10.3 + image: mariadb:10.6 ports: - 3306:3306 env: diff --git a/lms/lms/doctype/lms_batch/lms_batch.js b/lms/lms/doctype/lms_batch/lms_batch.js index f7273fc1..1a95c493 100644 --- a/lms/lms/doctype/lms_batch/lms_batch.js +++ b/lms/lms/doctype/lms_batch/lms_batch.js @@ -12,12 +12,16 @@ frappe.ui.form.on("LMS Batch", { }); frm.set_query("reference_doctype", "timetable", function () { - let doctypes = [ - "Course Lesson", - "LMS Quiz", - "LMS Assignment", - "LMS Live Class", - ]; + let doctypes = ["Course Lesson", "LMS Quiz", "LMS Assignment"]; + return { + filters: { + name: ["in", doctypes], + }, + }; + }); + + frm.set_query("reference_doctype", "timetable_legends", function () { + let doctypes = ["Course Lesson", "LMS Quiz", "LMS Assignment"]; return { filters: { name: ["in", doctypes], @@ -27,36 +31,41 @@ frappe.ui.form.on("LMS Batch", { }, timetable_template: function (frm) { - if (frm.doc.timetable_template) { - frm.clear_table("timetable"); - frm.refresh_fields(); - - frappe.call({ - method: "frappe.client.get_list", - args: { - doctype: "LMS Batch Timetable", - parent: "LMS Timetable Template", - fields: [ - "reference_doctype", - "reference_docname", - "day", - "start_time", - "end_time", - "duration", - ], - filters: { - parent: frm.doc.timetable_template, - }, - order_by: "idx", - }, - callback: (data) => { - add_timetable_rows(frm, data.message); - }, - }); - } + set_timetable(frm); }, }); +const set_timetable = (frm) => { + if (frm.doc.timetable_template) { + frm.clear_table("timetable"); + frm.refresh_fields(); + + frappe.call({ + method: "frappe.client.get_list", + args: { + doctype: "LMS Batch Timetable", + parent: "LMS Timetable Template", + fields: [ + "reference_doctype", + "reference_docname", + "day", + "start_time", + "end_time", + "duration", + ], + filters: { + parent: frm.doc.timetable_template, + parenttype: "LMS Timetable Template", + }, + order_by: "idx", + }, + callback: (data) => { + add_timetable_rows(frm, data.message); + }, + }); + } +}; + const add_timetable_rows = (frm, timetable) => { timetable.forEach((row) => { let child = frm.add_child("timetable"); @@ -75,5 +84,40 @@ const add_timetable_rows = (frm, timetable) => { child.duration = row.duration; }); frm.refresh_field("timetable"); + + set_legends(frm); +}; + +const set_legends = (frm) => { + if (frm.doc.timetable_template) { + frm.clear_table("timetable_legends"); + frm.refresh_fields(); + frappe.call({ + method: "frappe.client.get_list", + args: { + doctype: "LMS Timetable Legend", + parent: "LMS Timetable Template", + fields: ["reference_doctype", "label", "color"], + filters: { + parent: frm.doc.timetable_template, + parenttype: "LMS Timetable Template", + }, + order_by: "idx", + }, + callback: (data) => { + add_legend_rows(frm, data.message); + }, + }); + } +}; + +const add_legend_rows = (frm, legends) => { + legends.forEach((row) => { + let child = frm.add_child("timetable_legends"); + child.reference_doctype = row.reference_doctype; + child.label = row.label; + child.color = row.color; + }); + frm.refresh_field("timetable_legends"); frm.save(); }; diff --git a/lms/lms/doctype/lms_batch/lms_batch.json b/lms/lms/doctype/lms_batch/lms_batch.json index 4cdb1e0a..f0838a4b 100644 --- a/lms/lms/doctype/lms_batch/lms_batch.json +++ b/lms/lms/doctype/lms_batch/lms_batch.json @@ -35,8 +35,10 @@ "timetable_template", "column_break_anya", "show_live_class", + "allow_future", "section_break_ontp", "timetable", + "timetable_legends", "pricing_tab", "section_break_gsac", "paid_batch", @@ -220,7 +222,7 @@ "default": "0", "fieldname": "show_live_class", "fieldtype": "Check", - "label": "Show Live Class" + "label": "Show live class" }, { "fieldname": "section_break_ontp", @@ -263,11 +265,23 @@ "fieldtype": "Code", "label": "Custom Script (JavaScript)", "options": "Javascript" + }, + { + "fieldname": "timetable_legends", + "fieldtype": "Table", + "label": "Timetable Legends", + "options": "LMS Timetable Legend" + }, + { + "default": "1", + "fieldname": "allow_future", + "fieldtype": "Check", + "label": "Allow accessing future dates" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-09-28 12:18:34.418812", + "modified": "2023-10-12 12:53:37.351989", "modified_by": "Administrator", "module": "LMS", "name": "LMS Batch", diff --git a/lms/lms/doctype/lms_timetable_legend/__init__.py b/lms/lms/doctype/lms_timetable_legend/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/lms/lms/doctype/lms_timetable_legend/lms_timetable_legend.js b/lms/lms/doctype/lms_timetable_legend/lms_timetable_legend.js new file mode 100644 index 00000000..7a8a3684 --- /dev/null +++ b/lms/lms/doctype/lms_timetable_legend/lms_timetable_legend.js @@ -0,0 +1,8 @@ +// Copyright (c) 2023, Frappe and contributors +// For license information, please see license.txt + +// frappe.ui.form.on("LMS Timetable Legend", { +// refresh(frm) { + +// }, +// }); diff --git a/lms/lms/doctype/lms_timetable_legend/lms_timetable_legend.json b/lms/lms/doctype/lms_timetable_legend/lms_timetable_legend.json new file mode 100644 index 00000000..6ae0ffe4 --- /dev/null +++ b/lms/lms/doctype/lms_timetable_legend/lms_timetable_legend.json @@ -0,0 +1,52 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "hash", + "creation": "2023-10-11 16:36:45.079267", + "default_view": "List", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "reference_doctype", + "label", + "color" + ], + "fields": [ + { + "fieldname": "reference_doctype", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Reference DocType", + "options": "DocType", + "reqd": 1 + }, + { + "fieldname": "color", + "fieldtype": "Color", + "in_list_view": 1, + "label": "Color", + "reqd": 1 + }, + { + "fieldname": "label", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Label", + "reqd": 1 + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2023-10-11 17:15:37.039139", + "modified_by": "Administrator", + "module": "LMS", + "name": "LMS Timetable Legend", + "naming_rule": "Random", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/lms/lms/doctype/lms_timetable_legend/lms_timetable_legend.py b/lms/lms/doctype/lms_timetable_legend/lms_timetable_legend.py new file mode 100644 index 00000000..c842e3a2 --- /dev/null +++ b/lms/lms/doctype/lms_timetable_legend/lms_timetable_legend.py @@ -0,0 +1,9 @@ +# Copyright (c) 2023, Frappe and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + + +class LMSTimetableLegend(Document): + pass diff --git a/lms/lms/doctype/lms_timetable_legend/test_lms_timetable_legend.py b/lms/lms/doctype/lms_timetable_legend/test_lms_timetable_legend.py new file mode 100644 index 00000000..816b1793 --- /dev/null +++ b/lms/lms/doctype/lms_timetable_legend/test_lms_timetable_legend.py @@ -0,0 +1,9 @@ +# Copyright (c) 2023, Frappe and Contributors +# See license.txt + +# import frappe +from frappe.tests.utils import FrappeTestCase + + +class TestLMSTimetableLegend(FrappeTestCase): + pass diff --git a/lms/lms/doctype/lms_timetable_template/lms_timetable_template.js b/lms/lms/doctype/lms_timetable_template/lms_timetable_template.js index a9bff04e..b5ec2d9b 100644 --- a/lms/lms/doctype/lms_timetable_template/lms_timetable_template.js +++ b/lms/lms/doctype/lms_timetable_template/lms_timetable_template.js @@ -11,5 +11,19 @@ frappe.ui.form.on("LMS Timetable Template", { }, }; }); + + frm.set_query("reference_doctype", "timetable_legends", function () { + let doctypes = [ + "Course Lesson", + "LMS Quiz", + "LMS Assignment", + "LMS Live Class", + ]; + return { + filters: { + name: ["in", doctypes], + }, + }; + }); }, }); diff --git a/lms/lms/doctype/lms_timetable_template/lms_timetable_template.json b/lms/lms/doctype/lms_timetable_template/lms_timetable_template.json index 99c88628..3b016b7a 100644 --- a/lms/lms/doctype/lms_timetable_template/lms_timetable_template.json +++ b/lms/lms/doctype/lms_timetable_template/lms_timetable_template.json @@ -8,7 +8,8 @@ "engine": "InnoDB", "field_order": [ "title", - "timetable" + "timetable", + "timetable_legends" ], "fields": [ { @@ -21,11 +22,17 @@ "fieldtype": "Table", "label": "Timetable", "options": "LMS Batch Timetable" + }, + { + "fieldname": "timetable_legends", + "fieldtype": "Table", + "label": "Timetable Legends", + "options": "LMS Timetable Legend" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-09-18 17:57:15.819072", + "modified": "2023-10-11 17:09:05.096243", "modified_by": "Administrator", "module": "LMS", "name": "LMS Timetable Template", diff --git a/lms/www/batches/batch.html b/lms/www/batches/batch.html index 2f78e0c6..86cb1202 100644 --- a/lms/www/batches/batch.html +++ b/lms/www/batches/batch.html @@ -552,7 +552,7 @@ {% for legend in legends %}
-
{{ legend.title }}
+
{{ legend.label }}
{% endfor %} @@ -574,6 +574,8 @@ diff --git a/lms/www/batches/batch.js b/lms/www/batches/batch.js index 1f4cd60d..6fb088a8 100644 --- a/lms/www/batches/batch.js +++ b/lms/www/batches/batch.js @@ -653,7 +653,6 @@ const setup_calendar = (events) => { const options = get_calendar_options(element, calendar_id); const calendar = new Calendar(container, options); this.calendar_ = calendar; - console.log(options); create_events(calendar, events); add_links_to_events(calendar, events); scroll_to_date(calendar, events); @@ -698,8 +697,8 @@ const get_calendar_options = (element, calendar_id) => { const create_events = (calendar, events, calendar_id) => { let calendar_events = []; - events.forEach((event, idx) => { + let clr = get_background_color(event.reference_doctype); calendar_events.push({ id: `event${idx}`, calendarId: calendar_id, @@ -707,7 +706,7 @@ const create_events = (calendar, events, calendar_id) => { start: `${event.date}T${event.start_time}`, end: `${event.date}T${event.end_time}`, isAllday: event.start_time ? false : true, - borderColor: get_background_color(event.reference_doctype), + borderColor: clr, backgroundColor: "var(--fg-color)", customStyle: { borderRadius: "var(--border-radius-md)", @@ -724,10 +723,21 @@ const create_events = (calendar, events, calendar_id) => { calendar.createEvents(calendar_events); }; -const add_links_to_events = (calendar, events) => { +const add_links_to_events = (calendar) => { calendar.on("clickEvent", ({ event }) => { - const el = document.getElementById("clicked-event"); - window.open(event.raw.url, "_blank"); + let event_date = event.start.d.d; + event_date = moment(event_date).format("YYYY-MM-DD"); + + let current_date = moment().format("YYYY-MM-DD"); + console.log(current_date, event_date); + console.log( + allow_future, + moment(event_date).isSameOrBefore(current_date) + ); + if (allow_future || moment(event_date).isSameOrBefore(current_date)) { + console.log("in here"); + window.open(event.raw.url, "_blank"); + } }); }; @@ -764,10 +774,10 @@ const set_calendar_range = (calendar, events) => { }; const get_background_color = (doctype) => { - if (doctype == "Course Lesson") return "var(--blue-400)"; - if (doctype == "LMS Quiz") return "var(--green-400)"; - if (doctype == "LMS Assignment") return "var(--orange-400)"; - if (doctype == "LMS Live Class") return "var(--purple-400)"; + const match = legends.filter((legend) => { + return legend.reference_doctype == doctype; + }); + if (match.length) return match[0].color; }; const email_to_students = () => { diff --git a/lms/www/batches/batch.py b/lms/www/batches/batch.py index 5e408c84..bb3ad307 100644 --- a/lms/www/batches/batch.py +++ b/lms/www/batches/batch.py @@ -42,6 +42,7 @@ def get_context(context): "currency", "batch_details", "published", + "allow_future", ], as_dict=True, ) @@ -96,7 +97,7 @@ def get_context(context): "parent": batch_name, }, ) - context.legends = get_legends() + context.legends = get_legends(batch_name) custom_tabs = frappe.get_hooks("lms_batch_tabs") @@ -261,22 +262,9 @@ def get_course_progress(batch_courses, student_details): student_details.courses[course.course] = 0 -def get_legends(): - return [ - { - "title": "Lesson", - "color": "var(--blue-400)", - }, - { - "title": "Quiz", - "color": "var(--green-400)", - }, - { - "title": "Assignment", - "color": "var(--orange-400)", - }, - { - "title": "Live Class", - "color": "var(--purple-400)", - }, - ] +def get_legends(batch): + return frappe.get_all( + "LMS Timetable Legend", + filters={"parenttype": "LMS Batch", "parent": batch}, + fields=["reference_doctype", "color", "label"], + ) From 55feb419985258da8a253bcb0e4085bec9fe0467 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 10:59:44 +0530 Subject: [PATCH 04/21] feat: timetable customisations --- lms/www/batches/batch.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lms/www/batches/batch.js b/lms/www/batches/batch.js index 6fb088a8..9614a924 100644 --- a/lms/www/batches/batch.js +++ b/lms/www/batches/batch.js @@ -729,13 +729,7 @@ const add_links_to_events = (calendar) => { event_date = moment(event_date).format("YYYY-MM-DD"); let current_date = moment().format("YYYY-MM-DD"); - console.log(current_date, event_date); - console.log( - allow_future, - moment(event_date).isSameOrBefore(current_date) - ); if (allow_future || moment(event_date).isSameOrBefore(current_date)) { - console.log("in here"); window.open(event.raw.url, "_blank"); } }); From 1e458921e8af81e2ca114e70f11fbccca6cb5878 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 11:17:41 +0530 Subject: [PATCH 05/21] ci: fix server tests script --- .github/workflows/ci.yml | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c0c28c7..a4ad07e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,26 +28,32 @@ jobs: MYSQL_ROOT_PASSWORD: root options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 steps: + - name: Clone - uses: actions/checkout@v2 - - name: setup python + + - name: Setup Python uses: actions/setup-python@v2 with: python-version: '3.10' - - name: setup node + + - name: Setup Node uses: actions/setup-node@v2 with: node-version: '18' check-latest: true - - name: setup cache for bench + + - name: Setup ache for bench uses: actions/cache@v2 with: path: ~/bench-cache key: ${{ runner.os }} - - name: install bench + + - name: Install Bench run: | pip3 install frappe-bench which bench - - name: bench init + + - name: Bench Init run: | if [ -d ~/bench-cache/bench.tgz ] then @@ -57,25 +63,32 @@ jobs: mkdir -p ~/bench-cache (cd && tar czf ~/bench-cache/bench.tgz frappe-bench) fi - - name: add lms app to bench + + - name: Add LMS app to bench working-directory: /home/runner/frappe-bench run: bench get-app lms $GITHUB_WORKSPACE - - name: create bench site + + - name: Create bench site working-directory: /home/runner/frappe-bench - run: bench new-site --mariadb-root-password root --admin-password admin frappe.local - - name: install lms app + run: bench new-site --mariadb-root-password root --character-set-server utf8mb4 --collation-server utf8mb4_unicode_ci --admin-password admin frappe.local + + - name: Install LMS app working-directory: /home/runner/frappe-bench run: bench --site frappe.local install-app lms - - name: setup requirements + + - name: Setup Requirements working-directory: /home/runner/frappe-bench run: bench setup requirements --dev - - name: allow tests + + - name: Allow Tests working-directory: /home/runner/frappe-bench run: bench --site frappe.local set-config allow_tests true - - name: bench build + + - name: Build working-directory: /home/runner/frappe-bench run: bench --site frappe.local build - - name: run tests + + - name: Run Tests working-directory: /home/runner/frappe-bench run: bench --site frappe.local run-tests --app lms From d840d2fc18e021a097d7417151aa14e426475e76 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 11:19:27 +0530 Subject: [PATCH 06/21] ci: fixed step in server tests script --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4ad07e9..439c6613 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 steps: - name: Clone - - uses: actions/checkout@v2 + uses: actions/checkout@v2 - name: Setup Python uses: actions/setup-python@v2 From bf5cc5e1d167ba76c3cf981e92b19fe4dd3f9176 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 11:24:58 +0530 Subject: [PATCH 07/21] ci: fixed mariadb options --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 439c6613..dc73014d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: - 3306:3306 env: MYSQL_ROOT_PASSWORD: root - options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 + options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 --character-set-server utf8mb4 --collation-server utf8mb4_unicode_ci steps: - name: Clone uses: actions/checkout@v2 @@ -70,7 +70,7 @@ jobs: - name: Create bench site working-directory: /home/runner/frappe-bench - run: bench new-site --mariadb-root-password root --character-set-server utf8mb4 --collation-server utf8mb4_unicode_ci --admin-password admin frappe.local + run: bench new-site --mariadb-root-password root --admin-password admin frappe.local - name: Install LMS app working-directory: /home/runner/frappe-bench From a1bb7962bcd3186d2ec88e4a3e8300d70f899368 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 11:40:17 +0530 Subject: [PATCH 08/21] ci: added collation server for mariadb --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc73014d..9a1061a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,9 +24,11 @@ jobs: image: mariadb:10.6 ports: - 3306:3306 + with: + collation server: 'utf8mb4_unicode_ci' env: MYSQL_ROOT_PASSWORD: root - options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 --character-set-server utf8mb4 --collation-server utf8mb4_unicode_ci + options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 steps: - name: Clone uses: actions/checkout@v2 From 3f5c3e89c8784404ddc4cfa047629d9748016587 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 11:45:42 +0530 Subject: [PATCH 09/21] ci: added collation server for mariadb --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a1061a1..e02c1ba8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,8 +24,7 @@ jobs: image: mariadb:10.6 ports: - 3306:3306 - with: - collation server: 'utf8mb4_unicode_ci' + collation server: 'utf8mb4_unicode_ci' env: MYSQL_ROOT_PASSWORD: root options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 From 2ff3d83d8f84ca08f099b56d5609a59e43c3ab18 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 11:52:38 +0530 Subject: [PATCH 10/21] ci: added collation server for mariadb --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e02c1ba8..03f6e315 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: image: mariadb:10.6 ports: - 3306:3306 - collation server: 'utf8mb4_unicode_ci' + command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci env: MYSQL_ROOT_PASSWORD: root options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 From bf0cb25a8804a0085e8b1f368e578c356d575f0a Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 12:33:16 +0530 Subject: [PATCH 11/21] ci: added collation server for mariadb --- .github/workflows/ci.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03f6e315..7ee6f555 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,18 +20,20 @@ jobs: image: redis:alpine ports: - 12000:6379 - mariadb: - image: mariadb:10.6 - ports: - - 3306:3306 - command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci - env: - MYSQL_ROOT_PASSWORD: root - options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 + steps: - name: Clone uses: actions/checkout@v2 + - name: Start MariaDB + uses: getong/mariadb-action@v1.1 + host port: 3306 + container port: 3306 + character set server: 'utf8mb4' + collation server: 'utf8_general_ci' + mariadb version: '10.6' + mysql root password: root + - name: Setup Python uses: actions/setup-python@v2 with: From f592cf08d88f08fda93ea6ef51e30e03ebbafa02 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 12:47:36 +0530 Subject: [PATCH 12/21] ci: added collation server for mariadb --- .github/workflows/ci.yml | 159 +++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 81 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ee6f555..5a485f16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,97 +1,94 @@ name: Server Tests on: - push: - branches: - - main - pull_request: {} + push: + branches: + - main + pull_request: {} jobs: - tests: - runs-on: ubuntu-latest - services: - redis-cache: - image: redis:alpine - ports: - - 13000:6379 - redis-queue: - image: redis:alpine - ports: - - 11000:6379 - redis-socketio: - image: redis:alpine - ports: - - 12000:6379 - - steps: - - name: Clone - uses: actions/checkout@v2 + tests: + runs-on: ubuntu-latest + services: + redis-cache: + image: redis:alpine + ports: + - 13000:6379 + redis-queue: + image: redis:alpine + ports: + - 11000:6379 + redis-socketio: + image: redis:alpine + ports: + - 12000:6379 + mysql: + image: mariadb:10.6 + env: + MARIADB_ROOT_PASSWORD: "root" + ports: + - 3306:3306 + options: --health-cmd="mariadb-admin ping" --health-interval=5s --health-timeout=2s --health-retries=3 - - name: Start MariaDB - uses: getong/mariadb-action@v1.1 - host port: 3306 - container port: 3306 - character set server: 'utf8mb4' - collation server: 'utf8_general_ci' - mariadb version: '10.6' - mysql root password: root + steps: + - name: Clone + uses: actions/checkout@v2 - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: '3.10' + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" - - name: Setup Node - uses: actions/setup-node@v2 - with: - node-version: '18' - check-latest: true + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: 18 + check-latest: true - - name: Setup ache for bench - uses: actions/cache@v2 - with: - path: ~/bench-cache - key: ${{ runner.os }} + - name: Setup ache for bench + uses: actions/cache@v2 + with: + path: ~/bench-cache + key: ${{ runner.os }} - - name: Install Bench - run: | - pip3 install frappe-bench - which bench + - name: Install Bench + run: | + pip3 install frappe-bench + which bench - - name: Bench Init - run: | - if [ -d ~/bench-cache/bench.tgz ] - then - (cd && tar xzf ~/bench-cache/bench.tgz) - else - bench init ~/frappe-bench --skip-redis-config-generation --skip-assets --python "$(which python)" - mkdir -p ~/bench-cache - (cd && tar czf ~/bench-cache/bench.tgz frappe-bench) - fi + - name: Bench Init + run: | + if [ -d ~/bench-cache/bench.tgz ] + then + (cd && tar xzf ~/bench-cache/bench.tgz) + else + bench init ~/frappe-bench --skip-redis-config-generation --skip-assets --python "$(which python)" + mkdir -p ~/bench-cache + (cd && tar czf ~/bench-cache/bench.tgz frappe-bench) + fi - - name: Add LMS app to bench - working-directory: /home/runner/frappe-bench - run: bench get-app lms $GITHUB_WORKSPACE + - name: Add LMS app to bench + working-directory: /home/runner/frappe-bench + run: bench get-app lms $GITHUB_WORKSPACE - - name: Create bench site - working-directory: /home/runner/frappe-bench - run: bench new-site --mariadb-root-password root --admin-password admin frappe.local + - name: Create bench site + working-directory: /home/runner/frappe-bench + run: bench new-site --mariadb-root-password root --admin-password admin frappe.local - - name: Install LMS app - working-directory: /home/runner/frappe-bench - run: bench --site frappe.local install-app lms + - name: Install LMS app + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local install-app lms - - name: Setup Requirements - working-directory: /home/runner/frappe-bench - run: bench setup requirements --dev + - name: Setup Requirements + working-directory: /home/runner/frappe-bench + run: bench setup requirements --dev - - name: Allow Tests - working-directory: /home/runner/frappe-bench - run: bench --site frappe.local set-config allow_tests true + - name: Allow Tests + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local set-config allow_tests true - - name: Build - working-directory: /home/runner/frappe-bench - run: bench --site frappe.local build - - - name: Run Tests - working-directory: /home/runner/frappe-bench - run: bench --site frappe.local run-tests --app lms + - name: Build + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local build + - name: Run Tests + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local run-tests --app lms From 4c83264c4a4d0869daa649a16428f261a733e6af Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 13:14:35 +0530 Subject: [PATCH 13/21] ci: added collation server for mariadb --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a485f16..6dd16f80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,10 +20,11 @@ jobs: image: redis:alpine ports: - 12000:6379 - mysql: + mariadb: image: mariadb:10.6 env: - MARIADB_ROOT_PASSWORD: "root" + MYSQL_ROOT_PASSWORD: "root" + COLLATION_SERVER: "utf8mb4_unicode_ci" ports: - 3306:3306 options: --health-cmd="mariadb-admin ping" --health-interval=5s --health-timeout=2s --health-retries=3 From c20fa7e093869adcd4b43ff4629ab429f9f0c3dc Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 14:50:50 +0530 Subject: [PATCH 14/21] ci: added collation server for mariadb --- .github/workflows/ci.yml | 102 +++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6dd16f80..ee4a2cd7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,65 +31,71 @@ jobs: steps: - name: Clone - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: "3.11" + + - name: Check for valid Python & Merge Conflicts + run: | + python -m compileall -q -f "${GITHUB_WORKSPACE}" + if grep -lr --exclude-dir=node_modules "^<<<<<<< " "${GITHUB_WORKSPACE}" + then echo "Found merge conflicts" + exit 1 + fi - name: Setup Node - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: 18 check-latest: true - - name: Setup ache for bench - uses: actions/cache@v2 + - name: Add to Hosts + run: | + echo "127.0.0.1 lms.test" | sudo tee -a /etc/hosts + + - name: Cache pip + uses: actions/cache@v3 with: - path: ~/bench-cache - key: ${{ runner.os }} + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/pyproject.toml', '**/setup.py') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- - - name: Install Bench + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 + id: yarn-cache + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install Dependencies run: | - pip3 install frappe-bench - which bench - - - name: Bench Init - run: | - if [ -d ~/bench-cache/bench.tgz ] - then - (cd && tar xzf ~/bench-cache/bench.tgz) - else - bench init ~/frappe-bench --skip-redis-config-generation --skip-assets --python "$(which python)" - mkdir -p ~/bench-cache - (cd && tar czf ~/bench-cache/bench.tgz frappe-bench) - fi - - - name: Add LMS app to bench - working-directory: /home/runner/frappe-bench - run: bench get-app lms $GITHUB_WORKSPACE - - - name: Create bench site - working-directory: /home/runner/frappe-bench - run: bench new-site --mariadb-root-password root --admin-password admin frappe.local - - - name: Install LMS app - working-directory: /home/runner/frappe-bench - run: bench --site frappe.local install-app lms - - - name: Setup Requirements - working-directory: /home/runner/frappe-bench - run: bench setup requirements --dev - - - name: Allow Tests - working-directory: /home/runner/frappe-bench - run: bench --site frappe.local set-config allow_tests true - - - name: Build - working-directory: /home/runner/frappe-bench - run: bench --site frappe.local build + bash ${GITHUB_WORKSPACE}/.github/helper/install_dependencies.sh + bash ${GITHUB_WORKSPACE}/.github/helper/install.sh + env: + BEFORE: ${{ env.GITHUB_EVENT_PATH.before }} + AFTER: ${{ env.GITHUB_EVENT_PATH.after }} + TYPE: server + DB: ${{ matrix.db }} - name: Run Tests - working-directory: /home/runner/frappe-bench - run: bench --site frappe.local run-tests --app lms + run: cd ~/frappe-bench/ && bench --site lms.test run-parallel-tests --app lms --total-builds 4 --build-number ${{ matrix.container }} + env: + SITE: lms.test + CI_BUILD_ID: ${{ github.run_id }} + BUILD_NUMBER: ${{ matrix.container }} + TOTAL_BUILDS: 2 + + - name: Show bench output + if: ${{ always() }} + run: cat ~/frappe-bench/bench_start.log || true + From 12c5ad54e722e1976ad03c4066b13831690fa364 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 15:24:12 +0530 Subject: [PATCH 15/21] ci: added collation server for mariadb --- .github/workflows/ci.yml | 168 +++++++++++++++++++-------------------- 1 file changed, 82 insertions(+), 86 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee4a2cd7..7ae67c73 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,101 +1,97 @@ name: Server Tests + on: - push: - branches: - - main - pull_request: {} + push: + branches: + - main + pull_request: {} + jobs: - tests: - runs-on: ubuntu-latest - services: - redis-cache: - image: redis:alpine - ports: - - 13000:6379 - redis-queue: - image: redis:alpine - ports: - - 11000:6379 - redis-socketio: - image: redis:alpine - ports: - - 12000:6379 - mariadb: - image: mariadb:10.6 - env: - MYSQL_ROOT_PASSWORD: "root" - COLLATION_SERVER: "utf8mb4_unicode_ci" - ports: - - 3306:3306 - options: --health-cmd="mariadb-admin ping" --health-interval=5s --health-timeout=2s --health-retries=3 + tests: + runs-on: ubuntu-latest + services: + redis-cache: + image: redis:alpine + ports: + - 13000:6379 + redis-queue: + image: redis:alpine + ports: + - 11000:6379 + redis-socketio: + image: redis:alpine + ports: + - 12000:6379 + mariadb: + image: mariadb:10.6 + ports: + - 3306:3306 + env: + MARIADB_ROOT_PASSWORD: root + MARIADB_CHARACTER_SET: utf8mb4 + MARIADB_COLLATION_SERVER: utf8mb4_unicode_ci + options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 + steps: + - name: Checkout code + uses: actions/checkout@v2 - steps: - - name: Clone - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.11' - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: "3.11" + - name: Set up Node + uses: actions/setup-node@v2 + with: + node-version: 18 + check-latest: true - - name: Check for valid Python & Merge Conflicts - run: | - python -m compileall -q -f "${GITHUB_WORKSPACE}" - if grep -lr --exclude-dir=node_modules "^<<<<<<< " "${GITHUB_WORKSPACE}" - then echo "Found merge conflicts" - exit 1 - fi + - name: Cache Bench + uses: actions/cache@v2 + with: + path: ~/bench-cache + key: ${{ runner.os }} - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 18 - check-latest: true + - name: Install Bench + run: | + pip3 install frappe-bench + which bench - - name: Add to Hosts - run: | - echo "127.0.0.1 lms.test" | sudo tee -a /etc/hosts + - name: Initialize Bench + run: | + if [ -d ~/bench-cache/bench.tgz ] + then + (cd && tar xzf ~/bench-cache/bench.tgz) + else + bench init ~/frappe-bench --skip-redis-config-generation --skip-assets --python "$(which python)" + mkdir -p ~/bench-cache + (cd && tar czf ~/bench-cache/bench.tgz frappe-bench) + fi - - name: Cache pip - uses: actions/cache@v3 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/pyproject.toml', '**/setup.py') }} - restore-keys: | - ${{ runner.os }}-pip- - ${{ runner.os }}- + - name: Add LMS App + working-directory: /home/runner/frappe-bench + run: bench get-app lms $GITHUB_WORKSPACE - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + - name: Create Bench Site + working-directory: /home/runner/frappe-bench + run: bench new-site --mariadb-root-password root --admin-password admin frappe.local - - uses: actions/cache@v3 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- + - name: Install LMS App + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local install-app lms - - name: Install Dependencies - run: | - bash ${GITHUB_WORKSPACE}/.github/helper/install_dependencies.sh - bash ${GITHUB_WORKSPACE}/.github/helper/install.sh - env: - BEFORE: ${{ env.GITHUB_EVENT_PATH.before }} - AFTER: ${{ env.GITHUB_EVENT_PATH.after }} - TYPE: server - DB: ${{ matrix.db }} + - name: Setup Requirements + working-directory: /home/runner/frappe-bench + run: bench setup requirements --dev - - name: Run Tests - run: cd ~/frappe-bench/ && bench --site lms.test run-parallel-tests --app lms --total-builds 4 --build-number ${{ matrix.container }} - env: - SITE: lms.test - CI_BUILD_ID: ${{ github.run_id }} - BUILD_NUMBER: ${{ matrix.container }} - TOTAL_BUILDS: 2 + - name: Allow Tests + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local set-config allow_tests true - - name: Show bench output - if: ${{ always() }} - run: cat ~/frappe-bench/bench_start.log || true + - name: Build + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local build + - name: Run Tests + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local run-tests --app lms From 8e12cae91f1ca1681a16d3c1e9f2c43e75d227da Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 15:58:07 +0530 Subject: [PATCH 16/21] ci: added collation server for mariadb --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ae67c73..f4838e75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,6 +46,10 @@ jobs: node-version: 18 check-latest: true + - name: Change MariaDB Collation + run: | + mysql -h 127.0.0.1 -P 3306 -uroot -proot -e "ALTER DATABASE dbname CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci" + - name: Cache Bench uses: actions/cache@v2 with: From eecc9b53df8284b848d456ddf905c666630f5494 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 16:07:01 +0530 Subject: [PATCH 17/21] ci: added collation server for mariadb --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f4838e75..550d823e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,8 +28,7 @@ jobs: - 3306:3306 env: MARIADB_ROOT_PASSWORD: root - MARIADB_CHARACTER_SET: utf8mb4 - MARIADB_COLLATION_SERVER: utf8mb4_unicode_ci + MARIADB_DATABASE: dbname options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 steps: - name: Checkout code From caf967f2e2352f0bcf1b05eac9dfea027210b35d Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 16:13:45 +0530 Subject: [PATCH 18/21] ci: added collation server for mariadb --- .github/workflows/ci.yml | 88 +++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 47 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 550d823e..49978e98 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,6 @@ jobs: - 3306:3306 env: MARIADB_ROOT_PASSWORD: root - MARIADB_DATABASE: dbname options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 steps: - name: Checkout code @@ -45,56 +44,51 @@ jobs: node-version: 18 check-latest: true - - name: Change MariaDB Collation - run: | - mysql -h 127.0.0.1 -P 3306 -uroot -proot -e "ALTER DATABASE dbname CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci" + - name: Add to Hosts + run: echo "127.0.0.1 lms.test" | sudo tee -a /etc/hosts - - name: Cache Bench + - name: Cache pip uses: actions/cache@v2 with: - path: ~/bench-cache - key: ${{ runner.os }} + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/pyproject.toml') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- - - name: Install Bench + - name: Cache node modules + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + + - uses: actions/cache@v2 + id: yarn-cache + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install run: | - pip3 install frappe-bench - which bench - - - name: Initialize Bench - run: | - if [ -d ~/bench-cache/bench.tgz ] - then - (cd && tar xzf ~/bench-cache/bench.tgz) - else - bench init ~/frappe-bench --skip-redis-config-generation --skip-assets --python "$(which python)" - mkdir -p ~/bench-cache - (cd && tar czf ~/bench-cache/bench.tgz frappe-bench) - fi - - - name: Add LMS App - working-directory: /home/runner/frappe-bench - run: bench get-app lms $GITHUB_WORKSPACE - - - name: Create Bench Site - working-directory: /home/runner/frappe-bench - run: bench new-site --mariadb-root-password root --admin-password admin frappe.local - - - name: Install LMS App - working-directory: /home/runner/frappe-bench - run: bench --site frappe.local install-app lms - - - name: Setup Requirements - working-directory: /home/runner/frappe-bench - run: bench setup requirements --dev - - - name: Allow Tests - working-directory: /home/runner/frappe-bench - run: bench --site frappe.local set-config allow_tests true - - - name: Build - working-directory: /home/runner/frappe-bench - run: bench --site frappe.local build + bash ${GITHUB_WORKSPACE}/.github/helper/install.sh + env: + BRANCH_TO_CLONE: ${{ env.HR_BRANCH }} - name: Run Tests - working-directory: /home/runner/frappe-bench - run: bench --site frappe.local run-tests --app lms + run: cd ~/frappe-bench/ && bench --site lms.test run-parallel-tests --app lms --total-builds 2 --build-number ${{ matrix.container }} + env: + TYPE: server + CI_BUILD_ID: ${{ github.run_id }} + ORCHESTRATOR_URL: http://test-orchestrator.frappe.io From f27eecce1fcf639570be8f87c6277154cda5fabf Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 16:17:58 +0530 Subject: [PATCH 19/21] ci: added collation server for mariadb --- .github/helper/install.sh | 4 ++++ .github/workflows/ci.yml | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/helper/install.sh b/.github/helper/install.sh index b5661726..198ead37 100644 --- a/.github/helper/install.sh +++ b/.github/helper/install.sh @@ -2,6 +2,10 @@ set -e cd ~ || exit +sudo apt update +sudo apt remove mysql-server mysql-client +sudo apt install libcups2-dev redis-server mariadb-client-10.6 + echo "Setting Up Bench..." pip install frappe-bench diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49978e98..6703541e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,8 +83,6 @@ jobs: - name: Install run: | bash ${GITHUB_WORKSPACE}/.github/helper/install.sh - env: - BRANCH_TO_CLONE: ${{ env.HR_BRANCH }} - name: Run Tests run: cd ~/frappe-bench/ && bench --site lms.test run-parallel-tests --app lms --total-builds 2 --build-number ${{ matrix.container }} From f2432d78ee3cf98ff1ad0f0f1f22feb2aa1d5cf5 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 16:29:47 +0530 Subject: [PATCH 20/21] ci: added collation server for mariadb --- .github/helper/install.sh | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/helper/install.sh b/.github/helper/install.sh index 198ead37..b6b9d354 100644 --- a/.github/helper/install.sh +++ b/.github/helper/install.sh @@ -23,14 +23,16 @@ mkdir ~/frappe-bench/sites/lms.test cp "${GITHUB_WORKSPACE}/.github/helper/site_config.json" ~/frappe-bench/sites/lms.test/site_config.json -mariadb --host 127.0.0.1 --port 3306 -u root -p123 -e "SET GLOBAL character_set_server = 'utf8mb4'"; -mariadb --host 127.0.0.1 --port 3306 -u root -p123 -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"; +mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "SET GLOBAL character_set_server = 'utf8mb4'"; +mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"; -mariadb --host 127.0.0.1 --port 3306 -u root -p123 -e "CREATE DATABASE test_lms"; -mariadb --host 127.0.0.1 --port 3306 -u root -p123 -e "CREATE USER 'test_lms'@'localhost' IDENTIFIED BY 'test_lms'"; -mariadb --host 127.0.0.1 --port 3306 -u root -p123 -e "GRANT ALL PRIVILEGES ON \`test_lms\`.* TO 'test_lms'@'localhost'"; +mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "CREATE DATABASE test_lms"; +mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "CREATE USER 'test_lms'@'localhost' IDENTIFIED BY 'test_lms'"; +mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "GRANT ALL PRIVILEGES ON \`test_lms\`.* TO 'test_lms'@'localhost'"; -mariadb --host 127.0.0.1 --port 3306 -u root -p123 -e "FLUSH PRIVILEGES"; +mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "FLUSH PRIVILEGES"; + +cd ~/frappe-bench || exit echo "Setting Up Procfile..." @@ -40,11 +42,10 @@ sed -i 's/^schedule:/# schedule:/g' Procfile echo "Starting Bench..." bench start &> bench_start.log & - CI=Yes bench build & -build_pid=$! - bench --site lms.test reinstall --yes -bench --site lms.test install-app lms -wait $build_pid +bench get-app hrms + +bench --site lms.test install-app lms +bench setup requirements --dev From bc2dc679a8b26454f646f4fd3ed2cbd9435329b1 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Oct 2023 18:15:49 +0530 Subject: [PATCH 21/21] fix: revert ci changes --- .github/helper/install.sh | 27 +++++----- .github/workflows/ci.yml | 100 +++++++++++++++++--------------------- 2 files changed, 55 insertions(+), 72 deletions(-) diff --git a/.github/helper/install.sh b/.github/helper/install.sh index b6b9d354..21bb9d9a 100644 --- a/.github/helper/install.sh +++ b/.github/helper/install.sh @@ -2,10 +2,6 @@ set -e cd ~ || exit -sudo apt update -sudo apt remove mysql-server mysql-client -sudo apt install libcups2-dev redis-server mariadb-client-10.6 - echo "Setting Up Bench..." pip install frappe-bench @@ -23,16 +19,14 @@ mkdir ~/frappe-bench/sites/lms.test cp "${GITHUB_WORKSPACE}/.github/helper/site_config.json" ~/frappe-bench/sites/lms.test/site_config.json -mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "SET GLOBAL character_set_server = 'utf8mb4'"; -mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"; +mariadb --host 127.0.0.1 --port 3306 -u root -p123 -e "SET GLOBAL character_set_server = 'utf8mb4'"; +mariadb --host 127.0.0.1 --port 3306 -u root -p123 -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"; -mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "CREATE DATABASE test_lms"; -mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "CREATE USER 'test_lms'@'localhost' IDENTIFIED BY 'test_lms'"; -mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "GRANT ALL PRIVILEGES ON \`test_lms\`.* TO 'test_lms'@'localhost'"; +mariadb --host 127.0.0.1 --port 3306 -u root -p123 -e "CREATE DATABASE test_lms"; +mariadb --host 127.0.0.1 --port 3306 -u root -p123 -e "CREATE USER 'test_lms'@'localhost' IDENTIFIED BY 'test_lms'"; +mariadb --host 127.0.0.1 --port 3306 -u root -p123 -e "GRANT ALL PRIVILEGES ON \`test_lms\`.* TO 'test_lms'@'localhost'"; -mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "FLUSH PRIVILEGES"; - -cd ~/frappe-bench || exit +mariadb --host 127.0.0.1 --port 3306 -u root -p123 -e "FLUSH PRIVILEGES"; echo "Setting Up Procfile..." @@ -42,10 +36,11 @@ sed -i 's/^schedule:/# schedule:/g' Procfile echo "Starting Bench..." bench start &> bench_start.log & + CI=Yes bench build & +build_pid=$! + bench --site lms.test reinstall --yes - -bench get-app hrms - bench --site lms.test install-app lms -bench setup requirements --dev + +wait $build_pid \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6703541e..01ee036a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,11 +1,9 @@ name: Server Tests - on: push: branches: - main pull_request: {} - jobs: tests: runs-on: ubuntu-latest @@ -23,70 +21,60 @@ jobs: ports: - 12000:6379 mariadb: - image: mariadb:10.6 + image: anandology/mariadb-utf8mb4:10.3 ports: - 3306:3306 env: - MARIADB_ROOT_PASSWORD: root + MYSQL_ROOT_PASSWORD: root options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Python + - uses: actions/checkout@v2 + - name: setup python uses: actions/setup-python@v2 with: - python-version: '3.11' - - - name: Set up Node + python-version: '3.10' + - name: setup node uses: actions/setup-node@v2 with: - node-version: 18 + node-version: '18' check-latest: true - - - name: Add to Hosts - run: echo "127.0.0.1 lms.test" | sudo tee -a /etc/hosts - - - name: Cache pip + - name: setup cache for bench uses: actions/cache@v2 with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/pyproject.toml') }} - restore-keys: | - ${{ runner.os }}-pip- - ${{ runner.os }}- - - - name: Cache node modules - uses: actions/cache@v2 - env: - cache-name: cache-node-modules - with: - path: ~/.npm - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - - uses: actions/cache@v2 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Install + path: ~/bench-cache + key: ${{ runner.os }} + - name: install bench run: | - bash ${GITHUB_WORKSPACE}/.github/helper/install.sh - - - name: Run Tests - run: cd ~/frappe-bench/ && bench --site lms.test run-parallel-tests --app lms --total-builds 2 --build-number ${{ matrix.container }} - env: - TYPE: server - CI_BUILD_ID: ${{ github.run_id }} - ORCHESTRATOR_URL: http://test-orchestrator.frappe.io + pip3 install frappe-bench + which bench + - name: bench init + run: | + if [ -d ~/bench-cache/bench.tgz ] + then + (cd && tar xzf ~/bench-cache/bench.tgz) + else + bench init ~/frappe-bench --skip-redis-config-generation --skip-assets --python "$(which python)" + mkdir -p ~/bench-cache + (cd && tar czf ~/bench-cache/bench.tgz frappe-bench) + fi + - name: add lms app to bench + working-directory: /home/runner/frappe-bench + run: bench get-app lms $GITHUB_WORKSPACE + - name: create bench site + working-directory: /home/runner/frappe-bench + run: bench new-site --mariadb-root-password root --admin-password admin frappe.local + - name: install lms app + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local install-app lms + - name: setup requirements + working-directory: /home/runner/frappe-bench + run: bench setup requirements --dev + - name: allow tests + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local set-config allow_tests true + - name: bench build + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local build + - name: run tests + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local run-tests --app lms \ No newline at end of file