Merge pull request #6463 from betagouv/save_api_particulier_token_scopes

Sauvegarde les scopes api particulier
This commit is contained in:
LeSim 2021-09-16 10:34:08 +02:00 committed by GitHub
commit b1ac364cdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 5 deletions

View file

@ -18,7 +18,8 @@ module NewAdministrateur
flash.now.alert = t('.no_scopes_token')
render :show
else
@procedure.save
@procedure.api_particulier_scopes = scopes
@procedure.save!
redirect_to admin_procedure_api_particulier_jeton_path(procedure_id: @procedure.id),
notice: t('.token_ok')

View file

@ -6,6 +6,7 @@
# aasm_state :string default("brouillon")
# allow_expert_review :boolean default(TRUE), not null
# api_entreprise_token :string
# api_particulier_scopes :text default([]), is an Array
# ask_birthday :boolean default(FALSE), not null
# auto_archive_on :date
# cadre_juridique :string
@ -447,6 +448,7 @@ class Procedure < ApplicationRecord
procedure.administrateurs = [admin]
procedure.api_entreprise_token = nil
procedure.encrypted_api_particulier_token = nil
procedure.api_particulier_scopes = []
else
procedure.administrateurs = administrateurs
end

View file

@ -0,0 +1,5 @@
class AddAPIParticulierScopesToProcedure < ActiveRecord::Migration[6.1]
def change
add_column :procedures, :api_particulier_scopes, :text, array: true, default: []
end
end

View file

@ -10,8 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_08_27_161956) do
ActiveRecord::Schema.define(version: 2021_09_08_162000) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "unaccent"
@ -617,8 +616,9 @@ ActiveRecord::Schema.define(version: 2021_08_27_161956) do
t.bigint "draft_revision_id"
t.bigint "published_revision_id"
t.boolean "allow_expert_review", default: true, null: false
t.string "encrypted_api_particulier_token"
t.boolean "experts_require_administrateur_invitation", default: false
t.string "encrypted_api_particulier_token"
t.text "api_particulier_scopes", default: [], array: true
t.index ["declarative_with_state"], name: "index_procedures_on_declarative_with_state"
t.index ["draft_revision_id"], name: "index_procedures_on_draft_revision_id"
t.index ["hidden_at"], name: "index_procedures_on_hidden_at"

View file

@ -44,6 +44,7 @@ describe NewAdministrateur::JetonParticulierController, type: :controller do
it { expect(flash.alert).to be_nil }
it { expect(flash.notice).to eq("Le jeton a bien été mis à jour") }
it { expect(procedure.reload.api_particulier_token).to eql(token) }
it { expect(procedure.reload.api_particulier_scopes).to contain_exactly("dgfip_avis_imposition", "dgfip_adresse", "cnaf_allocataires", "cnaf_enfants", "cnaf_adresse", "cnaf_quotient_familial", "mesri_statut_etudiant") }
end
context "and the api response is a success but with an empty scopes" do

View file

@ -326,7 +326,7 @@ describe Procedure do
describe 'clone' do
let(:service) { create(:service) }
let(:procedure) { create(:procedure, received_mail: received_mail, service: service, types_de_champ: [type_de_champ_0, type_de_champ_1, type_de_champ_2, type_de_champ_pj, type_de_champ_repetition], types_de_champ_private: [type_de_champ_private_0, type_de_champ_private_1, type_de_champ_private_2, type_de_champ_private_repetition]) }
let(:procedure) { create(:procedure, received_mail: received_mail, service: service, types_de_champ: [type_de_champ_0, type_de_champ_1, type_de_champ_2, type_de_champ_pj, type_de_champ_repetition], types_de_champ_private: [type_de_champ_private_0, type_de_champ_private_1, type_de_champ_private_2, type_de_champ_private_repetition], api_particulier_token: '123456789012345', api_particulier_scopes: ['cnaf_famille']) }
let(:type_de_champ_0) { build(:type_de_champ, position: 0) }
let(:type_de_champ_1) { build(:type_de_champ, position: 1) }
let(:type_de_champ_2) { build(:type_de_champ_drop_down_list, position: 2) }
@ -471,6 +471,11 @@ describe Procedure do
expect(subject.groupe_instructeurs.where(label: "groupe_1").first).to be nil
end
it "should discard api_particulier_scopes and token" do
expect(subject.encrypted_api_particulier_token).to be_nil
expect(subject.api_particulier_scopes).to be_empty
end
it 'should have a default groupe instructeur' do
expect(subject.groupe_instructeurs.size).to eq(1)
expect(subject.groupe_instructeurs.first.label).to eq(GroupeInstructeur::DEFAUT_LABEL)