Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
settings_org: Use settings_checkbox in Authentication Methods UI.
Alex Tereschenko9142aab8ba93
diff --git a/static/js/settings_org.js b/static/js/settings_org.jsindex 466a67ae82b..76ae225fc77 100644--- a/static/js/settings_org.js+++ b/static/js/settings_org.js@@ -218,6 +218,17 @@ export function extract_property_name($elem, for_realm_default_settings) {// ID approach.return $elem.attr("name");}++ if ($elem.attr("id").startsWith("id_authmethod")) {+ // Authentication Method component IDs include authentication method name+ // for uniqueness, anchored to "id_authmethod" prefix, e.g. "id_authmethodapple_<property_name>".+ // We need to strip that whole construct down to extract the actual property name.+ // The [\da-z]+ part of the regexp covers the auth method name itself.+ // We assume it's not an empty string and can contain only digits and lowercase ASCII letters,+ // this is ensured by a respective allowlist-based filter in populate_auth_methods().+ return /^id_authmethod[\da-z]+_(.*)$/.exec($elem.attr("id"))[1];+ }+return /^id_(.*)$/.exec($elem.attr("id").replace(/-/g, "_"))[1];}@@ -415,6 +426,13 @@ export function populate_auth_methods(auth_methods) {method: auth_method,enabled: value,is_owner: page_params.is_owner,+ // The negated character class regexp serves as an allowlist - the replace() will+ // remove *all* symbols *but* digits (\d) and lowecase letters (a-z),+ // so that we can make assumptions on this string elsewhere in the code.+ // As a result, the only two "incoming" assumptions on the auth method name are:+ // 1) It contains at least one allowed symbol+ // 2) No two auth method names are identical after this allowlist filtering+ prefix: "id_authmethod" + auth_method.toLowerCase().replace(/[^\da-z]/g, "") + "_",});}$auth_methods_table.html(rendered_auth_method_rows);@@ -704,7 +722,7 @@ export function set_up() {function get_auth_method_table_data() {const new_auth_methods = {};- const $auth_method_rows = $("#id_realm_authentication_methods").find("tr.method_row");+ const $auth_method_rows = $("#id_realm_authentication_methods").find("div.method_row");for (const method_row of $auth_method_rows) {new_auth_methods[$(method_row).data("method")] = $(method_row)@@ -1016,6 +1034,16 @@ export function register_save_discard_widget_handlers(// IDs, and also the emojiset input is not compatible with the// ID approach.property_name = $input_elem.attr("name");+ } else if ($input_elem.attr("id").startsWith("id_authmethod")) {+ // Authentication Method component IDs include authentication method name+ // for uniqueness, anchored to "id_authmethod" prefix, e.g. "id_authmethodapple_<property_name>".+ // We need to strip that whole construct down to extract the actual property name.+ // The [\da-z]+ part of the regexp covers the auth method name itself.+ // We assume it's not an empty string and can contain only digits and lowercase ASCII letters,+ // this is ensured by a respective allowlist-based filter in populate_auth_methods().+ [, property_name] = /^id_authmethod[\da-z]+_(.*)$/.exec(+ $input_elem.attr("id"),+ );} else {[, property_name] = /^id_realm_(.*)$/.exec($input_elem.attr("id"));}diff --git a/static/styles/settings.css b/static/styles/settings.cssindex 56061667c42..05dfb2bd9a1 100644--- a/static/styles/settings.css+++ b/static/styles/settings.css@@ -285,14 +285,6 @@ td .button {z-index: 1;}- #id_realm_authentication_methods {- width: 20%;-- td {- border: none;- }- }-#admin_page_users_loading_indicator,#attachments_loading_indicator,#admin_page_deactivated_users_loading_indicator,diff --git a/static/templates/settings/admin_auth_methods_list.hbs b/static/templates/settings/admin_auth_methods_list.hbsindex 3345f8be6b2..6bf0a2e3279 100644--- a/static/templates/settings/admin_auth_methods_list.hbs+++ b/static/templates/settings/admin_auth_methods_list.hbs@@ -1,12 +1,8 @@-<tr class="method_row" data-method="{{method}}">- <td>- <label class="checkbox">- <input type="checkbox" {{#if enabled}}checked="checked"{{/if}} {{#unless is_owner}}disabled{{/unless}}/>- <span></span>- </label>- </td>- <td>- <span class="method">{{method}}</span>- </td>--</tr>+<div class="method_row" data-method="{{method}}">+ {{> settings_checkbox+ setting_name="realm_authentication_methods"+ prefix=prefix+ is_checked=enabled+ label=method+ is_disabled=(not is_owner) }}+</div>diff --git a/static/templates/settings/auth_methods_settings_admin.hbs b/static/templates/settings/auth_methods_settings_admin.hbsindex ee702938b55..948049f6a22 100644--- a/static/templates/settings/auth_methods_settings_admin.hbs+++ b/static/templates/settings/auth_methods_settings_admin.hbs@@ -11,15 +11,9 @@<div><p>{{t "Configure the authentication methods for your organization."}}</p>- <table id="id_realm_authentication_methods"- class="table table-condensed table-striped prop-element">- <thead>- <th>{{t "Method" }}</th>- <th>{{t "Enabled" }}</th>- </thead>- <tbody>- </tbody>- </table>+ <div id="id_realm_authentication_methods">+ {{! Empty div is intentional, it will get populated by a dedicated template }}+ </div></div></div></form>