-
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
Save Confirmation - Admin (Part 1 of 3) #14418
Conversation
spec/requests/admin/configs_spec.rb
Outdated
@@ -807,15 +807,17 @@ | |||
end | |||
|
|||
it "unsets appropriate SMTP config, and apply default value if applicable" do | |||
Settings::SMTP.address = "smtp.example.com" | |||
Settings::SMTP.port = 12_345 | |||
default_address = ApplicationConfig["SMTP_ADDRESS"].presence || nil |
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.
We do have Settings::SMTP.address
and Settings::SMTP.port
which have default values set through the environment, why are we doing this manually here?
field :address, type: :string, default: ApplicationConfig["SMTP_ADDRESS"].presence
...
field :port, type: :integer, default: ApplicationConfig["SMTP_PORT"].presence || 25
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.
Hey @citizen428, locally and on Travis, this spec kept failing, specifically the expectation that the default port was 25
(locally it was 2525
for me). I thought it more robust to expect whatever the default port was on the system running the spec. Same for the default address.
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.
😄 I understand and agree with the reasoning. I was more wondering why we use ApplicationConfig
directly instead of
Settings::SMTP.get_field(:smtp_port)[:default]
Which is a bit more general.
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.
Hey @citizen428,
So locally, this is what I get for each of these Settings values:
Settings::SMTP.get_field(:smtp_address)[:default]
=> nil
Settings::SMTP.get_field(:smtp_port)[:default]
=> nil
ApplicationConfig["SMTP_PORT"]
=> "2525"
ApplicationConfig["SMTP_ADDRESS"]
=> "smtp.mailtrap.io"
The expectations in the relevant configs_spec.rb
specs are now failing when I use the more general Settings::SMTP.get_field
.
I'm not sure why these values differ from each other. I think I'll keep use of ApplicationConfig
; thoughts?
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.
It's fine to use ApplicationConfig
of course 😃
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.
Took this for a spin again locally and looks good to me - nice one @msarit ✨
cy.findByRole('alert').should( | ||
'have.text', | ||
'Successfully updated settings.', | ||
); |
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.
nice 🔥
cy.get('#facebook-auth-btn').click(); | ||
cy.get('#settings_authentication_facebook_key').type('randomkey'); | ||
cy.get('#settings_authentication_facebook_secret').type('randomsecret'); | ||
|
||
cy.get('@authSectionForm').findByText('Update Settings').click(); |
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.
just a suggestion and definitely not blocking, but it's a bit more robust to use cy.findByRole
or cy.findByLabelText
wherever possible, rather than getting by ID selector or inner text
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.
Yes @aitchiss Nick also pointed this out to me yesterday 😊
These cypress tests were existing before my modifications, and the use of cy.get(#id/text)
is quite plentiful throughout several files. We decided that making all these tests more robust was beyond the scope of this PR.
outcome.message == null | ||
? this.displaySnackbar(outcome.error) | ||
: this.displaySnackbar(outcome.message); |
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.
Refactor (non-blocking): Use the nullish-coalescing operator.
outcome.message == null | |
? this.displaySnackbar(outcome.error) | |
: this.displaySnackbar(outcome.message); | |
this.displaySnackbar(outcome.message ?? outcome.error) |
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.
@nickytonline Isn't your suggestion reversed? The first one says display .error
when .message == null
, yours is the other way around, isn't it?
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.
Updated it. 🙃
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.
Today I learned! 😅 Thanks Nick.
); | ||
} | ||
|
||
async activateLightConfirmation(event) { |
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.
nitpick (potentially-blocking): It's not clear to me what activateLightConfirmation
means. Is this method called activateLightConfirmation
because it's not a form post with a full server-side roundtrip? From what it looks like in the context of where this is called, updateConfigurationSettings
or updateSettings
seems more appropriate.
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.
I will change
end | ||
|
||
format.json do | ||
render json: { error: "😭 #{result.errors.to_sentence}" }, status: :unauthorized | ||
render json: { error: "❗️❗️ #{result.errors.to_sentence}" }, status: :unauthorized |
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.
I wonder how these symbols are going to be read by the screen reader. I understand they're added to catch the attention of the user since we don't have a way to differentiate between errors and non errors in Snackbar and we should have a global notification area for errors or something and that's outside the scope wrt the conversation with Pawel.
I think the Admin team should figure this one out in a future RFC/PR
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.
We probably don't need any emojis in the error message.
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.
I would love it if instead of emojis in the text we could have an optional svg/img icon in the snackbar to convey an error message vs a success/info message. You're right @rhymes in that screen reader behaviour with emojis can vary widely, and what it announces might not be something we intend (e.g. VO on Chrome announces 😭 as "loudly crying face", but this can be different when using a different screen reader/browser/etc)
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.
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.
I think I agree with Nick here - removing the emojis from the error messaging. They were already in place when I started this task; I changed the crying-face emoji to the exclamation points as I thought that was more indicative of an error. However, using the emojis re not worth the a11y drawbacks.
Eventually, I would love our snackbars to be customizable in terms of color perhaps, to indicate a successful transaction, as opposed to a failed one. But that's another PR.
@@ -24,6 +40,8 @@ def extra_authorization_and_confirmation | |||
end | |||
|
|||
def confirmation_text_valid? | |||
return true unless params.key?(:confirmation) |
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.
This means that one can theoretically skip the config check for everything by removing :confirmation
from the request params with a tool like Charles Proxy or Burp Suite. Not the biggest issue but still something to keep in mind.
@citizen428 In response to your comment above MK, I determined that we only use the confirmation form within the sections at |
@nickytonline Ready for your re-review! |
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.
Thanks for making the changes @msarit! Looking forward to seeing this in production! 🚀
What type of PR is this? (check all applicable)
Description
Part 1 of 2 implementing the Admin-Save-Confirmation RFC.
In this PR, I refactor all confirmation steps in the
/admin/customization/config
page to use async calls. I also update all associatedrequests
and end-to-end tests.The RFC: https://github.com/forem/rfcs/pull/78/
NOTES
Files changed
alarm you 😅 For about 10 files, I merely added theUpdate Settings
button, and added theupdateConfigurationSettings
callback to the form therein.QA Instructions, Screenshots, Recordings
http://localhost:xxxx/admin/customization/config
as asuper_admin
Update Settings
button each time, there should be NO page refresh, and a snackbar with messageSuccessfully updated settings
should appear in the bottom-left corner.spec/requests/admin/configs_spec.rb
and all tests undercypress/integration/seededFlows/adminFlows/config
and make sure they pass.UI accessibility concerns?
None. No major UI changes made; most changes are backend
Added/updated tests?
have not been included
[Forem core team only] How will this change be communicated?
Will this PR introduce a change that impacts Forem members or creators, the
development process, or any of our internal teams? If so, please note how you
will share this change with the people who need to know about it.
Admin Guide, or
Storybook (for Crayons components)
CHANGELOG.md
or in a forem.dev post
replace this line with details on why this change doesn't need to be
shared
What gif best describes this PR or how it makes you feel?