Skip to content

Commit 9fe4132

Browse files
authored
fix: raise not-found for unauthorized conversations (#1059)
## Summary - raise `ActiveRecord::RecordNotFound` when accessing conversations not belonging to the current user - add request spec to ensure non-participants receive a 404 response ## Testing - `bin/dc-run bundle exec rubocop` *(fails: docker: command not found)* - `bin/codex_style_guard` *(fails: bundler: command not found: rubocop)* - `bin/dc-run bundle exec brakeman --quiet --no-pager` *(fails: docker: command not found)* - `bin/dc-run bundle exec bundler-audit --update` *(fails: docker: command not found)* - `bin/dc-run bin/i18n` *(fails: docker: command not found)* - `bin/dc-run bin/ci` *(fails: docker: command not found)* ------ https://chatgpt.com/codex/tasks/task_e_68b1f69223b88321bb27a78b2da20f6d
2 parents ca5e351 + 4900c4f commit 9fe4132

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

app/controllers/better_together/conversations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def set_conversation # rubocop:todo Metrics/MethodLength
226226
:contact_detail,
227227
{ profile_image_attachment: :blob }
228228
])
229-
@conversation = scope.find_by(id: params[:id])
229+
@conversation = scope.find(params[:id])
230230
@set_conversation ||= Conversation.includes(participants: [
231231
:string_translations,
232232
:contact_detail,

spec/requests/better_together/conversations_request_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@
8080
end
8181
end
8282

83+
describe 'GET /conversations/:id' do
84+
context 'as a non-participant', :as_user do # rubocop:todo RSpec/ContextWording
85+
it 'returns not found' do
86+
conversation = create('better_together/conversation', creator: manager_user.person).tap do |c|
87+
c.participants << manager_user.person unless c.participants.exists?(manager_user.person.id)
88+
end
89+
90+
get better_together.conversation_path(conversation, locale: I18n.default_locale)
91+
expect(response).to have_http_status(:not_found)
92+
end
93+
end
94+
end
95+
8396
describe 'PATCH /conversations/:id' do
8497
context 'as a regular member', :as_user do # rubocop:todo RSpec/ContextWording
8598
let!(:conversation) do

0 commit comments

Comments
 (0)