Skip to content

A platform for community discussion. Free, open, simple.

FIX: new group without page refresh (#39075)

David Battersbya6024a81a5b6
diff --git a/frontend/discourse/app/controllers/groups/new.js b/frontend/discourse/app/controllers/groups/new.js
index 7498dbe1c4c..fb7364b3fd2 100644
--- a/frontend/discourse/app/controllers/groups/new.js
+++ b/frontend/discourse/app/controllers/groups/new.js
@@ -5,6 +5,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
export default class GroupsNewController extends Controller {
@service router;
+ @service site;
@service groupAutomaticMembersDialog;
saving = null;
@@ -41,6 +42,14 @@ export default class GroupsNewController extends Controller {
group
.create()
.then(() => {
+ this.site.groups.push({
+ id: group.id,
+ name: group.name,
+ flair_url: group.flair_url,
+ flair_bg_color: group.flair_bg_color,
+ flair_color: group.flair_color,
+ automatic: false,
+ });
this.router.transitionTo("group.members", group.name);
})
.catch(popupAjaxError)
diff --git a/frontend/discourse/tests/acceptance/groups-new-test.js b/frontend/discourse/tests/acceptance/groups-new-test.js
index b48fd5e91eb..74ee0a51071 100644
--- a/frontend/discourse/tests/acceptance/groups-new-test.js
+++ b/frontend/discourse/tests/acceptance/groups-new-test.js
@@ -1,5 +1,6 @@
import { click, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
+import Site from "discourse/models/site";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n";
@@ -15,6 +16,37 @@ acceptance("New Group - Anonymous", function () {
acceptance("New Group - Authenticated", function (needs) {
needs.user();
+ needs.pretender((server, helper) => {
+ server.post("/admin/groups", () => {
+ return helper.response(200, {
+ basic_group: {
+ id: 99,
+ name: "site-moderators",
+ flair_url: null,
+ flair_bg_color: null,
+ flair_color: null,
+ automatic: false,
+ },
+ });
+ });
+ server.get("/groups/site-moderators.json", () => {
+ return helper.response(200, {
+ group: {
+ id: 99,
+ name: "site-moderators",
+ automatic: false,
+ user_count: 0,
+ },
+ extras: { visible_group_names: ["site-moderators"] },
+ });
+ });
+ server.get("/groups/site-moderators/members.json", () => {
+ return helper.response(200, {
+ members: [],
+ meta: { total: 0, limit: 50, offset: 0 },
+ });
+ });
+ });
test("Creating a new group", async function (assert) {
await visit("/g");
@@ -54,7 +86,7 @@ acceptance("New Group - Authenticated", function (needs) {
"it should show the right validation tooltip"
);
- await fillIn("input[name='name']", "good-username");
+ await fillIn("input[name='name']", "site-moderators");
assert
.dom(".tip.good")
@@ -76,4 +108,23 @@ acceptance("New Group - Authenticated", function (needs) {
"has a default selection for notification level"
);
});
+
+ test("Creating a group adds it to site groups", async function (assert) {
+ const initialGroupCount = Site.current().groups.length;
+
+ await visit("/g/custom/new");
+ await fillIn("input[name='name']", "site-moderators");
+ await click(".group-form-save");
+
+ assert.strictEqual(
+ Site.current().groups.length,
+ initialGroupCount + 1,
+ "site.groups has the new group"
+ );
+
+ const newGroup = Site.current().groups.find(
+ (g) => g.name === "site-moderators"
+ );
+ assert.strictEqual(newGroup.id, 99);
+ });
});