Skip to content

Commit c4ba269

Browse files
committed
feat: keep profiles hidden for non participants
1 parent 022d6c9 commit c4ba269

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

app/controllers/users_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ class UsersController < ApplicationController
1010

1111
def index; end
1212

13-
def show; end
13+
def show
14+
raise ActiveRecord::RecordNotFound if current_user != user && user.events.none? && user.participants.none?
15+
end
1416

1517
def edit
1618
return unless current_user.missing_name?

spec/controllers/users_controller_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,34 @@
3030
context 'when user has no email' do
3131
render_views
3232

33-
before { user.update!(email: nil) }
33+
before do
34+
user.update!(email: nil)
35+
allow(@controller).to receive_messages(current_user: user)
36+
end
3437

3538
it 'does not fail' do
3639
get :show, params: { id: user.id }
3740
expect(response).to be_ok
3841
end
3942
end
43+
44+
context 'when player never participated' do
45+
it 'renders not found' do
46+
get :show, params: { id: user }
47+
expect(response).to be_not_found
48+
end
49+
end
50+
51+
context 'when player views his own profile, but did not participate yet' do
52+
before do
53+
allow(@controller).to receive_messages(current_user: user)
54+
end
55+
56+
it 'shows the user profile' do
57+
get :show, params: { id: user }
58+
expect(response).to be_ok
59+
end
60+
end
4061
end
4162

4263
context 'GET :edit' do

0 commit comments

Comments
 (0)