From 485571fbd4e142b8497af14aaf6dec58f13e4fa8 Mon Sep 17 00:00:00 2001 From: faucomte97 Date: Mon, 10 Oct 2022 14:59:39 +0100 Subject: [PATCH] fix: Fix custom level save bugs --- .github/workflows/ci.yml | 2 +- Pipfile.lock | 27 ++++++++++++++------------- game/static/game/js/level_editor.js | 6 ++++-- game/views/level_editor.py | 24 +++++++++++++++--------- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90c43c2e5..27cd4880a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: architecture: "x64" - name: Install pip requirements run: | - pip install pipenv + pip install pipenv==2022.10.4 pip install pytest-cov pipenv install --dev --system - name: Collect static diff --git a/Pipfile.lock b/Pipfile.lock index e506341af..62709158c 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -168,19 +168,20 @@ }, "typing-extensions": { "hashes": [ - "sha256:25642c956049920a5aa49edcdd6ab1e06d7e5d467fc00e0506c44ac86fbfca02", - "sha256:e6d2677a32f47fc7eb2795db1dd15c1f34eff616bcaf2cfb5e997f854fa1c4a6" + "sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa", + "sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e" ], - "version": "==4.3.0" + "markers": "python_version < '3.8'", + "version": "==4.4.0" } }, "develop": { "aimmo": { "hashes": [ - "sha256:a5a16ccd4b5e9c17a6cb6bec75b09bfd936d599c1071d78e6d4d8c35e1dc5b12", - "sha256:c8e8c2f16ba027e16ef1e9639b3a224cfdba064c17ee3b3c45e6fc3dfa2f5033" + "sha256:c82b519518e7d577c7b5ab7b58f61f3d0b6f9079e858557402839639aff85db6", + "sha256:cba7d68fad674a17d7c8040e60f94b6a2570dd8a513de59860a6f7195a3458ce" ], - "version": "==2.4.6" + "version": "==2.5.1" }, "asgiref": { "hashes": [ @@ -663,7 +664,6 @@ "sha256:4f365fec2dff9c1162f834d9f18af1ba13062db0c708bf7b946f8a5c76180c39" ], "index": "pypi", - "markers": "python_version < '3.10'", "version": "==7.1.3" }, "pytest-django": { @@ -843,10 +843,11 @@ }, "typing-extensions": { "hashes": [ - "sha256:25642c956049920a5aa49edcdd6ab1e06d7e5d467fc00e0506c44ac86fbfca02", - "sha256:e6d2677a32f47fc7eb2795db1dd15c1f34eff616bcaf2cfb5e997f854fa1c4a6" + "sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa", + "sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e" ], - "version": "==4.3.0" + "markers": "python_version < '3.8'", + "version": "==4.4.0" }, "urllib3": { "hashes": [ @@ -864,10 +865,10 @@ }, "zipp": { "hashes": [ - "sha256:05b45f1ee8f807d0cc928485ca40a07cb491cf092ff587c0df9cb1fd154848d2", - "sha256:47c40d7fe183a6f21403a199b3e4192cca5774656965b0a4988ad2f8feb5f009" + "sha256:3a7af91c3db40ec72dd9d154ae18e008c69efe8ca88dde4f9a731bb82fe2f9eb", + "sha256:972cfa31bc2fedd3fa838a51e9bc7e64b7fb725a8c00e7431554311f180e9980" ], - "version": "==3.8.1" + "version": "==3.9.0" } } } diff --git a/game/static/game/js/level_editor.js b/game/static/game/js/level_editor.js index 4553e73bd..64be68141 100644 --- a/game/static/game/js/level_editor.js +++ b/game/static/game/js/level_editor.js @@ -717,10 +717,12 @@ ocargo.LevelEditor = function(levelId) { if (!saveState.isCurrentLevel(existingId)) { var onYes = function(){ saveLevelLocal(existingId); - $("#close-modal").click(); + $("#myModal").hide() + $("#ocargo-modal").hide() }; var onNo = function(){ - $("#close-modal").click(); + $("#myModal").hide() + $("#ocargo-modal").hide() }; ocargo.Drawing.startYesNoPopup(gettext('Overwriting'), gettext('Warning'), interpolate(gettext('Level %(level_name)s already exists. Are you sure you want to overwrite it?'), { diff --git a/game/views/level_editor.py b/game/views/level_editor.py index 888f6c754..0f99de8c7 100644 --- a/game/views/level_editor.py +++ b/game/views/level_editor.py @@ -218,8 +218,12 @@ def save_level_for_editor(request, levelId=None): if levelId is None: teacher = None + is_user_school_student = hasattr(level.owner, "student") and not level.owner.student.is_independent() + is_user_independent = hasattr(level.owner, "student") and level.owner.student.is_independent() + is_user_teacher = hasattr(level.owner, "teacher") + # if level owner is a school student, share with teacher automatically if they aren't an admin - if hasattr(level.owner, "student") and not level.owner.student.is_independent(): + if is_user_school_student: teacher = level.owner.student.class_field.teacher if not teacher.is_admin: level.shared_with.add(teacher.new_user) @@ -233,17 +237,19 @@ def save_level_for_editor(request, levelId=None): str(level.owner.student), level.owner.student.class_field.name, ) - elif hasattr(level.owner, "teacher"): + elif is_user_teacher: teacher = level.owner.teacher - # share with all admins of the school - school_admins = teacher.school.admins() + # share with all admins of the school if user is in a school + if not is_user_independent: + school_admins = teacher.school.admins() + + [ + level.shared_with.add(school_admin.new_user) + for school_admin in school_admins + if school_admin.new_user != request.user + ] - [ - level.shared_with.add(school_admin.new_user) - for school_admin in school_admins - if school_admin.new_user != request.user - ] level.save() response = {"id": level.id} return HttpResponse(json.dumps(response), content_type="application/javascript")