-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
FEATURE: Introduce site settings which require confirmation #27315
FEATURE: Introduce site settings which require confirmation #27315
Conversation
Many site settings can be distructive or have huge side-effects for a site that the admin may not be aware of when changing it. This commit introduces a `requires_confirmation` attribute that can be added to any site setting. When it is true, a confirmation dialog will open if that setting is changed in the admin UI, optionally with a custom message that is defined in client.en.yml. If the admin does not confirm, we reset the setting to its previous clean value and do not save the new value.
b213e29
to
ab73800
Compare
config/locales/client.en.yml
Outdated
confirmation_messages: | ||
default: "Changing this setting may have far-reaching or unintended consequences for your site. Are you sure you want to proceed?" | ||
min_password_length: "All non-admin users of your site will be required to change their password to satisfy this requirement if they do not already. Are you sure you want to change this?" | ||
min_admin_password_length: "WORSE STUFF HAPPEN" |
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.
Need actual copy for these 3
bc7c7a8
to
9d5e0f8
Compare
@@ -204,10 +207,59 @@ export default Mixin.create({ | |||
} | |||
}, | |||
|
|||
async confirmChanges(settingKey) { | |||
return await new Promise((resolve) => { |
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.
now it's awaiting AND returning 🤪
anyway, I'd be good if dialog.alert
would return an object that had a response
promise on it, like:
const dialogInstance = await this.dialog.alert({
buttons: [
{ label: "ok", action: () => true },
{ label: "cancel", action () => false },
]
});
return await dialogInstance.response;
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 that would be nicer 😂 Until then what should have I done here based on Joffrey's feedback?
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.
Well, you could implement that 😜 but the next best thing would be to choose between async/await
(no return
) or return
(w/o async
and await
) 😛
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.
Sorry can you clarify this a bit more? I am doing this:
async confirmChanges(settingKey) {
return new Promise((resolve) => {
// Fallback is needed in case the setting does not have a custom confirmation
// prompt/confirm defined.
this.dialog.alert({
message: I18n.t(
`admin.site_settings.requires_confirmation_messages.${settingKey}.prompt`,
{
translatedFallback: I18n.t(
"admin.site_settings.requires_confirmation_messages.default.prompt"
),
}
),
buttons: [
{
label: I18n.t(
`admin.site_settings.requires_confirmation_messages.${settingKey}.confirm`,
{
translatedFallback: I18n.t(
"admin.site_settings.requires_confirmation_messages.default.confirm"
),
}
),
class: "btn-primary",
action: () => resolve(true),
},
{
label: I18n.t("no_value"),
class: "btn-default",
action: () => resolve(false),
},
],
});
});
},
// further down
confirm = await this.confirmChanges(key);
What specifically should I change without changing what dialog.confirm
returns?
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.
Like, I don't know how removing return
helps in confirmChanges
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.
Are you saying to do:
const confirmed = new Promise((resolve) => { //blah };
return confirmed;
?
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.
ah, sorry if you need the return value then this is the way to go:
function () {
return new Promise(…
i.e. no async
and no await
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.
Ah cool, thanks!
Many site settings can be destructive or have huge side-effects
for a site that the admin may not be aware of when changing it.
This commit introduces a
requires_confirmation
attribute thatcan be added to any site setting. When it is
simple
, a confirmationdialog will open if that setting is changed in the admin UI,
optionally with a custom message that is defined in client.en.yml.
I have decided to make
requires_confirmation
a kind of enumbecause we also have an existing system of confirmation for many
"default" site settings that affect user options, e.g. the ones defined
at
discourse/app/controllers/admin/site_settings_controller.rb
Lines 248 to 274 in bc7c7a8
In a future PR I would like to consolidate these two "requires confirmation"
systems into one for site settings.
If the admin does not confirm, we reset the setting to its previous
clean value and do not save the new value.