Skip to content

Commit

Permalink
User modification fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hmaciasc authored and kidanger committed Jan 19, 2024
1 parent df73bcf commit 744992f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 9 additions & 7 deletions cp2/ControlPanel/ControlPanel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ def user_created_handler(sender, instance, *args, **kwargs):
return

demoinfo_editor, _ = api_post(
"/api/demoinfo/editor", "get", data={"email": new_editor.email}
f"/api/demoinfo/editor?email={new_editor.email}", "get"
)
new_editor_exists = demoinfo_editor.get("editor", None)

demoinfo_editor, _ = api_post(
"/api/demoinfo/editor", "get", data={"email": old_editor.email}
f"/api/demoinfo/editor?email={old_editor.email}", "get"
)
old_editor_exists = demoinfo_editor.get("editor", None)

Expand Down Expand Up @@ -79,7 +79,7 @@ def delete_profile(sender, instance, *args, **kwargs):
Signal post-delete in djagno DB will try to remove the editor from demoinfo if it is found.
"""
demoinfo_editor, _ = api_post(
"/api/demoinfo/editor", "get", data={"email": instance.email}
"/api/demoinfo/editor", "get", params={"email": instance.email}
)
editor_info = demoinfo_editor.get("editor", None)
editor_id = editor_info["id"]
Expand All @@ -100,7 +100,7 @@ def add_editor(name: str, email: str):
"name": name,
"mail": email,
}
_, status = api_post("/api/demoinfo/editor", "post", data=data)
_, status = api_post("/api/demoinfo/editor", "post", params=data)

if status != 201:
error = "Error, user tried to set up an email which is already in use."
Expand All @@ -117,9 +117,11 @@ def update_editor(username, email, old_email):
"old_email": old_email,
"new_email": email,
}
_, status = api_post("/api/demoinfo/editor", "patch", data=data)
_, status = api_post("/api/demoinfo/editor", "patch", params=data)

if status != 200:
logger.error(
if status != 201:
error_message = (
f"Could not update email of user '{username}', '{old_email}' --> '{email}'"
)
logger.error(error_message)
raise ValidationError(error_message)
3 changes: 2 additions & 1 deletion ipol_demo/modules/core/demoinfo/demoinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ def get_editor(self, email: str) -> Result[Optional[dict], str]:

if editor:
editor = editor.__dict__
return Ok(editor)
return Ok(editor)
return Err("Editor not found")

def update_editor_email(
self, new_email: str, old_email: str, name: str
Expand Down

0 comments on commit 744992f

Please sign in to comment.