events: Change format of authentication_methods realm_update_dict event.

Makes the event in line with state_data.realm_authentication_methods.
This commit is contained in:
Mateusz Mandera
2024-02-16 00:56:08 +01:00
committed by Tim Abbott
parent da9e4e6e54
commit 1ede8da46c
6 changed files with 66 additions and 62 deletions

View File

@@ -965,13 +965,23 @@ def check_realm_default_update(
assert isinstance(event["value"], prop_type)
authentication_method_dict = DictType(
required_keys=[
("enabled", bool),
("available", bool),
],
optional_keys=[
("unavailable_reason", str),
],
)
authentication_dict = DictType(
required_keys=[
("Google", bool),
("Dev", bool),
("LDAP", bool),
("GitHub", bool),
("Email", bool),
("Google", authentication_method_dict),
("Dev", authentication_method_dict),
("LDAP", authentication_method_dict),
("GitHub", authentication_method_dict),
("Email", authentication_method_dict),
]
)

View File

@@ -1198,19 +1198,15 @@ def apply_event(
)
elif event["op"] == "update_dict":
for key, value in event["data"].items():
state["realm_" + key] = value
# It's a bit messy, but this is where we need to
# update the state for whether password authentication
# is enabled on this server.
if key == "authentication_methods":
state_realm_authentication_methods = state["realm_authentication_methods"]
for auth_method, enabled in value.items():
state_realm_authentication_methods[auth_method]["enabled"] = enabled
# It's a bit messy, but this is where we need to
# update the state for whether password authentication
# is enabled on this server.
state["realm_password_auth_enabled"] = value["Email"] or value["LDAP"]
state["realm_email_auth_enabled"] = value["Email"]
else:
state["realm_" + key] = value
state["realm_password_auth_enabled"] = (
value["Email"]["enabled"] or value["LDAP"]["enabled"]
)
state["realm_email_auth_enabled"] = value["Email"]["enabled"]
elif event["op"] == "deactivated":
# The realm has just been deactivated. If our request had
# arrived a moment later, we'd have rendered the