From 14ff18ca80c5276a7d40a51d11f467bc5c285b15 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Mon, 27 Apr 2020 14:58:12 +0200 Subject: [PATCH] store specific api-entreprise token for a procedure --- .../procedures_controller.rb | 16 +++++++++++-- ...dmin_procedurescontroller_navbar.html.haml | 4 ++++ .../procedures/jeton.html.haml | 24 +++++++++++++++++++ config/routes.rb | 2 ++ ..._add_api_entreprise_token_to_procedures.rb | 5 ++++ db/schema.rb | 3 ++- .../procedures_controller_spec.rb | 17 +++++++++++++ 7 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 app/views/new_administrateur/procedures/jeton.html.haml create mode 100644 db/migrate/20200423171759_add_api_entreprise_token_to_procedures.rb diff --git a/app/controllers/new_administrateur/procedures_controller.rb b/app/controllers/new_administrateur/procedures_controller.rb index e1d27941f..a5d266ced 100644 --- a/app/controllers/new_administrateur/procedures_controller.rb +++ b/app/controllers/new_administrateur/procedures_controller.rb @@ -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 diff --git a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml index 80a7e9d19..4a4be916f 100644 --- a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml +++ b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml @@ -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 diff --git a/app/views/new_administrateur/procedures/jeton.html.haml b/app/views/new_administrateur/procedures/jeton.html.haml new file mode 100644 index 000000000..d393b3c5b --- /dev/null +++ b/app/views/new_administrateur/procedures/jeton.html.haml @@ -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' diff --git a/config/routes.rb b/config/routes.rb index 456bb92fd..4e5648a8d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/db/migrate/20200423171759_add_api_entreprise_token_to_procedures.rb b/db/migrate/20200423171759_add_api_entreprise_token_to_procedures.rb new file mode 100644 index 000000000..5a3cdc746 --- /dev/null +++ b/db/migrate/20200423171759_add_api_entreprise_token_to_procedures.rb @@ -0,0 +1,5 @@ +class AddAPIEntrepriseTokenToProcedures < ActiveRecord::Migration[5.2] + def change + add_column :procedures, :api_entreprise_token, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index bc2fec001..37ad540a3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/spec/controllers/new_administrateur/procedures_controller_spec.rb b/spec/controllers/new_administrateur/procedures_controller_spec.rb index 2220e34f3..19c9f30fb 100644 --- a/spec/controllers/new_administrateur/procedures_controller_spec.rb +++ b/spec/controllers/new_administrateur/procedures_controller_spec.rb @@ -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