forked from Github-Mirrors/canaille
the only receiver of mail when the request on HIBP api have failed is current_app.config[CANAILLE][ADMIN_EMAIL] defined in config.
This commit is contained in:
parent
738ea3a5ac
commit
2787252d81
1 changed files with 8 additions and 37 deletions
|
@ -1,9 +1,7 @@
|
|||
from flask import current_app
|
||||
from flask import flash
|
||||
|
||||
from canaille.app import models
|
||||
from canaille.app.i18n import gettext as _
|
||||
from canaille.backends import Backend
|
||||
from canaille.core.mails import send_compromised_password_check_failure_mail
|
||||
|
||||
from .flask import request_is_htmx
|
||||
|
@ -19,29 +17,6 @@ def check_if_send_mail_to_admins(form, api_url, hashed_password_suffix):
|
|||
"error",
|
||||
)
|
||||
|
||||
group_user = Backend.instance.query(models.User)
|
||||
|
||||
if (
|
||||
current_app.config["CANAILLE"]["ACL"]
|
||||
and current_app.config["CANAILLE"]["ACL"]["ADMIN"]
|
||||
and current_app.config["CANAILLE"]["ACL"]["ADMIN"]["FILTER"]
|
||||
and current_app.config["CANAILLE"]["ACL"]["ADMIN"]["FILTER"]["groups"]
|
||||
):
|
||||
admin_group_display_name = current_app.config["CANAILLE"]["ACL"]["ADMIN"][
|
||||
"FILTER"
|
||||
]["groups"]
|
||||
|
||||
admin_emails = [
|
||||
user.emails[0]
|
||||
for user in group_user
|
||||
if any(
|
||||
group.display_name == admin_group_display_name
|
||||
for group in user.groups
|
||||
)
|
||||
]
|
||||
else:
|
||||
admin_emails = [current_app.config["CANAILLE"]["ADMIN_EMAIL"]]
|
||||
|
||||
if form.user is not None:
|
||||
user_name = form.user.user_name
|
||||
user_email = form.user.emails[0]
|
||||
|
@ -49,17 +24,13 @@ def check_if_send_mail_to_admins(form, api_url, hashed_password_suffix):
|
|||
user_name = form["user_name"].data
|
||||
user_email = form["emails"].data[0]
|
||||
|
||||
number_emails_send = 0
|
||||
|
||||
for email in admin_emails:
|
||||
if send_compromised_password_check_failure_mail(
|
||||
api_url, user_name, user_email, hashed_password_suffix, email
|
||||
api_url,
|
||||
user_name,
|
||||
user_email,
|
||||
hashed_password_suffix,
|
||||
current_app.config["CANAILLE"]["ADMIN_EMAIL"],
|
||||
):
|
||||
number_emails_send += 1
|
||||
else:
|
||||
pass
|
||||
|
||||
if number_emails_send > 0:
|
||||
flash(
|
||||
_(
|
||||
"We have informed your administrator about the failure of the password compromise investigation."
|
||||
|
@ -77,5 +48,5 @@ def check_if_send_mail_to_admins(form, api_url, hashed_password_suffix):
|
|||
)
|
||||
return None
|
||||
|
||||
return number_emails_send
|
||||
return
|
||||
return None
|
||||
|
|
Loading…
Reference in a new issue