From 8e8dca9246d1762c2e9e113471bd21b8e41b5563 Mon Sep 17 00:00:00 2001 From: jbrw Date: Wed, 18 Nov 2020 11:22:19 -0500 Subject: [PATCH] =?UTF-8?q?FIX:=20Selected=20Tag=20Group=20permission=20sh?= =?UTF-8?q?ouldn=E2=80=99t=20change=20during=20save=20(#11274)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `setPermissionsGroups` would initialize an empty permissions object whenever new groups were added to the Tag Group. This meant that if you selected the `visible` permission and then added groups to the Tag Group, the `visible` permission would be obliterated and the Tag Group would be treated as though it was `private`. --- .../discourse/app/components/tag-groups-form.js | 10 +++++++--- .../discourse/tests/acceptance/tag-groups-test.js | 8 +++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/tag-groups-form.js b/app/assets/javascripts/discourse/app/components/tag-groups-form.js index de2d7621009..cc51816677d 100644 --- a/app/assets/javascripts/discourse/app/components/tag-groups-form.js +++ b/app/assets/javascripts/discourse/app/components/tag-groups-form.js @@ -99,14 +99,18 @@ export default Component.extend(bufferedProperty("model"), { }, setPermissionsGroups(groupIds) { - let permissions = {}; + let updatedPermissions = Object.assign( + {}, + this.buffered.get("permissions") + ); + this.allGroups.forEach((group) => { if (groupIds.includes(group.id)) { - permissions[group.name] = PermissionType.FULL; + updatedPermissions[group.name] = PermissionType.FULL; } }); - this.buffered.set("permissions", permissions); + this.buffered.set("permissions", updatedPermissions); }, save() { diff --git a/app/assets/javascripts/discourse/tests/acceptance/tag-groups-test.js b/app/assets/javascripts/discourse/tests/acceptance/tag-groups-test.js index feddcff454f..6c4b2954bb3 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/tag-groups-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/tag-groups-test.js @@ -62,12 +62,18 @@ acceptance("Tag Groups", function (needs) { await tags.expand(); await tags.selectRowByValue("monkey"); - await click("#private-permission"); + await click("#visible-permission"); assert.ok(queryAll(".tag-group-content .btn.btn-default:disabled").length); await groups.expand(); await groups.selectRowByIndex(1); await groups.selectRowByIndex(0); assert.ok(!queryAll(".tag-group-content .btn.btn-default")[0].disabled); + + await click(".tag-group-content .btn.btn-default"); + assert.ok( + exists("#visible-permission:checked"), + "selected permission does not change after saving" + ); }); });