Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix custom level save bugs #1372

Merged
merged 1 commit into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 14 additions & 13 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions game/static/game/js/level_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?'), {
Expand Down
24 changes: 15 additions & 9 deletions game/views/level_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down