Skip to content

Commit

Permalink
fix: api crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
cquintana92 committed Dec 2, 2024
1 parent 3b0b5f4 commit 99ade0f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
8 changes: 7 additions & 1 deletion app/api/views/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,13 @@ def update_alias(alias_id):
changed = True

if "mailbox_ids" in data:
mailbox_ids = [int(m_id) for m_id in data.get("mailbox_ids")]
mailbox_ids = []
for mailbox_id in data.get("mailbox_ids"):
try:
mailbox_ids.append(int(mailbox_id))
except ValueError:
return jsonify(error="Invalid mailbox_id"), 400

err = set_mailboxes_for_alias(
user_id=user.id, alias=alias, mailbox_ids=mailbox_ids
)
Expand Down
24 changes: 18 additions & 6 deletions app/api/views/new_custom_alias.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from email_validator import EmailNotValidError
from flask import g
from flask import jsonify, request

Expand Down Expand Up @@ -93,12 +94,15 @@ def new_custom_alias_v2():
400,
)

alias = Alias.create(
user_id=user.id,
email=full_alias,
mailbox_id=user.default_mailbox_id,
note=note,
)
try:
alias = Alias.create(
user_id=user.id,
email=full_alias,
mailbox_id=user.default_mailbox_id,
note=note,
)
except EmailNotValidError:
return jsonify(error="Email is not valid"), 400

Session.commit()

Expand Down Expand Up @@ -154,8 +158,16 @@ def new_custom_alias_v3():
return jsonify(error="request body does not follow the required format"), 400

alias_prefix_data = data.get("alias_prefix", "") or ""

if not isinstance(alias_prefix_data, str):
return jsonify(error="request body does not follow the required format"), 400

alias_prefix = alias_prefix_data.strip().lower().replace(" ", "")
signed_suffix = data.get("signed_suffix", "") or ""

if not isinstance(signed_suffix, str):
return jsonify(error="request body does not follow the required format"), 400

signed_suffix = signed_suffix.strip()

mailbox_ids = data.get("mailbox_ids")
Expand Down
2 changes: 1 addition & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ def pgp_enabled(self) -> bool:
return False

@staticmethod
def get_custom_domain(alias_address) -> Optional["CustomDomain"]:
def get_custom_domain(alias_address: str) -> Optional["CustomDomain"]:
alias_domain = validate_email(
alias_address, check_deliverability=False, allow_smtputf8=False
).domain
Expand Down

0 comments on commit 99ade0f

Please sign in to comment.