discourse/plugins/discourse-assign/spec/system/group_assigned_spec.rb
Régis HANOL 026eae7352
FIX: show group Assignments tab based on assignable_level (#39085)
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
2026-04-08 16:50:27 +02:00

59 lines
1.9 KiB
Ruby

# frozen_string_literal: true
RSpec.describe "Assign | Group assigned" do
fab!(:admin)
fab!(:group) { Fabricate(:group, assignable_level: Group::ALIAS_LEVELS[:everyone]) }
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic) }
let(:topic_list) { PageObjects::Components::TopicList.new }
let(:topic_list_header) { PageObjects::Components::TopicListHeader.new }
let(:topic_bulk_modal) { PageObjects::Modals::TopicBulkActions.new }
let(:assign_modal) { PageObjects::Modals::Assign.new }
before do
group.add(admin)
SiteSetting.assign_enabled = true
SiteSetting.assign_allowed_on_groups = group.id.to_s
sign_in(admin)
end
it "shows empty state when group has no assignments" do
visit "/g/#{group.name}/assigned/everyone"
expect(page).to have_css(".empty-state")
expect(page).to have_css(".empty-state__title")
end
it "allows to bulk select assigned topics" do
Assigner.new(topic, Discourse.system_user).assign(admin)
visit "/g/#{group.name}/assigned/everyone"
topic_list_header.click_bulk_select_button
topic_list.click_topic_checkbox(topic)
# Click Assign Button
topic_list_header.click_bulk_select_topics_dropdown
expect(topic_list_header).to have_assign_topics_button
topic_list_header.click_assign_topics_button
expect(topic_list_header).to have_bulk_select_modal
# Assign User
assignee = admin.username
select_kit = PageObjects::Components::SelectKit.new("#assignee-chooser")
# This initial collapse is needed because for some reason the modal is
# opening with `is-expanded` property, but it isn't actually expanded.
select_kit.collapse
select_kit.search(assignee)
select_kit.select_row_by_value(assignee)
select_kit.collapse
# Click Confirm
topic_list_header.click_bulk_topics_confirm
expect(topic_bulk_modal).to be_closed
expect(Assignment.find_by(topic: topic).assigned_to).to eq(admin)
end
end