mirror of
https://github.com/discourse/discourse.git
synced 2026-08-13 13:17:29 +08:00
The Assignments tab on group pages had two problematic visibility conditions that caused it to disappear unexpectedly: 1. `can_show_assigned_tab?` checked whether ALL members of the group belonged to an `assign_allowed_on_groups` group. This meant a single member outside those groups would hide the tab for everyone — even when the group was fully assignable and had active assignments. 2. The frontend required `assignment_count > 0`, so the tab silently vanished when the last assignment was resolved, with no indication of whether the feature was unconfigured or simply empty. The root cause is that tab visibility was answering the wrong question: "can all members use the assign feature?" instead of "is this group set up to receive assignments?" This replaces the member-overlap SQL in `can_show_assigned_tab?` with a simple check on `assignable_level > nobody` — the setting that actually controls whether a group can receive assignments. The `assignment_count > 0` gate is removed from the frontend so the tab stays visible with an empty state, consistent with other group tabs. Also fixes the `assign_allowed_on_groups` setting description which incorrectly stated it controls who can be assigned topics (that's `assignable_level`). Ref - t/179679
61 lines
2 KiB
Ruby
Vendored
61 lines
2 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe Group do
|
|
let(:group) { Fabricate(:group) }
|
|
|
|
before { SiteSetting.assign_enabled = true }
|
|
|
|
describe "Tracking changes that could affect the allow assign on groups site setting" do
|
|
let(:removed_group_setting) { "3|4" }
|
|
let(:group_attribute) { group.id }
|
|
|
|
it "removes the group from the setting when the group gets destroyed" do
|
|
SiteSetting.assign_allowed_on_groups = "#{group_attribute}|#{removed_group_setting}"
|
|
|
|
group.destroy!
|
|
|
|
expect(SiteSetting.assign_allowed_on_groups).to eq removed_group_setting
|
|
end
|
|
|
|
it "removes the group from the setting when this is the last one on the list" do
|
|
SiteSetting.assign_allowed_on_groups = "#{removed_group_setting}|#{group_attribute}"
|
|
|
|
group.destroy!
|
|
|
|
expect(SiteSetting.assign_allowed_on_groups).to eq removed_group_setting
|
|
end
|
|
|
|
it "removes the group from the list when it is on the middle of the list" do
|
|
allowed_groups = "3|#{group_attribute}|4"
|
|
SiteSetting.assign_allowed_on_groups = allowed_groups
|
|
|
|
group.destroy!
|
|
|
|
expect(SiteSetting.assign_allowed_on_groups).to eq removed_group_setting
|
|
end
|
|
end
|
|
|
|
describe "#can_show_assigned_tab?" do
|
|
it "returns false when assignable_level is nobody" do
|
|
group.update!(assignable_level: Group::ALIAS_LEVELS[:nobody])
|
|
expect(group.can_show_assigned_tab?).to eq(false)
|
|
end
|
|
|
|
it "returns true when assignable_level is only_admins" do
|
|
group.update!(assignable_level: Group::ALIAS_LEVELS[:only_admins])
|
|
expect(group.can_show_assigned_tab?).to eq(true)
|
|
end
|
|
|
|
it "returns true when assignable_level is everyone" do
|
|
group.update!(assignable_level: Group::ALIAS_LEVELS[:everyone])
|
|
expect(group.can_show_assigned_tab?).to eq(true)
|
|
end
|
|
|
|
it "does not depend on group members being in assign_allowed_on_groups" do
|
|
user = Fabricate(:user)
|
|
group.update!(assignable_level: Group::ALIAS_LEVELS[:everyone])
|
|
group.add(user)
|
|
expect(group.can_show_assigned_tab?).to eq(true)
|
|
end
|
|
end
|
|
end
|