refactor procedure_controller
This commit is contained in:
parent
40a15b9be4
commit
4a17dec87b
2 changed files with 5 additions and 12 deletions
|
@ -1,5 +1,6 @@
|
|||
class API::V1::ProceduresController < APIController
|
||||
before_action :fetch_procedure_and_check_token
|
||||
before_action :check_api_token
|
||||
before_action :fetch_procedure
|
||||
|
||||
def show
|
||||
render json: { procedure: ProcedureSerializer.new(@procedure).as_json }
|
||||
|
@ -7,17 +8,9 @@ class API::V1::ProceduresController < APIController
|
|||
|
||||
private
|
||||
|
||||
def fetch_procedure_and_check_token
|
||||
@procedure = Procedure.for_api.find(params[:id])
|
||||
def fetch_procedure
|
||||
@procedure = @api_token.procedures.for_api.find(params[:id])
|
||||
|
||||
administrateur = find_administrateur_for_token(@procedure)
|
||||
if administrateur.nil?
|
||||
render json: {}, status: :unauthorized
|
||||
else
|
||||
# allow BaseController append_info_to_payload
|
||||
# to log info on current_user
|
||||
@current_user = administrateur.user
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render json: {}, status: :not_found
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ describe API::V1::ProceduresController, type: :controller do
|
|||
context 'when procedure belongs to administrateur without token' do
|
||||
let(:procedure_id) { create(:procedure).id }
|
||||
|
||||
it { is_expected.to have_http_status(401) }
|
||||
it { is_expected.to have_http_status(404) }
|
||||
end
|
||||
|
||||
context 'when procedure exist but bad token' do
|
||||
|
|
Loading…
Reference in a new issue