mirror of https://github.com/zulip/zulip.git
settings: Refactor code to handle authentication methods.
This commit refactors code to handle authentication methods so that we need not update the type returned for "realm_authentication_methods" by get_property_value to be something different than what is the type for realm object. This change essentially means that we do not use the value returned by get_property_value for authentication methods and directly call realm_authentication_methods_to_boolean_dict. Follow up to #29264.
This commit is contained in:
parent
a0cec2c378
commit
85d0c0d7dd
|
@ -79,9 +79,7 @@ export function get_realm_time_limits_in_minutes(property: message_time_limit_se
|
|||
return val;
|
||||
}
|
||||
|
||||
type RealmSetting = Omit<typeof realm, "realm_authentication_methods"> & {
|
||||
realm_authentication_methods: Record<string, boolean>;
|
||||
};
|
||||
type RealmSetting = typeof realm;
|
||||
type RealmSettingProperties = keyof RealmSetting | "realm_org_join_restrictions";
|
||||
|
||||
type RealmUserSettingDefaultType = typeof realm_user_settings_defaults;
|
||||
|
@ -148,10 +146,6 @@ export function get_property_value(
|
|||
return "no_restriction";
|
||||
}
|
||||
|
||||
if (property_name === "realm_authentication_methods") {
|
||||
return realm_authentication_methods_to_boolean_dict();
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
return realm[property_name as keyof RealmSetting] as valueof<RealmSetting>;
|
||||
}
|
||||
|
@ -164,7 +158,7 @@ export function realm_authentication_methods_to_boolean_dict(): Record<string, b
|
|||
auth_method_to_bool[auth_method_name] = auth_method_info.enabled;
|
||||
}
|
||||
|
||||
return auth_method_to_bool;
|
||||
return sort_object_by_key(auth_method_to_bool);
|
||||
}
|
||||
|
||||
export function extract_property_name($elem: JQuery, for_realm_default_settings?: boolean): string {
|
||||
|
@ -711,9 +705,7 @@ export function check_property_changed(
|
|||
|
||||
switch (property_name) {
|
||||
case "realm_authentication_methods":
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
current_val = sort_object_by_key(current_val as Record<string, boolean>);
|
||||
current_val = JSON.stringify(current_val);
|
||||
current_val = JSON.stringify(realm_authentication_methods_to_boolean_dict());
|
||||
proposed_val = get_auth_method_list_data();
|
||||
proposed_val = JSON.stringify(proposed_val);
|
||||
break;
|
||||
|
|
|
@ -393,7 +393,6 @@ export function populate_auth_methods(auth_method_to_bool_map) {
|
|||
return;
|
||||
}
|
||||
const $auth_methods_list = $("#id_realm_authentication_methods").expectOne();
|
||||
auth_method_to_bool_map = settings_components.sort_object_by_key(auth_method_to_bool_map);
|
||||
let rendered_auth_method_rows = "";
|
||||
for (const [auth_method, value] of Object.entries(auth_method_to_bool_map)) {
|
||||
// Certain authentication methods are not available to be enabled without
|
||||
|
@ -490,7 +489,9 @@ export function discard_property_element_changes(elem, for_realm_default_setting
|
|||
settings_components.set_input_element_value($elem, property_value);
|
||||
break;
|
||||
case "realm_authentication_methods":
|
||||
populate_auth_methods(property_value);
|
||||
populate_auth_methods(
|
||||
settings_components.realm_authentication_methods_to_boolean_dict(),
|
||||
);
|
||||
break;
|
||||
case "realm_new_stream_announcements_stream_id":
|
||||
case "realm_signup_announcements_stream_id":
|
||||
|
|
Loading…
Reference in New Issue