Skip to content

Commit

Permalink
Small improvements (#2082)
Browse files Browse the repository at this point in the history
* Update logs with more relevant info for debugging purposes

* Improved logs for alias creation rate-limit

* Reduce sudo time to 120 secs

* log fixes

* Fix missing object to add to the session
  • Loading branch information
acasajus committed Apr 8, 2024
1 parent 3c364da commit 2eb5fea
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
25 changes: 13 additions & 12 deletions app/alias_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,28 +308,29 @@ def delete_alias(alias: Alias, user: User):
Delete an alias and add it to either global or domain trash
Should be used instead of Alias.delete, DomainDeletedAlias.create, DeletedAlias.create
"""
# save deleted alias to either global or domain trash
LOG.i(f"User {user} has deleted alias {alias}")
# save deleted alias to either global or domain tra
if alias.custom_domain_id:
if not DomainDeletedAlias.get_by(
email=alias.email, domain_id=alias.custom_domain_id
):
LOG.d("add %s to domain %s trash", alias, alias.custom_domain_id)
Session.add(
DomainDeletedAlias(
user_id=user.id,
email=alias.email,
domain_id=alias.custom_domain_id,
)
domain_deleted_alias = DomainDeletedAlias(
user_id=user.id,
email=alias.email,
domain_id=alias.custom_domain_id,
)
Session.add(domain_deleted_alias)
Session.commit()

LOG.i(
f"Moving {alias} to domain {alias.custom_domain_id} trash {domain_deleted_alias}"
)
else:
if not DeletedAlias.get_by(email=alias.email):
LOG.d("add %s to global trash", alias)
Session.add(DeletedAlias(email=alias.email))
deleted_alias = DeletedAlias(email=alias.email)
Session.add(deleted_alias)
Session.commit()
LOG.i(f"Moving {alias} to global trash {deleted_alias}")

LOG.i("delete alias %s", alias)
Alias.filter(Alias.id == alias.id).delete()
Session.commit()

Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/views/enter_sudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from app.proton.utils import get_proton_partner
from app.utils import sanitize_next_url

_SUDO_GAP = 900
_SUDO_GAP = 120


class LoginForm(FlaskForm):
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def index():
)

if request.form.get("form-name") == "delete-alias":
LOG.d("delete alias %s", alias)
LOG.i(f"User {current_user} requested deletion of alias {alias}")
email = alias.email
alias_utils.delete_alias(alias, current_user)
flash(f"Alias {email} has been deleted", "success")
Expand Down
4 changes: 3 additions & 1 deletion app/rate_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def check_bucket_limit(
try:
value = lock_redis.incr(bucket_lock_name, bucket_seconds)
if value > max_hits:
LOG.i(f"Rate limit hit for {bucket_lock_name} -> {value}/{max_hits}")
LOG.i(
f"Rate limit hit for {lock_name} (bucket id {bucket_id}) -> {value}/{max_hits}"
)
newrelic.agent.record_custom_event(
"BucketRateLimit",
{"lock_name": lock_name, "bucket_seconds": bucket_seconds},
Expand Down

0 comments on commit 2eb5fea

Please sign in to comment.