Skip to content

Commit

Permalink
fix: Fix custom level save bugs (#1372)
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 authored Oct 10, 2022
1 parent 7bcd10a commit ee4079a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
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

0 comments on commit ee4079a

Please sign in to comment.