diff --git a/app/assets/javascripts/discourse/app/controllers/share-topic.js b/app/assets/javascripts/discourse/app/controllers/share-topic.js index 3c54976d9b5..c693cf9190f 100644 --- a/app/assets/javascripts/discourse/app/controllers/share-topic.js +++ b/app/assets/javascripts/discourse/app/controllers/share-topic.js @@ -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"); - } - }); - }); - }, } ); diff --git a/app/assets/javascripts/discourse/tests/acceptance/share-topic-test.js b/app/assets/javascripts/discourse/tests/acceptance/share-topic-test.js index 0823af574f4..26f2509c0a0 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/share-topic-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/share-topic-test.js @@ -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"); diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-test.js index 8d0a61ca496..131b437a2af 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/topic-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/topic-test.js @@ -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({}); });