Skip to content

A platform for community discussion. Free, open, simple.

FIX: Hide secret admin fields by default (#33255)

Chris Alberti61033eed4ca4
diff --git a/app/assets/javascripts/admin/addon/components/site-setting.gjs b/app/assets/javascripts/admin/addon/components/site-setting.gjs
index fa7874bd201..27d79f77249 100644
--- a/app/assets/javascripts/admin/addon/components/site-setting.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-setting.gjs
@@ -1,6 +1,7 @@
+import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
-import Component from "@ember/component";
import { hash } from "@ember/helper";
+import { on } from "@ember/modifier";
import { action } from "@ember/object";
import { dependentKeyCompat } from "@ember/object/compat";
import { getOwner } from "@ember/owner";
@@ -50,29 +51,14 @@ export default class SiteSettingComponent extends Component {
@service dialog;
@service siteSettingChangeTracker;
- @tracked setting = null;
@tracked isSecret = null;
updateExistingUsers = null;
- // Classic component attributes
- classNameBindings = [":row", ":setting", "overridden", "typeClass"];
- attributeBindings = ["setting.setting:data-setting"];
-
constructor() {
super(...arguments);
this.isSecret = this.setting?.secret;
}
- didInsertElement() {
- super.didInsertElement(...arguments);
- this.element.addEventListener("keydown", this._handleKeydown);
- }
-
- willDestroyElement() {
- super.willDestroyElement(...arguments);
- this.element.removeEventListener("keydown", this._handleKeydown);
- }
-
@action
async _handleKeydown(event) {
if (
@@ -145,6 +131,10 @@ export default class SiteSettingComponent extends Component {
return componentType.replace(/\_/g, "-");
}
+ get setting() {
+ return this.args.setting;
+ }
+
get settingName() {
return this.setting.label || this.setting.humanized_name;
}
@@ -332,92 +322,101 @@ export default class SiteSettingComponent extends Component {
}
<template>
- <div class="setting-label">
- <h3>
- {{this.settingName}}
-
- {{#if this.staffLogFilter}}
- <LinkTo
- @route="adminLogs.staffActionLogs"
- @query={{hash filters=this.staffLogFilter force_refresh=true}}
- title={{i18n "admin.settings.history"}}
- >
- <span class="history-icon">
- {{icon "clock-rotate-left"}}
- </span>
- </LinkTo>
+ <div
+ data-setting={{this.setting.setting}}
+ class="row setting {{this.typeClass}} {{if this.overridden 'overridden'}}"
+ ...attributes
+ >
+ <div class="setting-label">
+ <h3>
+ {{this.settingName}}
+
+ {{#if this.staffLogFilter}}
+ <LinkTo
+ @route="adminLogs.staffActionLogs"
+ @query={{hash filters=this.staffLogFilter force_refresh=true}}
+ title={{i18n "admin.settings.history"}}
+ >
+ <span class="history-icon">
+ {{icon "clock-rotate-left"}}
+ </span>
+ </LinkTo>
+ {{/if}}
+ </h3>
+
+ {{#if this.defaultIsAvailable}}
+ <DButton
+ class="btn-link"
+ @action={{this.setDefaultValues}}
+ @translatedLabel={{this.setting.setDefaultValuesLabel}}
+ />
{{/if}}
- </h3>
-
- {{#if this.defaultIsAvailable}}
- <DButton
- class="btn-link"
- @action={{this.setDefaultValues}}
- @translatedLabel={{this.setting.setDefaultValuesLabel}}
- />
- {{/if}}
- </div>
+ </div>
- <div class="setting-value">
- {{#if this.settingEditButton}}
- <DButton
- @action={{this.settingEditButton.action}}
- @icon={{this.settingEditButton.icon}}
- @label={{this.settingEditButton.label}}
- class="setting-value-edit-button"
- />
+ <div class="setting-value">
+ {{#if this.settingEditButton}}
+ <DButton
+ @action={{this.settingEditButton.action}}
+ @icon={{this.settingEditButton.icon}}
+ @label={{this.settingEditButton.label}}
+ class="setting-value-edit-button"
+ />
- <Description @description={{this.setting.description}} />
- {{else}}
- <this.resolvedComponent
- @setting={{this.setting}}
- @value={{this.buffered.value}}
- @preview={{this.preview}}
- @isSecret={{this.isSecret}}
- @allowAny={{this.allowAny}}
- @changeValueCallback={{this.changeValueCallback}}
- @setValidationMessage={{this.setValidationMessage}}
- />
- <SettingValidationMessage @message={{this.setting.validationMessage}} />
- {{#if this.displayDescription}}
<Description @description={{this.setting.description}} />
+ {{else}}
+ <this.resolvedComponent
+ {{on "keydown" this._handleKeydown}}
+ @setting={{this.setting}}
+ @value={{this.buffered.value}}
+ @preview={{this.preview}}
+ @isSecret={{this.isSecret}}
+ @allowAny={{this.allowAny}}
+ @changeValueCallback={{this.changeValueCallback}}
+ @setValidationMessage={{this.setValidationMessage}}
+ />
+ <SettingValidationMessage
+ @message={{this.setting.validationMessage}}
+ />
+ {{#if this.displayDescription}}
+ <Description @description={{this.setting.description}} />
+ {{/if}}
{{/if}}
- {{/if}}
- </div>
-
- {{#if this.dirty}}
- <div class="setting-controls">
- <DButton
- @action={{this.update}}
- @icon="check"
- @isLoading={{this.disableControls}}
- @ariaLabel="admin.settings.save"
- class="ok setting-controls__ok"
- />
- <DButton
- @action={{this.cancel}}
- @icon="xmark"
- @isLoading={{this.disableControls}}
- @ariaLabel="admin.settings.cancel"
- class="cancel setting-controls__cancel"
- />
</div>
- {{else if this.overridden}}
- {{#if this.setting.secret}}
+
+ {{#if this.dirty}}
+ <div class="setting-controls">
+ <DButton
+ @action={{this.update}}
+ @icon="check"
+ @isLoading={{this.disableControls}}
+ @ariaLabel="admin.settings.save"
+ class="ok setting-controls__ok"
+ />
+ <DButton
+ @action={{this.cancel}}
+ @icon="xmark"
+ @isLoading={{this.disableControls}}
+ @ariaLabel="admin.settings.cancel"
+ class="cancel setting-controls__cancel"
+ />
+ </div>
+ {{else if this.overridden}}
+ {{#if this.setting.secret}}
+ <DButton
+ @action={{this.toggleSecret}}
+ @icon="far-eye-slash"
+ @ariaLabel="admin.settings.unmask"
+ class="setting-toggle-secret"
+ />
+ {{/if}}
+
<DButton
- @action={{this.toggleSecret}}
- @icon="far-eye-slash"
- @ariaLabel="admin.settings.unmask"
- class="setting-toggle-secret"
+ class="btn-default undo setting-controls__undo"
+ @action={{this.resetDefault}}
+ @icon="arrow-rotate-left"
+ @label="admin.settings.reset"
/>
{{/if}}
-
- <DButton
- class="btn-default undo setting-controls__undo"
- @action={{this.resetDefault}}
- @icon="arrow-rotate-left"
- @label="admin.settings.reset"
- />
- {{/if}}
+ </div>
</template>
}
diff --git a/app/assets/javascripts/admin/addon/components/theme-setting-editor.js b/app/assets/javascripts/admin/addon/components/theme-setting-editor.js
index 5c8e9734356..a6aabc6c5a9 100644
--- a/app/assets/javascripts/admin/addon/components/theme-setting-editor.js
+++ b/app/assets/javascripts/admin/addon/components/theme-setting-editor.js
@@ -3,8 +3,8 @@ import SiteSettingComponent from "./site-setting";
export default class extends SiteSettingComponent {
_save() {
return this.setting.updateSetting(
- this.model.id,
- this.get("buffered.value")
+ this.args.model.id,
+ this.buffered.get("value")
);
}
}
diff --git a/app/assets/javascripts/admin/addon/components/theme-setting-relatives-selector.js b/app/assets/javascripts/admin/addon/components/theme-setting-relatives-selector.js
index 02c7c84b335..df031f4f214 100644
--- a/app/assets/javascripts/admin/addon/components/theme-setting-relatives-selector.js
+++ b/app/assets/javascripts/admin/addon/components/theme-setting-relatives-selector.js
@@ -8,7 +8,8 @@ export default class ThemeSettingRelativesSelectorComponent extends SiteSettingC
}
convertNamesToIds() {
- return this.get("buffered.value")
+ return this.buffered
+ .get("value")
.split("|")
.filter(Boolean)
.map((themeName) => {
diff --git a/app/assets/javascripts/admin/addon/components/theme-translation.js b/app/assets/javascripts/admin/addon/components/theme-translation.js
index 21e88b41e4d..93249e9876d 100644
--- a/app/assets/javascripts/admin/addon/components/theme-translation.js
+++ b/app/assets/javascripts/admin/addon/components/theme-translation.js
@@ -1,23 +1,26 @@
-import { alias } from "@ember/object/computed";
import { ajax } from "discourse/lib/ajax";
-import { url } from "discourse/lib/computed";
+import getURL from "discourse/lib/get-url";
import SiteSettingComponent from "./site-setting";
export default class ThemeTranslation extends SiteSettingComponent {
- @alias("translation") setting;
- @alias("translation.key") settingName;
- @url("model.id", "/admin/themes/%@") updateUrl;
-
type = "string";
+ get setting() {
+ return this.args.translation;
+ }
+
+ get settingName() {
+ return this.args.translation.key;
+ }
+
_save() {
const translations = {
- [this.get("translation.key")]: this.get("buffered.value"),
+ [this.args.translation.key]: this.buffered.get("value"),
};
- return ajax(this.updateUrl, {
+ return ajax(getURL(`/admin/themes/${this.args.model.id}`), {
type: "PUT",
- data: { theme: { translations, locale: this.get("model.locale") } },
+ data: { theme: { translations, locale: this.args.model.locale } },
});
}
}
diff --git a/app/assets/javascripts/discourse-markdown-it/addon-main.cjs b/app/assets/javascripts/discourse-markdown-it/addon-main.cjs
index f868d6b91ec..0c082321106 100644
--- a/app/assets/javascripts/discourse-markdown-it/addon-main.cjs
+++ b/app/assets/javascripts/discourse-markdown-it/addon-main.cjs
@@ -1,4 +1,4 @@
-'use strict';
+"use strict";
-const { addonV1Shim } = require('@embroider/addon-shim');
+const { addonV1Shim } = require("@embroider/addon-shim");
module.exports = addonV1Shim(__dirname);
diff --git a/app/assets/javascripts/discourse/tests/integration/components/site-setting-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/site-setting-test.gjs
index 04615485a94..66197ffcca0 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/site-setting-test.gjs
+++ b/app/assets/javascripts/discourse/tests/integration/components/site-setting-test.gjs
@@ -156,6 +156,27 @@ module("Integration | Component | site-setting", function (hooks) {
.dom("[data-setting='suggested_topics_unread_max_days_old']")
.hasNoClass("overridden");
});
+
+ test("Input for secret site setting is hidden by default", async function (assert) {
+ const self = this;
+
+ this.set(
+ "setting",
+ SiteSetting.create({
+ setting: "test_setting",
+ secret: true,
+ value: "foo",
+ })
+ );
+ await render(
+ <template><SiteSettingComponent @setting={{self.setting}} /></template>
+ );
+ assert.dom(".input-setting-string").hasAttribute("type", "password");
+ await click(".setting-toggle-secret");
+ assert.dom(".input-setting-string").hasAttribute("type", "text");
+ await click(".setting-toggle-secret");
+ assert.dom(".input-setting-string").hasAttribute("type", "password");
+ });
});
module(