demarches-normaliennes/app/controllers/new_administrateur/jeton_particulier_controller.rb
2021-09-16 09:49:16 +02:00

46 lines
1 KiB
Ruby

module NewAdministrateur
class JetonParticulierController < AdministrateurController
before_action :retrieve_procedure
def api_particulier
end
def show
end
def update
@procedure.api_particulier_token = token
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.api_particulier_scopes = scopes
@procedure.save!
redirect_to admin_procedure_api_particulier_jeton_path(procedure_id: @procedure.id),
notice: t('.token_ok')
end
rescue APIParticulier::Error::Unauthorized
flash.now.alert = t('.not_found_token')
render :show
rescue APIParticulier::Error::HttpError
flash.now.alert = t('.network_error')
render :show
end
private
def scopes
@scopes ||= APIParticulier::API.new(token).scopes
end
def token
params[:procedure][:api_particulier_token]
end
end
end