Skip to content

Commit

Permalink
fixing error in deletion of object in admin frontend, that would rais…
Browse files Browse the repository at this point in the history
…e 500 error, because uf no longer needed if else condition
  • Loading branch information
ooemperor committed Jan 16, 2024
1 parent 8740445 commit b906b89
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 81 deletions.
16 changes: 4 additions & 12 deletions codeGrader/frontend/admin/handlers/AdminUser.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,11 @@ def post(self, id_: int) -> Response:

admin = self.api.get(f"/admin/{id_}")
if self.admin.check_permission('w', admin["profile"]["id"]): # admin is allowed to delete the admin
if self.get_value("action_button") == "Submit":
self.api.delete(f"/admin/{id_}")
self.api.delete(f"/admin/{id_}")

# display message that Admin has been deleted on the returned page.
flash("Admin has been deleted")
return redirect(url_for("admins"))

elif self.get_value("action_button") == "Cancel":
return redirect(url_for("admin", id_=id_))

else:
pass
# TODO Implement Error
# display message that Admin has been deleted on the returned page.
flash("Admin has been deleted")
return redirect(url_for("admins"))

else: # admin is not allowed to delete users
self.flash("You are not allowed to delete admins. ")
Expand Down
16 changes: 4 additions & 12 deletions codeGrader/frontend/admin/handlers/Exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,12 @@ def post(self, id_: int) -> Response:
"""
exercise = self.api.get(f"/exercise/{id_}")
if self.admin.check_permission('w', exercise["profile"]["id"]): # admin is allowed to delete the exercise
if self.get_value("action_button") == "Submit":

response = self.api.delete(f"/exercise/{id_}")
response = self.api.delete(f"/exercise/{id_}")

# display message that exercise has been deleted on the returned page.
self.flash("Exercise has been deleted")
return redirect(url_for("exercises"))

elif self.get_value("action_button") == "Cancel":
return redirect(url_for("exercise", id_=id_))

else:
pass
# TODO Implement Error
# display message that exercise has been deleted on the returned page.
self.flash("Exercise has been deleted")
return redirect(url_for("exercises"))

else: # admin is not allowed to delete exercises
self.flash("You are not allowed to delete exercises. ")
Expand Down
14 changes: 4 additions & 10 deletions codeGrader/frontend/admin/handlers/Profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,13 @@ def post(self, id_: int) -> Response:

profile = self.api.get(f"/profile/{id_}")
if self.admin.check_permission('w'): # admin is allowed to delete the profile
if self.get_value("action_button") == "Submit":
response = self.api.delete(f"/profile/{id_}")

# display message that Profile has been deleted on the returned page.
self.flash("Profile has been deleted")
return redirect(url_for("profiles"))
response = self.api.delete(f"/profile/{id_}")

elif self.get_value("action_button") == "Cancel":
return redirect(url_for("profile", id_=id_))
# display message that Profile has been deleted on the returned page.
self.flash("Profile has been deleted")
return redirect(url_for("profiles"))

else:
pass
# TODO Implement Error

else: # admin is not allowed to delete profiles
self.flash("You are not allowed to delete profiles. ")
Expand Down
15 changes: 4 additions & 11 deletions codeGrader/frontend/admin/handlers/Subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,12 @@ def post(self, id_: int) -> Response:
"""
subject = self.api.get(f"/subject/{id_}")
if self.admin.check_permission('w', subject["profile"]["id"]): # admin is allowed to delete the subject
if self.get_value("action_button") == "Submit":
response = self.api.delete(f"/subject/{id_}")

# display message that Subject has been deleted on the returned page.
self.flash("Subject has been deleted")
return redirect(url_for("subjects"))
response = self.api.delete(f"/subject/{id_}")

elif self.get_value("action_button") == "Cancel":
return redirect(url_for("subject", id_=id_))

else:
pass
# TODO Implement Error
# display message that Subject has been deleted on the returned page.
self.flash("Subject has been deleted")
return redirect(url_for("subjects"))

else: # admin is not allowed to see subjects
self.flash("You are not allowed to delete subjects. ")
Expand Down
17 changes: 4 additions & 13 deletions codeGrader/frontend/admin/handlers/Task.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,10 @@ def post(self, id_: int) -> Response:
task = self.api.get(f"/task/{id_}")
if self.admin.check_permission('w', task["profile"]["id"]): # admin is allowed to delete the task

if self.get_value("action_button") == "Submit":
response = self.api.delete(f"/task/{id_}")

# display message that task has been deleted on the returned page.
self.flash("Task has been deleted")
return redirect(url_for("tasks"))

elif self.get_value("action_button") == "Cancel":
return redirect(url_for("task", id_=id_))

else:
pass
# TODO Implement Error
response = self.api.delete(f"/task/{id_}")
# display message that task has been deleted on the returned page.
self.flash("Task has been deleted")
return redirect(url_for("tasks"))

else: # admin is not allowed to delete tasks
self.flash("You are not allowed to delete tasks. ")
Expand Down
14 changes: 3 additions & 11 deletions codeGrader/frontend/admin/handlers/TaskFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,10 @@ def post(self,task_id_: int, file_id_: int) -> Response:
task = self.api.get(f"/task/{task_id_}")
if self.admin.check_permission('w', task["profile"]["id"]): # admin is allowed to delete the task

if self.get_value("action_button") == "Submit":
self.api.delete(f"/task/{task_id_}/{self.fileObject}/{file_id_}")
self.api.delete(f"/task/{task_id_}/{self.fileObject}/{file_id_}")

self.flash(f"{self.fileObject} has been deleted")
return redirect(url_for("task", id_=task_id_))

elif self.get_value("action_button") == "Cancel":
return redirect(url_for("task", id_=task_id_))

else:
pass
# TODO Implement Error
self.flash(f"{self.fileObject} has been deleted")
return redirect(url_for("task", id_=task_id_))

else: # admin is not allowed to delete tasks
self.flash("You are not allowed to delete Files from tasks. ")
Expand Down
16 changes: 4 additions & 12 deletions codeGrader/frontend/admin/handlers/User.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,11 @@ def post(self, id_: int) -> Response:
user = self.api.get(f"/user/{id_}")
if self.admin.check_permission('w', user["profile"]["id"]): # admin is allowed to delete the user

if self.get_value("action_button") == "Submit":
self.api.delete(f"/user/{id_}")
self.api.delete(f"/user/{id_}")

# display message that user has been deleted on the returned page.
self.flash("User has been deleted")
return redirect(url_for("users"))

elif self.get_value("action_button") == "Cancel":
return redirect(url_for("user", id_=id_))

else:
self.flash("You made an illegal operation. Please Try Again or Contact an Administrator!")
return redirect(url_for("user", id_=id_))
# display message that user has been deleted on the returned page.
self.flash("User has been deleted")
return redirect(url_for("users"))

else: # admin is not allowed to delete users
self.flash("You are not allowed to delete users. ")
Expand Down

0 comments on commit b906b89

Please sign in to comment.