FIX: Do not preview chat channels to read-only users (#21700)

We want to simplify this case as it contains a lot of rabbit holes.
This commit is contained in:
Jan Cernik 2023-05-24 09:05:20 -03:00 committed by GitHub
parent 4332f4b833
commit 436b68a581
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 43 deletions

View File

@ -121,7 +121,7 @@ class Chat::Api::ChannelsController < Chat::ApiController
@channel ||=
begin
channel = Chat::Channel.find(params.require(:channel_id))
guardian.ensure_can_preview_chat_channel!(channel)
guardian.ensure_can_join_chat_channel!(channel)
channel
end
end

View File

@ -230,7 +230,7 @@ module Chat
end
raise Discourse::NotFound if chat_channel.blank?
raise Discourse::InvalidAccess if !guardian.can_preview_chat_channel?(chat_channel)
raise Discourse::InvalidAccess if !guardian.can_join_chat_channel?(chat_channel)
chat_channel
end
end

View File

@ -1125,7 +1125,7 @@ RSpec.describe Chat::ChatController do
channel = Fabricate(:category_channel, chatable: Fabricate(:category))
message = Fabricate(:chat_message, chat_channel: channel)
Guardian.any_instance.expects(:can_preview_chat_channel?).with(channel)
Guardian.any_instance.expects(:can_join_chat_channel?).with(channel)
sign_in(Fabricate(:user))
get "/chat/message/#{message.id}.json"
@ -1141,7 +1141,7 @@ RSpec.describe Chat::ChatController do
before { sign_in(user) }
it "ensures message's channel can be seen" do
Guardian.any_instance.expects(:can_preview_chat_channel?).with(channel)
Guardian.any_instance.expects(:can_join_chat_channel?).with(channel)
get "/chat/lookup/#{message.id}.json", params: { chat_channel_id: channel.id }
end

View File

@ -50,35 +50,6 @@ RSpec.describe "JIT messages", type: :system, js: true do
)
end
end
context "when user cant access a non read_restrictd channel" do
let!(:everyone) { Group.find(Group::AUTO_GROUPS[:everyone]) }
fab!(:category) { Fabricate(:category) }
fab!(:readonly_channel) { Fabricate(:category_channel, chatable: category) }
before do
Fabricate(
:category_group,
category: category,
group: everyone,
permission_type: CategoryGroup.permission_types[:readonly],
)
everyone.add(other_user)
readonly_channel.add(current_user)
end
it "displays a mention warning" do
Jobs.run_immediately!
chat.visit_channel(readonly_channel)
channel.send_message("hi @#{other_user.username}")
expect(page).to have_content(
I18n.t("js.chat.mention_warning.cannot_see", username: other_user.username),
wait: 5,
)
end
end
end
context "when category channel permission is readonly for everyone" do

View File

@ -110,17 +110,10 @@ RSpec.describe "Visit channel", type: :system, js: true do
)
end
it "doesn't allow user to join it" do
chat.visit_channel(readonly_category_channel_1)
it "shows an error" do
chat.visit_channel(inaccessible_dm_channel_1)
expect(page).not_to have_content(I18n.t("js.chat.channel_settings.join_channel"))
end
it "shows a preview of the channel" do
chat.visit_channel(readonly_category_channel_1)
expect(page).to have_content(readonly_category_channel_1.name)
expect(chat).to have_message(message_1)
expect(page).to have_content(I18n.t("invalid_access"))
end
end