2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-11-25 16:26:55 +01:00
|
|
|
module Administrateurs
|
2021-09-15 11:10:28 +02:00
|
|
|
class JetonParticulierController < AdministrateurController
|
|
|
|
before_action :retrieve_procedure
|
|
|
|
|
|
|
|
def api_particulier
|
|
|
|
end
|
2021-09-15 10:53:09 +02:00
|
|
|
|
|
|
|
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
|
2021-09-17 13:48:12 +02:00
|
|
|
@procedure.update!(api_particulier_scopes: scopes, api_particulier_sources: {})
|
2021-09-15 10:53:09 +02:00
|
|
|
|
2021-09-13 15:56:40 +02:00
|
|
|
redirect_to admin_procedure_api_particulier_sources_path(procedure_id: @procedure.id),
|
2021-09-09 19:48:34 +02:00
|
|
|
notice: t('.token_ok')
|
2021-09-15 10:53:09 +02:00
|
|
|
end
|
2021-09-16 09:09:26 +02:00
|
|
|
|
2021-09-15 10:53:09 +02:00
|
|
|
rescue APIParticulier::Error::Unauthorized
|
2021-09-09 19:48:34 +02:00
|
|
|
flash.now.alert = t('.not_found_token')
|
2021-09-15 10:53:09 +02:00
|
|
|
render :show
|
|
|
|
rescue APIParticulier::Error::HttpError
|
2021-09-09 19:48:34 +02:00
|
|
|
flash.now.alert = t('.network_error')
|
2021-09-15 10:53:09 +02:00
|
|
|
render :show
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-09-16 09:09:26 +02:00
|
|
|
def scopes
|
2021-09-15 10:53:09 +02:00
|
|
|
@scopes ||= APIParticulier::API.new(token).scopes
|
|
|
|
end
|
|
|
|
|
|
|
|
def token
|
|
|
|
params[:procedure][:api_particulier_token]
|
|
|
|
end
|
2021-09-15 11:10:28 +02:00
|
|
|
end
|
|
|
|
end
|