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 Gerhard Schlager
parent 7b5ef41a43
commit 1516dd75f5
3 changed files with 42 additions and 21 deletions

View File

@ -21,9 +21,38 @@ export default Controller.extend(
onShow() {
this.set("showNotifyUsers", false);
if (this.model && this.model.read_restricted) {
this.restrictedGroupWarning();
this.appEvents.on(
"modal:body-shown",
this,
this.showRestrictedGroupWarning
);
},
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"
);
}
});
},
@discourseComputed("topic.shareUrl")
@ -111,24 +140,5 @@ export default Controller.extend(
topicTitle: this.topic.title,
});
},
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 {
acceptance,
@ -11,6 +12,12 @@ import { test } from "qunit";
acceptance("Share and Invite modal", function (needs) {
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) {
await visit("/t/internationalization-localization/280");

View File

@ -20,10 +20,14 @@ import { skip, test } from "qunit";
import { withPluginApi } from "discourse/lib/plugin-api";
import topicFixtures from "discourse/tests/fixtures/topic";
import { cloneJSON } from "discourse-common/lib/object";
import CategoryFixtures from "discourse/tests/fixtures/category-fixtures";
acceptance("Topic", function (needs) {
needs.user();
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", () => {
return helper.response({});
});