From e4849445ceb93941b9b80a54660bb97179b7ff97 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Wed, 13 Sep 2023 19:21:44 +0530 Subject: [PATCH] UX: hide warning if all users mentioned via group are already invited. (#23557) Previously, a "`some_not_allowed`" warning message was appeared in composer even when all the users mentioned via group are already invited to the private message directly or via other groups. --- app/controllers/composer_controller.rb | 8 ++++++-- spec/requests/composer_controller_spec.rb | 10 +++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/controllers/composer_controller.rb b/app/controllers/composer_controller.rb index d87441a5615..d8bc8625186 100644 --- a/app/controllers/composer_controller.rb +++ b/app/controllers/composer_controller.rb @@ -65,8 +65,12 @@ class ComposerController < ApplicationController .count if notified_count > 0 - group_reasons[group.name] = :some_not_allowed - serialized_group[:notified_count] = notified_count + if notified_count == group.user_count + group_reasons.delete(group.name) + else + group_reasons[group.name] = :some_not_allowed + serialized_group[:notified_count] = notified_count + end end end diff --git a/spec/requests/composer_controller_spec.rb b/spec/requests/composer_controller_spec.rb index 76297223d5c..3e85ca1098c 100644 --- a/spec/requests/composer_controller_spec.rb +++ b/spec/requests/composer_controller_spec.rb @@ -185,7 +185,6 @@ RSpec.describe ComposerController do other_group = Fabricate(:group, mentionable_level: Group::ALIAS_LEVELS[:everyone]) other_group.add(allowed_user) other_group.add(user) - other_group.add(Fabricate(:user)) # Trying to mention other_group which has not been invited, but two of # its members have been (allowed_user directly and user via group). @@ -193,6 +192,15 @@ RSpec.describe ComposerController do expect(response.status).to eq(200) + expect(response.parsed_body["groups"]).to eq(other_group.name => { "user_count" => 2 }) + expect(response.parsed_body["group_reasons"]).to be_empty + + other_group.add(Fabricate(:user)) + + get "/composer/mentions.json", params: { names: [other_group.name], topic_id: topic.id } + + expect(response.status).to eq(200) + expect(response.parsed_body["groups"]).to eq( other_group.name => { "user_count" => 3,