fix: SMTP feature can be disabled again

This commit is contained in:
Éloi Rivard 2024-05-14 23:04:32 +02:00
parent 43f9f328a5
commit 3fb5d0149d
No known key found for this signature in database
GPG key ID: 7EDA204EA57DD184
5 changed files with 9 additions and 9 deletions

View file

@ -4,7 +4,7 @@ class Features:
@property
def has_smtp(self):
return "SMTP" in self.app.config["CANAILLE"]
return bool(self.app.config["CANAILLE"]["SMTP"])
@property
def has_oidc(self):

View file

@ -75,7 +75,7 @@ def index():
@bp.route("/join", methods=("GET", "POST"))
def join():
if not current_app.config["CANAILLE"]["ENABLE_REGISTRATION"]:
if not current_app.features.has_registration:
abort(404)
if not current_app.config["CANAILLE"]["EMAIL_CONFIRMATION"]:
@ -235,8 +235,8 @@ def registration(data=None, hash=None):
if not data:
payload = None
if (
not current_app.config["CANAILLE"]["ENABLE_REGISTRATION"]
or current_app.config["CANAILLE"]["EMAIL_CONFIRMATION"]
not current_app.features.has_registration
or current_app.features.has_email_confirmation
):
abort(403)

View file

@ -36,7 +36,7 @@ def test_confirmation_unset_smtp_disabled_email_editable(
"""If email confirmation is unset and no SMTP server has been configured,
then email confirmation cannot be enabled, thus users must be able to pick
any email."""
del testclient.app.config["CANAILLE"]["SMTP"]
testclient.app.config["CANAILLE"]["SMTP"] = None
testclient.app.config["CANAILLE"]["EMAIL_CONFIRMATION"] = None
res = testclient.get("/profile/user")
@ -61,7 +61,7 @@ def test_confirmation_enabled_smtp_disabled_readonly(testclient, backend, logged
In doubt, users cannot edit their emails.
"""
del testclient.app.config["CANAILLE"]["SMTP"]
testclient.app.config["CANAILLE"]["SMTP"] = None
testclient.app.config["CANAILLE"]["EMAIL_CONFIRMATION"] = True
res = testclient.get("/profile/user")
@ -101,7 +101,7 @@ def test_confirmation_enabled_smtp_disabled_admin_editable(
"""Administrators should be able to edit user email addresses, even when
email confirmation is enabled and SMTP is disabled."""
testclient.app.config["CANAILLE"]["EMAIL_CONFIRMATION"] = True
del testclient.app.config["CANAILLE"]["SMTP"]
testclient.app.config["CANAILLE"]["SMTP"] = None
res = testclient.get("/profile/user")
assert "readonly" not in res.form["emails-0"].attrs

View file

@ -292,7 +292,7 @@ def test_unavailable_if_no_smtp(testclient, logged_admin):
res.mustcontain("Invite")
testclient.get("/invite")
del testclient.app.config["CANAILLE"]["SMTP"]
testclient.app.config["CANAILLE"]["SMTP"] = None
res = testclient.get("/users")
res.mustcontain(no="Invite")

View file

@ -78,7 +78,7 @@ def test_unavailable_if_no_smtp(testclient, user):
testclient.get("/reset", status=200)
del testclient.app.config["CANAILLE"]["SMTP"]
testclient.app.config["CANAILLE"]["SMTP"] = None
res = testclient.get("/login")
res.mustcontain(no="Forgotten password")