store specific api-entreprise token for a procedure

This commit is contained in:
Christophe Robillard 2020-04-27 14:58:12 +02:00
parent 920cf6bb3f
commit 14ff18ca80
7 changed files with 68 additions and 3 deletions

View file

@ -1,6 +1,6 @@
module NewAdministrateur
class ProceduresController < AdministrateurController
before_action :retrieve_procedure, only: [:champs, :annotations, :edit, :monavis, :update_monavis]
before_action :retrieve_procedure, only: [:champs, :annotations, :edit, :monavis, :update_monavis, :jeton, :update_jeton]
before_action :procedure_locked?, only: [:champs, :annotations]
def apercu
@ -57,6 +57,18 @@ module NewAdministrateur
render 'monavis'
end
def jeton
end
def update_jeton
if !@procedure.update(procedure_params)
flash.now.alert = @procedure.errors.full_messages
else
flash.notice = 'Le jeton a bien été mis à jour'
end
render 'jeton'
end
private
def apercu_tab
@ -68,7 +80,7 @@ module NewAdministrateur
end
def procedure_params
editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :cadre_juridique, :deliberation, :notice, :web_hook_url, :declarative_with_state, :euro_flag, :logo, :auto_archive_on, :monavis_embed]
editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :cadre_juridique, :deliberation, :notice, :web_hook_url, :declarative_with_state, :euro_flag, :logo, :auto_archive_on, :monavis_embed, :api_entreprise_token]
permited_params = if @procedure&.locked?
params.require(:procedure).permit(*editable_params)
else

View file

@ -68,6 +68,10 @@
.procedure-list-element{ class: ('active' if active == 'MonAvis') }
MonAvis
%a#onglet-description{ href: url_for(admin_procedure_jeton_path(@procedure)) }
.procedure-list-element
Jeton
%a#onglet-description{ href: url_for(admin_procedures_path()) }
.procedure-list-element
Sortir

View file

@ -0,0 +1,24 @@
= render partial: 'new_administrateur/breadcrumbs',
locals: { steps: [link_to('Démarches', admin_procedures_path),
link_to(@procedure.libelle, admin_procedure_path(@procedure)),
'Jeton'] }
.container
%h1.page-title
Configurer le jeton API Entreprise
.container
%h1
= form_with model: @procedure, url: url_for({ controller: 'new_administrateur/procedures', action: :update_jeton }), html: { class: 'form' } do |f|
%p.explication
Démarches Simplifiées utilise
= link_to 'API Entreprise', "https://entreprise.api.gouv.fr/"
qui permet de récupérer les informations administratives des entreprises et des associations.
Si votre démarche nécessite des autorisations spécifiques que Démarches Simplifiées n'a pas par défaut, merci de renseigner ici le jeton
= link_to 'API Entreprise', "https://entreprise.api.gouv.fr/demander_un_acces/"
propre à votre démarche.
= f.label :api_entreprise_token, "Jeton"
= f.password_field :api_entreprise_token, class: 'form-control'
.text-right
= f.button 'Enregistrer', class: 'button primary send'

View file

@ -166,6 +166,8 @@ Rails.application.routes.draw do
post 'admin/procedures' => 'new_administrateur/procedures#create'
get 'admin/procedures/:id/monavis' => 'new_administrateur/procedures#monavis', as: :admin_procedure_monavis
patch 'admin/procedures/:id/monavis' => 'new_administrateur/procedures#update_monavis', as: :update_monavis
get 'admin/procedures/:id/jeton' => 'new_administrateur/procedures#jeton', as: :admin_procedure_jeton
patch 'admin/procedures/:id/jeton' => 'new_administrateur/procedures#update_jeton', as: :update_jeton
namespace :admin do
get 'activate' => '/administrateurs/activate#new'

View file

@ -0,0 +1,5 @@
class AddAPIEntrepriseTokenToProcedures < ActiveRecord::Migration[5.2]
def change
add_column :procedures, :api_entreprise_token, :string
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_04_22_090426) do
ActiveRecord::Schema.define(version: 2020_04_23_171759) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -515,6 +515,7 @@ ActiveRecord::Schema.define(version: 2020_04_22_090426) do
t.datetime "closed_at"
t.datetime "unpublished_at"
t.bigint "canonical_procedure_id"
t.string "api_entreprise_token"
t.index ["declarative_with_state"], name: "index_procedures_on_declarative_with_state"
t.index ["hidden_at"], name: "index_procedures_on_hidden_at"
t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id"

View file

@ -301,4 +301,21 @@ describe NewAdministrateur::ProceduresController, type: :controller do
end
end
end
describe 'GET #jeton' do
let(:procedure) { create(:procedure, administrateur: admin) }
subject { get :jeton, params: { id: procedure.id } }
it { is_expected.to have_http_status(:success) }
end
describe 'PATCH #jeton' do
let(:procedure) { create(:procedure, administrateur: admin) }
it "update api_entreprise_token" do
patch :update_jeton, params: { id: procedure.id, procedure: { api_entreprise_token: 'ceci-est-un-jeton' } }
expect(procedure.reload.api_entreprise_token).to eq('ceci-est-un-jeton')
end
end
end