mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-16 18:05:35 +08:00
Policy nodes in the rich editor now display a summary of their attributes (groups, version, renew, accept, etc.) and expose an edit button that opens the policy builder modal pre-populated with the current values. Changes are applied directly to the node, so policies can be tweaked without dropping back to markdown source. Also migrates the policy builder form to FormKit, replacing the bespoke `policy-form-field` component. This brings tooltips, proper field-level validation and a layout consistent with the rest of the UI. The "add users to group" picker now excludes automatic groups, which cannot be assigned to. Before: <img width="1238" height="337" alt="image" src="https://github.com/user-attachments/assets/44b21b44-a669-4474-8d14-5855326debfa" /> <img width="1030" height="1539" alt="image" src="https://github.com/user-attachments/assets/a816a491-ba25-4b0a-aa50-cbee32c60962" /> After: <img width="1280" height="574" alt="image" src="https://github.com/user-attachments/assets/6c4b4e18-674d-4e5a-be20-6008c730d348" /> <img width="1160" height="1499" alt="image" src="https://github.com/user-attachments/assets/7d47782c-9b53-43ee-b135-3bb3a2b9ae43" />
136 lines
4.2 KiB
JavaScript
136 lines
4.2 KiB
JavaScript
import { click, fillIn, visit } from "@ember/test-helpers";
|
|
import { test } from "qunit";
|
|
import { cloneJSON } from "discourse/lib/object";
|
|
import postFixtures from "discourse/tests/fixtures/post";
|
|
import topicFixtures from "discourse/tests/fixtures/topic";
|
|
import pretender, {
|
|
parsePostData,
|
|
response,
|
|
} from "discourse/tests/helpers/create-pretender";
|
|
import {
|
|
acceptance,
|
|
updateCurrentUser,
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
|
import { i18n } from "discourse-i18n";
|
|
|
|
acceptance("post", function (needs) {
|
|
needs.user();
|
|
|
|
needs.settings({
|
|
policy_enabled: true,
|
|
});
|
|
|
|
needs.pretender((server, helper) => {
|
|
const topic = cloneJSON(topicFixtures["/t/130.json"]);
|
|
const post = cloneJSON(postFixtures["/posts/18"]);
|
|
|
|
post.topic_id = topic.id;
|
|
post.policy_can_accept = true;
|
|
post.cooked = `<div class=\"policy\" data-group=\"everyone\" data-version=\"1\">\n<p>test</p>\n</div>`;
|
|
|
|
topic.post_stream = {
|
|
posts: [post],
|
|
stream: [post.id],
|
|
};
|
|
|
|
server.get("/t/130.json", () => helper.response(topic));
|
|
server.put("/policy/accept", () => helper.response(200, {}));
|
|
server.put("/policy/unaccept", () => helper.response(200, {}));
|
|
});
|
|
|
|
test("insert a policy", async function (assert) {
|
|
updateCurrentUser({ can_create_policy: true });
|
|
await visit("/t/-/130");
|
|
await click(".actions .edit");
|
|
|
|
await fillIn("textarea.d-editor-input", "");
|
|
|
|
await click(".toolbar-menu__options-trigger");
|
|
await click(`button[title="${i18n("discourse_policy.builder.attach")}"]`);
|
|
await selectKit(".group-chooser").expand();
|
|
await selectKit(".group-chooser").fillInFilter("staff");
|
|
await selectKit(".group-chooser").selectRowByValue("staff");
|
|
await selectKit(".group-chooser").collapse();
|
|
|
|
await selectKit(".combo-box").expand();
|
|
await selectKit(".combo-box").selectRowByIndex(0);
|
|
|
|
await click(".d-modal__footer .btn-primary");
|
|
|
|
let raw = document.querySelector("textarea.d-editor-input").value;
|
|
|
|
assert.strictEqual(
|
|
raw.trim(),
|
|
'[policy groups="staff" version="1" reminder="daily"]\nI accept this policy\n[/policy]'
|
|
);
|
|
});
|
|
|
|
test("edit email preferences", async function (assert) {
|
|
let savedData;
|
|
pretender.put("/u/eviltrout.json", (request) => {
|
|
savedData = parsePostData(request.requestBody);
|
|
return response({ user: {} });
|
|
});
|
|
|
|
await visit(`/u/eviltrout/preferences/emails`);
|
|
assert.dom("#user_policy_email_frequency").exists();
|
|
|
|
const dropdown = selectKit("#user_policy_email_frequency");
|
|
await dropdown.expand();
|
|
await dropdown.selectRowByValue("never");
|
|
|
|
await click(".save-changes");
|
|
|
|
assert.strictEqual(
|
|
savedData.policy_email_frequency,
|
|
"never",
|
|
"policy_email_frequency is included in saved data"
|
|
);
|
|
});
|
|
|
|
test("edit policy - staff", async function (assert) {
|
|
await visit("/t/-/130");
|
|
await click(".edit-policy-settings-btn");
|
|
|
|
assert.dom(".policy-builder").exists();
|
|
await selectKit(".group-chooser").expand();
|
|
await selectKit(".group-chooser").selectRowByName("admins");
|
|
await selectKit(".group-chooser").selectRowByName("moderators");
|
|
await selectKit(".group-chooser").collapse();
|
|
|
|
await assert.strictEqual(
|
|
selectKit(".group-chooser").header().value(),
|
|
"admins,moderators"
|
|
);
|
|
});
|
|
|
|
test("edit policy - not staff", async function (assert) {
|
|
updateCurrentUser({ moderator: false, admin: false });
|
|
await visit("/t/-/130");
|
|
|
|
assert.dom(".edit-policy-settings-btn").doesNotExist();
|
|
});
|
|
|
|
test("edit policy - not staff, post owner", async function (assert) {
|
|
updateCurrentUser({ moderator: false, admin: false, id: 1 });
|
|
await visit("/t/-/130");
|
|
|
|
assert.dom(".edit-policy-settings-btn").exists();
|
|
});
|
|
|
|
test("accept a policy", async function (assert) {
|
|
await visit("/t/-/130");
|
|
await click(".btn-accept-policy");
|
|
|
|
assert.dom(".btn-revoke-policy").exists();
|
|
});
|
|
|
|
test("revoke a policy", async function (assert) {
|
|
await visit("/t/-/130");
|
|
await click(".btn-accept-policy");
|
|
await click(".btn-revoke-policy");
|
|
|
|
assert.dom(".btn-accept-policy").exists();
|
|
});
|
|
});
|