-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the UX of the SMTP Section #16223
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
daac40e
feat: allow reply_to and email_from to be set for an SMTP config
Ridhwana 9208be7
feat: use these SMTP values in the mailers
Ridhwana 0337165
spec: test the application_mailer
Ridhwana f7e3d98
fix: validate with email, and not url
Ridhwana 1fa44cf
feat: mimic macs changes from https://github.com/forem/forem/pull/162…
Ridhwana dcc5201
Merge branch 'main' into Ridhwana/update-smtp-email-addresses
Ridhwana 9963ba4
setup packs for admin
Ridhwana 924ded9
refactor: order the keys and add a const for the auth methods
Ridhwana 4995d2b
feat: rename the header to a more user friendlly name
Ridhwana fb44a96
chore: move the section with Emails
Ridhwana ed0ca8a
feat: add a toggle that will show and hide the SMTP form under certai…
Ridhwana 14aa5be
feat: add the javaScript to handle the toggles
Ridhwana 585acea
feat: add a better description until we convert to a dropdown
Ridhwana 1ddbf0d
feat: ensure that we have declared sendgrid_enabled
Ridhwana 8f955bc
chore: add anote to the config controller
Ridhwana 05450d7
chore: remove references of the email addresses to keep brnach scoped
Ridhwana d3df886
feat: tweak js
Ridhwana 1d79faf
test: cypress workflow to update smtp settings
Ridhwana af6f1fe
feat : update the smtp tests
Ridhwana 9ca2b06
remove comments
Ridhwana fbd3cd2
update test
Ridhwana adee068
chore: rename NOTE
Ridhwana 869acf0
feat: polisha dn test ForemInstance.only_sendgrid_enabled?
Ridhwana 6e0abcf
main merge conflicts and rubocop fixes
Ridhwana c722e3a
chore: remove specs
Ridhwana 26aad50
Update app/lib/constants/settings/smtp.rb
Ridhwana a48ad74
Update spec/system/admin/config/admin_updates_smtp_settings_spec.rb
Ridhwana 1d177c9
Update spec/system/admin/config/admin_updates_smtp_settings_spec.rb
Ridhwana 08f6440
Update spec/system/admin/config/admin_updates_smtp_settings_spec.rb
Ridhwana 7a6aed4
Update app/javascript/packs/admin/config/smtp.js
Ridhwana 147dacb
refactor js as per comments
Ridhwana 505309c
refactor as per comments
Ridhwana 5268989
Update cypress/integration/seededFlows/adminFlows/config/emailServerS…
Ridhwana 2c00bef
refactor: update the Cypress tests
Ridhwana 7d34f8d
Merge branch 'main' into Ridhwana/update-smtp-email-addresses
Ridhwana File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
document | ||
.getElementById('settings_smtp_own_email_server') | ||
?.addEventListener('change', (event) => { | ||
const [customSMTPSection] = document.getElementsByClassName( | ||
'js-custom-smtp-section', | ||
); | ||
|
||
if (event.target.checked) { | ||
customSMTPSection.classList.remove('hidden'); | ||
} else { | ||
// when the user indicates that they do not want to use their own server | ||
// we clear the form values except for those fields that have a default value. | ||
const inputs = customSMTPSection.getElementsByTagName('input'); | ||
const haveDefaultValues = ['authentication']; | ||
|
||
for (const input of inputs) { | ||
if (!haveDefaultValues.some((el) => input.name.includes(el))) { | ||
input.value = ''; | ||
} | ||
} | ||
customSMTPSection.classList.add('hidden'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,12 @@ module Settings | |
class SMTP < Base | ||
self.table_name = :settings_smtp | ||
|
||
OPTIONS = %i[address port authentication user_name password domain].freeze | ||
OPTIONS = %i[user_name password address authentication domain port].freeze | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed the order of the fields to be a bit more friendly |
||
AUTHENTICATION_METHODS = %w[plain login cram_md5].freeze | ||
|
||
setting :address, type: :string, default: ApplicationConfig["SMTP_ADDRESS"].presence | ||
setting :authentication, type: :string, default: ApplicationConfig["SMTP_AUTHENTICATION"].presence, | ||
validates: { inclusion: %w[plain login cram_md5] } | ||
validates: { inclusion: AUTHENTICATION_METHODS } | ||
setting :domain, type: :string, default: ApplicationConfig["SMTP_DOMAIN"].presence | ||
setting :password, type: :string, default: ApplicationConfig["SMTP_PASSWORD"].presence | ||
setting :port, type: :integer, default: ApplicationConfig["SMTP_PORT"].presence || 25 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,47 @@ | ||
<%= javascript_packs_with_chunks_tag "admin/config/smtp", defer: true %> | ||
|
||
<%= form_for(Settings::SMTP.new, | ||
url: admin_settings_smtp_settings_path, | ||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %> | ||
html: { data: { | ||
action: "submit->config#updateConfigurationSettings", | ||
testid: "emailServerSettings" | ||
} }) do |f| %> | ||
<div class="card mt-3" id="smtp-section"> | ||
<%= render partial: "admin/shared/card_header", | ||
locals: { header: "SMTP Settings", state: "collapse", target: "smtpSettingsBodyContainer", expanded: false } %> | ||
locals: { header: "Email Server Settings (SMTP)", state: "collapse", target: "smtpSettingsBodyContainer", expanded: false } %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed the SMTP section to a more understandable term |
||
<div id="smtpSettingsBodyContainer" class="card-body collapse hide" aria-labelledby="smtpSettingsBodyContainer"> | ||
<fieldset class="grid gap-4"> | ||
<% Settings::SMTP::OPTIONS.each do |config_key| %> | ||
<div class="crayons-field"> | ||
<%= admin_config_label config_key %> | ||
<%= admin_config_description Constants::Settings::SMTP::DETAILS[config_key][:description] %> | ||
<%= f.text_field config_key, | ||
class: "crayons-textfield", | ||
value: Settings::SMTP.public_send(config_key), | ||
placeholder: Constants::Settings::SMTP::DETAILS[config_key][:placeholder] %> | ||
|
||
<% if ForemInstance.sendgrid_enabled? %> | ||
<div class="crayons-field crayons-field--checkbox mt-3"> | ||
<%= f.check_box :own_email_server, | ||
checked: Settings::SMTP.provided_minimum_settings?, | ||
class: "crayons-checkbox" %> | ||
<%= f.label :own_email_server, class: "crayons-field__label" do %> | ||
Use my own email server | ||
<% end %> | ||
</div> | ||
<% end %> | ||
|
||
<% if ForemInstance.only_sendgrid_enabled? %> | ||
<p class="mb-3"> | ||
As a Forem Cloud client, we provide an email server managed by the Forem team. All settings are managed by us and the from and reply email addresses are set as <%= ForemInstance.email %>. However, you can override this to use your own email server. | ||
</p> | ||
<% end %> | ||
|
||
<div class="js-custom-smtp-section <%= "hidden" if ForemInstance.only_sendgrid_enabled? %>"> | ||
<% Settings::SMTP::OPTIONS.each do |config_key| %> | ||
<div class="crayons-field mt-3"> | ||
<%= admin_config_label config_key, model: Settings::SMTP %> | ||
<%= admin_config_description Constants::Settings::SMTP::DETAILS[config_key][:description] %> | ||
<%= f.text_field config_key, | ||
class: "crayons-textfield", | ||
value: Settings::SMTP.public_send(config_key), | ||
placeholder: Constants::Settings::SMTP::DETAILS[config_key][:placeholder], | ||
"data-config-target": "smtpSetting#{config_key.to_s.camelize(:upper)}" %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</fieldset> | ||
<%= render "update_setting_button", f: f %> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
cypress/integration/seededFlows/adminFlows/config/emailServerSettingsSection.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
describe('Email Server Settings Section', () => { | ||
beforeEach(() => { | ||
cy.testSetup(); | ||
cy.fixture('users/adminUser.json').as('user'); | ||
|
||
cy.get('@user').then((user) => { | ||
cy.loginAndVisit(user, '/admin/customization/config'); | ||
}); | ||
}); | ||
|
||
describe('email server settings', () => { | ||
it('updates the smtp fields', () => { | ||
cy.findByTestId('emailServerSettings').as('emailServerSettings'); | ||
|
||
cy.get('@emailServerSettings') | ||
.findByText('Email Server Settings (SMTP)') | ||
.click(); | ||
|
||
cy.get('@emailServerSettings').within(() => { | ||
cy.findByText('Email Server Settings (SMTP)').click(); | ||
cy.findByLabelText('User name').clear().type('jane_doe'); | ||
cy.findByLabelText('Password').clear().type('abc123456'); | ||
cy.findByLabelText('Address').clear().type('smtp.gmail.com'); | ||
cy.findByLabelText('Authentication').clear().type('plain'); | ||
cy.findByText('Update Settings').click(); | ||
}); | ||
|
||
cy.url().should('contains', '/admin/customization/config'); | ||
cy.findByText('Successfully updated settings.').should('be.visible'); | ||
cy.findByLabelText('User name').should('have.value', 'jane_doe'); | ||
cy.findByLabelText('Password').should('have.value', 'abc123456'); | ||
cy.findByLabelText('Address').should('have.value', 'smtp.gmail.com'); | ||
cy.findByLabelText('Authentication').should('have.value', 'plain'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
spec/system/admin/config/admin_updates_smtp_settings_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "Admin updates SMTP Settings", type: :system do | ||
let(:admin) { create(:user, :super_admin) } | ||
|
||
before do | ||
sign_in admin | ||
end | ||
|
||
# We're unable to set and unset an ENV variable in Cypress to test different scenarios | ||
# hence, we test the view layouts with Capybara, and we test successful updates with Cypress. | ||
context "when Sendgrid is not enabled and SMTP is not enabled" do | ||
before do | ||
allow(ForemInstance).to receive(:sendgrid_enabled?).and_return(false) | ||
allow(Settings::SMTP).to receive(:address).and_return(nil) | ||
allow(Settings::SMTP).to receive(:user_name).and_return(nil) | ||
allow(Settings::SMTP).to receive(:password).and_return(nil) | ||
visit admin_config_path | ||
end | ||
|
||
it "does not show the 'Use my own email server' checkbox" do | ||
within("form[data-testid='emailServerSettings']") do | ||
expect(page).not_to have_content("Use my own email server") | ||
end | ||
end | ||
|
||
it "shows the SMTP Form", :aggregate_failures do | ||
within("form[data-testid='emailServerSettings']") do | ||
expect(page).to have_selector(".js-custom-smtp-section") | ||
expect(page).not_to have_selector(".js-custom-smtp-section.hidden") | ||
end | ||
end | ||
end | ||
|
||
context "when Sendgrid is enabled and SMTP is not enabled" do | ||
before do | ||
allow(ForemInstance).to receive(:sendgrid_enabled?).and_return(true) | ||
allow(ForemInstance).to receive(:email).and_return("yo@forem.com") | ||
allow(Settings::SMTP).to receive(:address).and_return(nil) | ||
allow(Settings::SMTP).to receive(:user_name).and_return(nil) | ||
allow(Settings::SMTP).to receive(:password).and_return(nil) | ||
visit admin_config_path | ||
end | ||
|
||
it "shows the checkbox to allow one to toggle ones own server" do | ||
within("form[data-testid='emailServerSettings']") do | ||
expect(page).to have_content("Use my own email server") | ||
end | ||
end | ||
|
||
it "shows a description" do | ||
within("form[data-testid='emailServerSettings']") do | ||
# rubocop:disable Layout/LineLength | ||
expect(page).to have_content("As a Forem Cloud client, we provide an email server managed by the Forem team. All settings are managed by us and the from and reply email addresses are set as yo@forem.com. However, you can override this to use your own email server.") | ||
# rubocop:enable Layout/LineLength | ||
end | ||
end | ||
|
||
it "does not show an SMTP Form" do | ||
within("form[data-testid='emailServerSettings']") do | ||
expect(page).to have_selector(".js-custom-smtp-section.hidden") | ||
end | ||
end | ||
end | ||
|
||
context "when Sendgrid is not enabled and SMTP is enabled" do | ||
before do | ||
allow(ForemInstance).to receive(:sendgrid_enabled?).and_return(false) | ||
allow(Settings::SMTP).to receive(:address).and_return("smtp.gmail.com") | ||
allow(Settings::SMTP).to receive(:user_name).and_return("jane_doe") | ||
allow(Settings::SMTP).to receive(:password).and_return("abc123456") | ||
visit admin_config_path | ||
end | ||
|
||
it "does not show the 'Use my own email server' checkbox" do | ||
within("form[data-testid='emailServerSettings']") do | ||
expect(page).not_to have_content("Use my own email server") | ||
end | ||
end | ||
|
||
it "shows the SMTP Form", :aggregate_failures do | ||
within("form[data-testid='emailServerSettings']") do | ||
expect(page).to have_selector(".js-custom-smtp-section") | ||
expect(page).not_to have_selector(".js-custom-smtp-section.hidden") | ||
end | ||
end | ||
end | ||
|
||
context "when Sendgrid is enabled and SMTP is enabled" do | ||
before do | ||
allow(ForemInstance).to receive(:sendgrid_enabled?).and_return(true) | ||
allow(Settings::SMTP).to receive(:address).and_return("smtp.gmail.com") | ||
allow(Settings::SMTP).to receive(:user_name).and_return("jane_doe") | ||
allow(Settings::SMTP).to receive(:password).and_return("abc123456") | ||
visit admin_config_path | ||
end | ||
|
||
it "shows the 'Use my own email server' checkbox" do | ||
within("form[data-testid='emailServerSettings']") do | ||
expect(page).to have_content("Use my own email server") | ||
end | ||
end | ||
|
||
it "shows an SMTP Form", :aggregate_failures do | ||
within("form[data-testid='emailServerSettings']") do | ||
expect(page).to have_selector(".js-custom-smtp-section") | ||
expect(page).not_to have_selector(".js-custom-smtp-section.hidden") | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some Rubocop fixes for LayoutLength