From 3a984c8ee7c010c1984050cc6ee983b98ca6396c Mon Sep 17 00:00:00 2001 From: Arit Amana <32520970+msarit@users.noreply.github.com> Date: Wed, 13 Jan 2021 13:54:39 -0500 Subject: [PATCH] [2020 EOY Issue] Modal alert when enabling Auth Provider without keys (#12135) * Start hooking things up * further generalize adminModal, hook up relevant code * Complete implementation * remove comments * Address QA suggestions * Address QA suggestions * Use object parameter for adminModal * starting the admin cypress tests * Code review suggestions * remove incomplete test * rename data attributes to make more sense * complete the work * use destructuring * edit warning modal text --- app/assets/stylesheets/admin.scss | 8 +- app/helpers/authentication_helper.rb | 7 +- app/javascript/admin/adminModal.js | 92 +++++---- .../admin/controllers/config_controller.js | 179 ++++++++++++++---- .../_apple_auth_provider_settings.html.erb | 10 +- .../configs/_auth_provider_settings.html.erb | 14 +- app/views/admin/configs/show.html.erb | 13 +- spec/helpers/authentication_helper_spec.rb | 25 +-- 8 files changed, 213 insertions(+), 135 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index c9cca23dc..f63f26bae 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -147,10 +147,6 @@ label { gap: var(--su-4); padding-top: var(--su-6); padding-bottom: var(--su-2); - - .auth-warning { - padding: var(--su-2); // Override default crayons notice padding - } } .admin-config-checkmark { @@ -180,3 +176,7 @@ label { .mod-actions__data { max-width: 300px; } + +.capitalize { + text-transform: capitalize; +} diff --git a/app/helpers/authentication_helper.rb b/app/helpers/authentication_helper.rb index e5606564b..7d244c7fc 100644 --- a/app/helpers/authentication_helper.rb +++ b/app/helpers/authentication_helper.rb @@ -23,11 +23,6 @@ module AuthenticationHelper Authentication::Providers.available.map(&:to_s) end - def provider_keys_configured?(provider) - SiteConfig.public_send("#{provider}_key").present? && - SiteConfig.public_send("#{provider}_secret").present? - end - def forem_creator_flow_enabled? FeatureFlag.enabled?(:creator_onboarding) && waiting_on_first_user? end @@ -45,7 +40,7 @@ module AuthenticationHelper invite_only_mode_or_no_enabled_auth_options ? "crayons-tooltip" : "" end - def disabled_attr_on_auth_provider_enablebtn + def disabled_attr_on_auth_provider_enable_btn invite_only_mode_or_no_enabled_auth_options ? "disabled" : "" end diff --git a/app/javascript/admin/adminModal.js b/app/javascript/admin/adminModal.js index 185480d7b..6cc097666 100644 --- a/app/javascript/admin/adminModal.js +++ b/app/javascript/admin/adminModal.js @@ -2,54 +2,62 @@ * A function to generate the HTML for a Crayons modal within the /admin/ space. * * @function adminModal - * @param {string} title The title of the modal. - * @param {string} body The modal's content. May use HTML tags for styling. - * @param {string} confirmBtnText The text for the modal's "Confirm" button. - * @param {string} confirmBtnAction The function that fires when "Confirm" button is clicked. - * @param {string} cancelBtnText The text for the modal's "Cancel" button. - * @param {string} cancelBtnAction The function that fires when "Cancel" button is clicked. - * @param {string} customAttr A custom data attribute name. Will be apprended to the "data-" part. - * @param {string} customAttrValue The value of the custom attribute "customAttr". + * @param {Object} modalProps Properties of the Modal + * @param {string} modalProps.title The title of the modal. + * @param {string} modalProps.body The modal's content. May use HTML tags for styling. + * @param {string} modalProps.leftBtnText The text for the modal's left button. + * @param {string} modalProps.leftBtnAction The function that fires when left button is clicked. + * @param {string} modalProps.rightBtnText The text for the modal's right button. + * @param {string} modalProps.rightBtnAction The function that fires when right button is clicked. + * @param {string} modalProps.leftBtnClasses Classes applied to left button. + * @param {string} modalProps.rightBtnClasses Classes applied to right button. + * @param {string} modalProps.leftCustomDataAttr A custom data attribute for the left button. + * @param {string} modalProps.rightCustomDataAttr A custom data attribute for the right button. */ -const adminModal = ( +const adminModal = function ({ title, body, - confirmBtnText, - confirmBtnAction, - cancelBtnText, - cancelBtnAction, - customAttr = null, - customAttrValue = null, -) => ` -
${title}
- -You haven't filled out all of the required fields to enable the following authentication providers:
+You may continue editing these authentication providers, or you may cancel.
+ `; + } + + submitForm() { + this.authSectionFormTarget.submit(); + } + + activateMissingKeysModal(providers) { + this.configModalAnchorTarget.innerHTML = adminModal({ + title: 'Setup not complete', + body: this.missingAuthKeysModalBody(providers), + leftBtnText: 'Continue editing', + leftBtnAction: 'closeAdminModal', + rightBtnText: 'Cancel', + rightBtnAction: 'cancelAuthProviderEnable', + rightBtnClasses: 'crayons-btn--secondary', + }); + } + + configUpdatePrecheck(event) { + if (this.enabledProvidersWithMissingKeys().length > 0) { + event.preventDefault(); + this.activateMissingKeysModal(this.enabledProvidersWithMissingKeys()); + } else { + event.target.submit(); + } + } + + cancelAuthProviderEnable() { + const providers = this.enabledProvidersWithMissingKeys(); + + providers.forEach((provider) => { + const enabledIndicator = document.getElementById( + `${provider}-enabled-indicator`, + ); + const authEnableButton = document.getElementById(`${provider}-auth-btn`); + + authEnableButton.setAttribute('data-enable-auth', 'false'); + enabledIndicator.classList.remove('visible'); + this.listAuthToBeEnabled(); + document + .getElementById(`${provider}-auth-settings`) + .classList.add('hidden'); + document + .getElementById(`${provider}-auth-btn`) + .classList.remove('hidden'); + + this.closeAdminModal(); + }); + } } diff --git a/app/views/admin/configs/_apple_auth_provider_settings.html.erb b/app/views/admin/configs/_apple_auth_provider_settings.html.erb index 49da9da65..5b033a795 100644 --- a/app/views/admin/configs/_apple_auth_provider_settings.html.erb +++ b/app/views/admin/configs/_apple_auth_provider_settings.html.erb @@ -54,21 +54,21 @@ requires a custom partial class="crayons-btn crayons-btn--danger" data-action="click->config#activateAuthProviderModal" data-tooltip="<%= tooltip_text_email_or_auth_provider_btns %>" - data-auth-provider="<%= provider.provider_name %>" - data-auth-provider-official="<%= provider.official_name %>" - <%= disabled_attr_on_auth_provider_enablebtn %>> + data-provider-name="<%= provider.provider_name %>" + data-provider-official-name="<%= provider.official_name %>" + <%= disabled_attr_on_auth_provider_enable_btn %>> Disable