FIX: Show restricted groups warning when necessary (#16236)

It was displayed for the "everyone" group too, but that was not
necessary.
This commit is contained in:
Bianca Nenciu 2022-03-28 19:38:29 +03:00 committed by GitHub
parent c219740274
commit 3fd7b31a2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 22 deletions

View File

@ -28,13 +28,42 @@ export default Controller.extend(
allowInvites: false, allowInvites: false,
}); });
if (this.model && this.model.read_restricted) { this.appEvents.on(
this.restrictedGroupWarning(); "modal:body-shown",
} this,
this.showRestrictedGroupWarning
);
scheduleOnce("afterRender", this, this.selectUrl); scheduleOnce("afterRender", this, this.selectUrl);
}, },
onClose() {
this.appEvents.off(
"modal:body-shown",
this,
this.showRestrictedGroupWarning
);
},
showRestrictedGroupWarning() {
if (!this.model) {
return;
}
Category.reloadBySlugPath(this.model.slug).then((result) => {
const groups = result.category.group_permissions.mapBy("group_name");
if (groups && !groups.any((x) => x === "everyone")) {
this.flash(
I18n.t("topic.share.restricted_groups", {
count: groups.length,
groups: groups.join(", "),
}),
"warning"
);
}
});
},
selectUrl() { selectUrl() {
const input = document.querySelector("input.invite-link"); const input = document.querySelector("input.invite-link");
if (input && !this.site.mobileView) { if (input && !this.site.mobileView) {
@ -105,24 +134,5 @@ export default Controller.extend(
topicController.actions.replyAsNewTopic.call(topicController, post); topicController.actions.replyAsNewTopic.call(topicController, post);
this.send("closeModal"); this.send("closeModal");
}, },
restrictedGroupWarning() {
this.appEvents.on("modal:body-shown", () => {
let restrictedGroups;
Category.reloadBySlugPath(this.model.slug).then((result) => {
restrictedGroups = result.category.group_permissions.map(
(g) => g.group_name
);
if (restrictedGroups) {
const message = I18n.t("topic.share.restricted_groups", {
count: restrictedGroups.length,
groupNames: restrictedGroups.join(", "),
});
this.flash(message, "warning");
}
});
});
},
} }
); );

View File

@ -1,3 +1,4 @@
import CategoryFixtures from "discourse/tests/fixtures/category-fixtures";
import { click, visit } from "@ember/test-helpers"; import { click, visit } from "@ember/test-helpers";
import { import {
acceptance, acceptance,
@ -10,6 +11,12 @@ import { test } from "qunit";
acceptance("Share and Invite modal", function (needs) { acceptance("Share and Invite modal", function (needs) {
needs.user(); needs.user();
needs.pretender((server, helper) => {
server.get("/c/feature/find_by_slug.json", () =>
helper.response(200, CategoryFixtures["/c/1/show.json"])
);
});
test("Topic footer button", async function (assert) { test("Topic footer button", async function (assert) {
await visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");

View File

@ -21,10 +21,14 @@ import { test } from "qunit";
import { withPluginApi } from "discourse/lib/plugin-api"; import { withPluginApi } from "discourse/lib/plugin-api";
import topicFixtures from "discourse/tests/fixtures/topic"; import topicFixtures from "discourse/tests/fixtures/topic";
import { cloneJSON } from "discourse-common/lib/object"; import { cloneJSON } from "discourse-common/lib/object";
import CategoryFixtures from "discourse/tests/fixtures/category-fixtures";
acceptance("Topic", function (needs) { acceptance("Topic", function (needs) {
needs.user(); needs.user();
needs.pretender((server, helper) => { needs.pretender((server, helper) => {
server.get("/c/feature/find_by_slug.json", () => {
return helper.response(200, CategoryFixtures["/c/1/show.json"]);
});
server.put("/posts/398/wiki", () => { server.put("/posts/398/wiki", () => {
return helper.response({}); return helper.response({});
}); });