FEATURE: Configure poll 'public' default via site setting (#24348)

Followup to 7e37e3e824
This commit is contained in:
David Taylor 2023-11-13 18:54:21 +00:00 committed by GitHub
parent 797da5870b
commit f395130429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import Component from "@ember/component"; import Component from "@ember/component";
import EmberObject, { action } from "@ember/object"; import EmberObject, { action } from "@ember/object";
import { gt, or } from "@ember/object/computed"; import { gt, or } from "@ember/object/computed";
import { inject as service } from "@ember/service";
import { observes } from "@ember-decorators/object"; import { observes } from "@ember-decorators/object";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import I18n from "discourse-i18n"; import I18n from "discourse-i18n";
@ -18,6 +19,8 @@ const CLOSED_POLL_RESULT = "on_close";
const STAFF_POLL_RESULT = "staff_only"; const STAFF_POLL_RESULT = "staff_only";
export default class PollUiBuilderModal extends Component { export default class PollUiBuilderModal extends Component {
@service siteSettings;
showAdvanced = false; showAdvanced = false;
pollType = REGULAR_POLL_TYPE; pollType = REGULAR_POLL_TYPE;
pollTitle; pollTitle;
@ -30,7 +33,7 @@ export default class PollUiBuilderModal extends Component {
pollAutoClose; pollAutoClose;
pollResult = ALWAYS_POLL_RESULT; pollResult = ALWAYS_POLL_RESULT;
chartType = BAR_CHART_TYPE; chartType = BAR_CHART_TYPE;
publicPoll = true; publicPoll = this.siteSettings.poll_default_public;
@or("showAdvanced", "isNumber") showNumber; @or("showAdvanced", "isNumber") showNumber;
@gt("pollOptions.length", 1) canRemoveOption; @gt("pollOptions.length", 1) canRemoveOption;

View File

@ -6,6 +6,7 @@ en:
poll_minimum_trust_level_to_create: "Define the minimum trust level needed to create polls." poll_minimum_trust_level_to_create: "Define the minimum trust level needed to create polls."
poll_groupable_user_fields: "A set of user field names that can be used to group and filter poll results." poll_groupable_user_fields: "A set of user field names that can be used to group and filter poll results."
poll_export_data_explorer_query_id: "ID of the Data Explorer Query to use for exporting poll results (0 to disable)." poll_export_data_explorer_query_id: "ID of the Data Explorer Query to use for exporting poll results (0 to disable)."
poll_default_public: "When creating a new poll, enable the 'show who voted' option by default."
poll: poll:
poll: "poll" poll: "poll"

View File

@ -22,3 +22,6 @@ plugins:
default: -16 default: -16
min: -9999 min: -9999
client: true client: true
poll_default_public:
default: true
client: true

View File

@ -211,4 +211,22 @@ module("Poll | Component | poll-ui-builder", function (hooks) {
); );
await resultVisibility.collapse(); await resultVisibility.collapse();
}); });
test("default public value can be controlled with site setting", async function (assert) {
this.siteSettings.poll_default_public = false;
const results = await setupBuilder(this);
await fillIn(".poll-option-value input", "a");
await click(".poll-option-add");
await fillIn(".poll-option-value:nth-of-type(2) input", "b");
await click(".insert-poll");
assert.strictEqual(
results[results.length - 1],
"[poll type=regular results=always public=false chartType=bar]\n* a\n* b\n[/poll]\n",
"can be set to private boolean"
);
});
}); });