Skip to content
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

Merged
merged 7 commits into from
Jun 19, 2024

Conversation

martin-brennan
Copy link
Contributor

@martin-brennan martin-brennan commented Jun 4, 2024

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 that
can be added to any site setting. When it is simple, 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.

I have decided to make requires_confirmation a kind of enum
because we also have an existing system of confirmation for many
"default" site settings that affect user options, e.g. the ones defined
at

def user_options
{
default_email_mailing_list_mode: "mailing_list_mode",
default_email_mailing_list_mode_frequency: "mailing_list_mode_frequency",
default_email_level: "email_level",
default_email_messages_level: "email_messages_level",
default_topics_automatic_unpin: "automatically_unpin_topics",
default_email_previous_replies: "email_previous_replies",
default_email_in_reply_to: "email_in_reply_to",
default_other_enable_quoting: "enable_quoting",
default_other_enable_defer: "enable_defer",
default_other_external_links_in_new_tab: "external_links_in_new_tab",
default_other_dynamic_favicon: "dynamic_favicon",
default_other_new_topic_duration_minutes: "new_topic_duration_minutes",
default_other_auto_track_topics_after_msecs: "auto_track_topics_after_msecs",
default_other_notification_level_when_replying: "notification_level_when_replying",
default_other_like_notification_frequency: "like_notification_frequency",
default_other_skip_new_user_tips: "skip_new_user_tips",
default_email_digest_frequency: "digest_after_minutes",
default_include_tl0_in_digests: "include_tl0_in_digests",
default_text_size: "text_size_key",
default_title_count_mode: "title_count_mode_key",
default_hide_profile_and_presence: "hide_profile_and_presence",
default_sidebar_link_to_filtered_list: "sidebar_link_to_filtered_list",
default_sidebar_show_count_of_new_items: "sidebar_show_count_of_new_items",
}
end
. This pops a modal like so:

image

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.

image

@github-actions github-actions bot added the i18n PRs which update English locale files or i18n related code label Jun 4, 2024
@martin-brennan martin-brennan marked this pull request as draft June 4, 2024 06:59
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.
@martin-brennan martin-brennan force-pushed the feature/requires-confirmation-site-settings branch from b213e29 to ab73800 Compare June 4, 2024 07:14
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"
Copy link
Contributor Author

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

@martin-brennan
Copy link
Contributor Author

Note to self, we already have some form of this for certain settings which relate to user options / preferences, maybe we could consolidate this into one thing

image

@martin-brennan martin-brennan marked this pull request as ready for review June 14, 2024 06:26
@martin-brennan martin-brennan force-pushed the feature/requires-confirmation-site-settings branch from bc7c7a8 to 9d5e0f8 Compare June 14, 2024 06:35
@@ -204,10 +207,59 @@ export default Mixin.create({
}
},

async confirmChanges(settingKey) {
return await new Promise((resolve) => {
Copy link
Contributor

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;

Copy link
Contributor Author

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?

Copy link
Contributor

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) 😛

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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;

?

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah cool, thanks!

@martin-brennan martin-brennan merged commit 83361b2 into main Jun 19, 2024
16 checks passed
@martin-brennan martin-brennan deleted the feature/requires-confirmation-site-settings branch June 19, 2024 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n PRs which update English locale files or i18n related code
4 participants