Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 3dc1249

Browse files
committed
Only allow update password if there is a session
1 parent aad8ebf commit 3dc1249

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

api/app/controllers/retros_controller.rb

+7-11
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@
3131
class RetrosController < ApplicationController
3232
include RetrosAuth
3333

34-
before_action :load_and_authenticate_retro, only: [:show, :update_password]
35-
before_action :authenticate_user, only: [:create, :index]
36-
before_action :load_and_authenticate_retro_admin, only: [:archive, :update]
34+
before_action :authenticate_user, only: [:index, :create]
35+
before_action :load_and_authenticate_retro, only: [:show]
36+
before_action :load_and_authenticate_retro_admin, only: [:archive, :update, :update_password]
37+
38+
def index
39+
render json: { retros: @user.retros }
40+
end
3741

3842
def create
3943
@retro = @user.retros.create(retro_params)
@@ -48,10 +52,6 @@ def create
4852
end
4953
end
5054

51-
def index
52-
render json: { retros: @user.retros }
53-
end
54-
5555
def update
5656
@retro.assign_attributes(retro_update_params.fetch(:retro))
5757

@@ -120,8 +120,4 @@ def retro_update_params
120120
def retro_update_password_params
121121
params.permit(:id, :current_password, :new_password, :request_uuid)
122122
end
123-
124-
def load_retro_with_items
125-
@retro = Retro.includes(:items, :action_items).find_by_slug!(params.fetch(:id))
126-
end
127123
end

api/config/routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
resources :oauth_sessions, path: 'sessions', only: [:create]
4141
resources :users, only: [:create]
4242

43-
resources :retros, only: [:create, :index, :show, :update] do
43+
resources :retros, only: [:index, :create, :show, :update] do
4444
resources :archives, only: [:index, :show]
4545
resources :settings, only: [:index]
4646
resources :action_items, only: [:create, :destroy, :update]

api/spec/requests/retros_request_spec.rb

+14-2
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,13 @@
419419
retro.update!(password: 'before')
420420

421421
patch retro_update_password_path(retro),
422-
params: { current_password: 'before', new_password: 'after', request_uuid: 'blah' }, as: :json
422+
headers: { HTTP_AUTHORIZATION: token },
423+
params: {
424+
current_password: 'before',
425+
new_password: 'after',
426+
request_uuid: 'blah'
427+
},
428+
as: :json
423429

424430
expect(response.status).to eq(200)
425431

@@ -430,7 +436,13 @@
430436
it 'returns unprocessable entity when current password does not match' do
431437
retro.update!(password: 'bleah')
432438

433-
patch retro_update_password_path(retro), params: { current_password: 'before', new_password: 'after' }, as: :json
439+
patch retro_update_password_path(retro),
440+
headers: { HTTP_AUTHORIZATION: token },
441+
params: {
442+
current_password: 'before',
443+
new_password: 'after'
444+
},
445+
as: :json
434446

435447
expect(response.status).to eq(422)
436448
expect(retro.validate_login?('bleah')).to eq(true)

0 commit comments

Comments
 (0)