demarches-normaliennes/app/controllers/new_administrateur/jeton_particulier_controller.rb

46 lines
1.1 KiB
Ruby
Raw Normal View History

module NewAdministrateur
class JetonParticulierController < AdministrateurController
before_action :retrieve_procedure
def api_particulier
end
def show
end
def update
@procedure.api_particulier_token = token
2021-09-16 09:09:26 +02:00
if @procedure.invalid?
flash.now.alert = @procedure.errors.full_messages
render :show
elsif scopes.empty?
flash.now.alert = t('.no_scopes_token')
render :show
else
@procedure.update!(api_particulier_scopes: scopes, api_particulier_sources: {})
redirect_to admin_procedure_api_particulier_sources_path(procedure_id: @procedure.id),
2021-09-09 19:48:34 +02:00
notice: t('.token_ok')
end
2021-09-16 09:09:26 +02:00
rescue APIParticulier::Error::Unauthorized
2021-09-09 19:48:34 +02:00
flash.now.alert = t('.not_found_token')
render :show
rescue APIParticulier::Error::HttpError
2021-09-09 19:48:34 +02:00
flash.now.alert = t('.network_error')
render :show
end
private
2021-09-16 09:09:26 +02:00
def scopes
@scopes ||= APIParticulier::API.new(token).scopes
end
def token
params[:procedure][:api_particulier_token]
end
end
end