From fc17b68dc172902b45308e9eb7c5819ab7f3d48f Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 17 Apr 2018 16:11:49 +0200 Subject: [PATCH 01/41] Service: create model --- app/models/administrateur.rb | 1 + app/models/procedure.rb | 1 + app/models/service.rb | 20 ++++++++ db/migrate/20180416120759_create_services.rb | 10 ++++ ...0180416122152_add_service_to_procedures.rb | 5 ++ ...19093104_add_administrateur_to_services.rb | 5 ++ ...0423102102_add_unique_index_to_services.rb | 5 ++ db/schema.rb | 14 ++++++ spec/models/service_spec.rb | 46 +++++++++++++++++++ 9 files changed, 107 insertions(+) create mode 100644 app/models/service.rb create mode 100644 db/migrate/20180416120759_create_services.rb create mode 100644 db/migrate/20180416122152_add_service_to_procedures.rb create mode 100644 db/migrate/20180419093104_add_administrateur_to_services.rb create mode 100644 db/migrate/20180423102102_add_unique_index_to_services.rb create mode 100644 spec/models/service_spec.rb diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb index 22ad5db10..fbf62a854 100644 --- a/app/models/administrateur.rb +++ b/app/models/administrateur.rb @@ -9,6 +9,7 @@ class Administrateur < ApplicationRecord has_many :procedures has_many :administrateurs_procedures has_many :admin_procedures, through: :administrateurs_procedures, source: :procedure + has_many :services before_validation -> { sanitize_email(:email) } before_save :ensure_api_token diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 218081808..2744623dd 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -11,6 +11,7 @@ class Procedure < ApplicationRecord belongs_to :administrateur belongs_to :parent_procedure, class_name: 'Procedure' + belongs_to :service has_many :assign_to, dependent: :destroy has_many :administrateurs_procedures diff --git a/app/models/service.rb b/app/models/service.rb new file mode 100644 index 000000000..f0f2c9111 --- /dev/null +++ b/app/models/service.rb @@ -0,0 +1,20 @@ +class Service < ApplicationRecord + has_many :procedures + belongs_to :administrateur + + enum type_organisme: { + administration_centrale: 'administration_centrale', + association: 'association', + commune: 'commune', + departement: 'departement', + etablissement_enseignement: 'etablissement_enseignement', + prefecture: 'prefecture', + region: 'region', + autre: 'autre' + } + + validates :nom, presence: { message: 'doit être renseigné' }, allow_nil: false + validates :nom, uniqueness: { scope: :administrateur, message: 'existe déjà' } + validates :type_organisme, presence: { message: 'doit être renseigné' }, allow_nil: false + validates :administrateur, presence: { message: 'doit être renseigné' }, allow_nil: false +end diff --git a/db/migrate/20180416120759_create_services.rb b/db/migrate/20180416120759_create_services.rb new file mode 100644 index 000000000..2af2eca7f --- /dev/null +++ b/db/migrate/20180416120759_create_services.rb @@ -0,0 +1,10 @@ +class CreateServices < ActiveRecord::Migration[5.2] + def change + create_table :services do |t| + t.string :type_organisme, null: false + t.string :nom, null: false + + t.timestamps + end + end +end diff --git a/db/migrate/20180416122152_add_service_to_procedures.rb b/db/migrate/20180416122152_add_service_to_procedures.rb new file mode 100644 index 000000000..79c3e919d --- /dev/null +++ b/db/migrate/20180416122152_add_service_to_procedures.rb @@ -0,0 +1,5 @@ +class AddServiceToProcedures < ActiveRecord::Migration[5.2] + def change + add_reference :procedures, :service, foreign_key: true + end +end diff --git a/db/migrate/20180419093104_add_administrateur_to_services.rb b/db/migrate/20180419093104_add_administrateur_to_services.rb new file mode 100644 index 000000000..a60ed5356 --- /dev/null +++ b/db/migrate/20180419093104_add_administrateur_to_services.rb @@ -0,0 +1,5 @@ +class AddAdministrateurToServices < ActiveRecord::Migration[5.2] + def change + add_reference :services, :administrateur, foreign_key: true + end +end diff --git a/db/migrate/20180423102102_add_unique_index_to_services.rb b/db/migrate/20180423102102_add_unique_index_to_services.rb new file mode 100644 index 000000000..50feedb51 --- /dev/null +++ b/db/migrate/20180423102102_add_unique_index_to_services.rb @@ -0,0 +1,5 @@ +class AddUniqueIndexToServices < ActiveRecord::Migration[5.2] + def change + add_index :services, [:administrateur_id, :nom], unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 9594d9709..57f898afe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -466,8 +466,10 @@ ActiveRecord::Schema.define(version: 2018_05_15_135415) do t.bigint "parent_procedure_id" t.datetime "test_started_at" t.string "aasm_state", default: "brouillon" + t.bigint "service_id" t.index ["hidden_at"], name: "index_procedures_on_hidden_at" t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id" + t.index ["service_id"], name: "index_procedures_on_service_id" end create_table "quartier_prioritaires", id: :serial, force: :cascade do |t| @@ -511,6 +513,16 @@ ActiveRecord::Schema.define(version: 2018_05_15_135415) do t.index ["entreprise_id"], name: "index_rna_informations_on_entreprise_id" end + create_table "services", force: :cascade do |t| + t.string "type_organisme", null: false + t.string "nom", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "administrateur_id" + t.index ["administrateur_id", "nom"], name: "index_services_on_administrateur_id_and_nom", unique: true + t.index ["administrateur_id"], name: "index_services_on_administrateur_id" + end + create_table "types_de_champ", id: :serial, force: :cascade do |t| t.string "libelle" t.string "type_champ" @@ -576,8 +588,10 @@ ActiveRecord::Schema.define(version: 2018_05_15_135415) do add_foreign_key "procedure_paths", "administrateurs" add_foreign_key "procedure_paths", "procedures" add_foreign_key "procedure_presentations", "assign_tos" + add_foreign_key "procedures", "services" add_foreign_key "received_mails", "procedures" add_foreign_key "refused_mails", "procedures" + add_foreign_key "services", "administrateurs" add_foreign_key "without_continuation_mails", "procedures" create_view "searches", sql_definition: <<-SQL diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb new file mode 100644 index 000000000..64802d55e --- /dev/null +++ b/spec/models/service_spec.rb @@ -0,0 +1,46 @@ +describe Service, type: :model do + describe 'validation' do + let(:administrateur) { create(:administrateur) } + let(:params) do + { + nom: 'service des jardins', + type_organisme: 'commune', + administrateur_id: administrateur.id + } + end + + it { expect(Service.new(params).valid?).to be_truthy } + + context 'when a first service exists' do + before { Service.create(params) } + + context 'checks uniqueness of administrateur, name couple' do + it { expect(Service.create(params).valid?).to be_falsey } + end + end + + context 'of type_organisme' do + it 'should be set' do + expect(Service.new(params.except(:type_organisme)).valid?).to be_falsey + end + end + + context 'of nom' do + it 'should be set' do + expect(Service.new(params.except(:nom)).valid?).to be_falsey + end + end + + context 'of administrateur' do + it 'should be set' do + expect(Service.new(params.except(:administrateur_id)).valid?).to be_falsey + end + end + + context 'of type_organisme' do + it 'should belong to the enum' do + expect{ Service.new(params.merge(type_organisme: 'choucroute')) }.to raise_error(ArgumentError) + end + end + end +end From 4d0a920e7a4f76d21749750b4419a54549334338 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 19 Apr 2018 16:15:44 +0200 Subject: [PATCH 02/41] Service: add index page --- .../new_administrateur/services_controller.rb | 13 +++++++++++++ .../new_administrateur/services/index.html.haml | 14 ++++++++++++++ config/routes.rb | 2 ++ 3 files changed, 29 insertions(+) create mode 100644 app/controllers/new_administrateur/services_controller.rb create mode 100644 app/views/new_administrateur/services/index.html.haml diff --git a/app/controllers/new_administrateur/services_controller.rb b/app/controllers/new_administrateur/services_controller.rb new file mode 100644 index 000000000..a4185cf88 --- /dev/null +++ b/app/controllers/new_administrateur/services_controller.rb @@ -0,0 +1,13 @@ +module NewAdministrateur + class ServicesController < AdministrateurController + def index + @services = services + end + + private + + def services + current_administrateur.services + end + end +end diff --git a/app/views/new_administrateur/services/index.html.haml b/app/views/new_administrateur/services/index.html.haml new file mode 100644 index 000000000..da3b94453 --- /dev/null +++ b/app/views/new_administrateur/services/index.html.haml @@ -0,0 +1,14 @@ +.container + %h1 Liste des Services + + %table.table + %thead + %tr + %th + nom + + %tbody + - @services.each do |service| + %tr + %td + = service.nom diff --git a/config/routes.rb b/config/routes.rb index 56601ac28..c8b8a498f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -286,6 +286,8 @@ Rails.application.routes.draw do get 'apercu' end end + + resources :services, only: [:index] end apipie From bda0ca8188c19192e40b026a665fcb5b08d89a46 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 23 Apr 2018 10:42:30 +0200 Subject: [PATCH 03/41] Service: sort services by name in index --- app/controllers/new_administrateur/services_controller.rb | 2 +- app/models/service.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/new_administrateur/services_controller.rb b/app/controllers/new_administrateur/services_controller.rb index a4185cf88..6b1621786 100644 --- a/app/controllers/new_administrateur/services_controller.rb +++ b/app/controllers/new_administrateur/services_controller.rb @@ -1,7 +1,7 @@ module NewAdministrateur class ServicesController < AdministrateurController def index - @services = services + @services = services.ordered end private diff --git a/app/models/service.rb b/app/models/service.rb index f0f2c9111..0ea150b8a 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -2,6 +2,8 @@ class Service < ApplicationRecord has_many :procedures belongs_to :administrateur + scope :ordered, -> { order(nom: :asc) } + enum type_organisme: { administration_centrale: 'administration_centrale', association: 'association', From c54c85bad8bf7fe259a881917fe469867cde9211 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 19 Apr 2018 10:44:14 +0200 Subject: [PATCH 04/41] Service: can create a service --- .../new_administrateur/services_controller.rb | 19 +++++++++++++ .../services/_form.html.haml | 15 +++++++++++ .../services/index.html.haml | 3 +++ .../new_administrateur/services/new.html.haml | 5 ++++ config/locales/models/service/fr.yml | 10 +++++++ config/routes.rb | 2 +- .../services_controller_spec.rb | 27 +++++++++++++++++++ 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 app/views/new_administrateur/services/_form.html.haml create mode 100644 app/views/new_administrateur/services/new.html.haml create mode 100644 config/locales/models/service/fr.yml create mode 100644 spec/controllers/new_administrateur/services_controller_spec.rb diff --git a/app/controllers/new_administrateur/services_controller.rb b/app/controllers/new_administrateur/services_controller.rb index 6b1621786..c0ff1366a 100644 --- a/app/controllers/new_administrateur/services_controller.rb +++ b/app/controllers/new_administrateur/services_controller.rb @@ -4,8 +4,27 @@ module NewAdministrateur @services = services.ordered end + def new + end + + def create + new_service = Service.new(service_params) + new_service.administrateur = current_administrateur + + if new_service.save + redirect_to services_path, notice: "#{new_service.nom} créé" + else + flash[:alert] = new_service.errors.full_messages + render :new + end + end + private + def service_params + params.require(:service).permit(:nom, :type_organisme) + end + def services current_administrateur.services end diff --git a/app/views/new_administrateur/services/_form.html.haml b/app/views/new_administrateur/services/_form.html.haml new file mode 100644 index 000000000..ae4559947 --- /dev/null +++ b/app/views/new_administrateur/services/_form.html.haml @@ -0,0 +1,15 @@ += form_for service, html: { class: 'form' } do |f| + + = f.label :nom do + Nom + %span.mandatory * + = f.text_field :nom, placeholder: 'service jeunesse et prévention, direction des affaires maritimes', required: true + + = f.label :type_organisme do + Type d’organisme + %span.mandatory * + + = f.select :type_organisme, Service.type_organismes.keys.map { |key| [ I18n.t("type_organisme.#{key}"), key] } + + .send-wrapper + = f.submit "Valider", class: 'button send' diff --git a/app/views/new_administrateur/services/index.html.haml b/app/views/new_administrateur/services/index.html.haml index da3b94453..5a3140184 100644 --- a/app/views/new_administrateur/services/index.html.haml +++ b/app/views/new_administrateur/services/index.html.haml @@ -6,9 +6,12 @@ %tr %th nom + %th + = link_to('Nouveau service', new_service_path, class: 'button') %tbody - @services.each do |service| %tr %td = service.nom + %td diff --git a/app/views/new_administrateur/services/new.html.haml b/app/views/new_administrateur/services/new.html.haml new file mode 100644 index 000000000..26e2778ec --- /dev/null +++ b/app/views/new_administrateur/services/new.html.haml @@ -0,0 +1,5 @@ +.container + %h1 Nouveau Service + + = render partial: 'form', + locals: { service: Service.new } diff --git a/config/locales/models/service/fr.yml b/config/locales/models/service/fr.yml new file mode 100644 index 000000000..4a573ecc4 --- /dev/null +++ b/config/locales/models/service/fr.yml @@ -0,0 +1,10 @@ +fr: + type_organisme: + administration_centrale: 'administration centrale' + association: 'association' + commune: 'commune' + departement: 'département' + etablissement_enseignement: 'établissement d’enseignement' + prefecture: 'préfecture' + region: 'région' + autre: 'autre' diff --git a/config/routes.rb b/config/routes.rb index c8b8a498f..27eedef16 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -287,7 +287,7 @@ Rails.application.routes.draw do end end - resources :services, only: [:index] + resources :services, only: [:index, :new, :create] end apipie diff --git a/spec/controllers/new_administrateur/services_controller_spec.rb b/spec/controllers/new_administrateur/services_controller_spec.rb new file mode 100644 index 000000000..91a74a67d --- /dev/null +++ b/spec/controllers/new_administrateur/services_controller_spec.rb @@ -0,0 +1,27 @@ +describe NewAdministrateur::ServicesController, type: :controller do + let(:admin) { create(:administrateur) } + + describe '#create' do + before do + sign_in admin + post :create, params: params + end + + context 'when submitting a new service' do + let(:params) { { service: { nom: 'super service', type_organisme: 'region' } } } + + it { expect(flash.alert).to be_nil } + it { expect(flash.notice).to eq('super service créé') } + it { expect(Service.last.nom).to eq('super service') } + it { expect(Service.last.type_organisme).to eq('region') } + it { expect(response).to redirect_to(services_path) } + end + + context 'when submitting an invalid service' do + let(:params) { { service: { nom: 'super service' } } } + + it { expect(flash.alert).not_to be_nil } + it { expect(response).to render_template(:new) } + end + end +end From 365cb9b44db01294f7b6c285dab4146905c4df42 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 19 Apr 2018 18:12:48 +0200 Subject: [PATCH 05/41] Service: can update a service --- .../stylesheets/new_design/table-service.scss | 9 +++++++ .../new_administrateur/services_controller.rb | 19 ++++++++++++++ .../services/edit.html.haml | 5 ++++ .../services/index.html.haml | 7 +++--- config/routes.rb | 2 +- .../services_controller_spec.rb | 25 +++++++++++++++++++ spec/factories/service.rb | 7 ++++++ 7 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 app/assets/stylesheets/new_design/table-service.scss create mode 100644 app/views/new_administrateur/services/edit.html.haml create mode 100644 spec/factories/service.rb diff --git a/app/assets/stylesheets/new_design/table-service.scss b/app/assets/stylesheets/new_design/table-service.scss new file mode 100644 index 000000000..bf7e9d67f --- /dev/null +++ b/app/assets/stylesheets/new_design/table-service.scss @@ -0,0 +1,9 @@ +@import "constants"; + +.table-service { + .change { + text-align: center; + width: 200px; + padding-left: $default-padding; + } +} diff --git a/app/controllers/new_administrateur/services_controller.rb b/app/controllers/new_administrateur/services_controller.rb index c0ff1366a..01f9484a7 100644 --- a/app/controllers/new_administrateur/services_controller.rb +++ b/app/controllers/new_administrateur/services_controller.rb @@ -19,12 +19,31 @@ module NewAdministrateur end end + def edit + @service = service + end + + def update + @service = service + + if @service.update(service_params) + redirect_to services_path, notice: "#{@service.nom} modifié" + else + flash[:alert] = @service.errors.full_messages + render :edit + end + end + private def service_params params.require(:service).permit(:nom, :type_organisme) end + def service + services.find(params[:id]) + end + def services current_administrateur.services end diff --git a/app/views/new_administrateur/services/edit.html.haml b/app/views/new_administrateur/services/edit.html.haml new file mode 100644 index 000000000..bcb573318 --- /dev/null +++ b/app/views/new_administrateur/services/edit.html.haml @@ -0,0 +1,5 @@ +.container + %h1 Modifier le service + + = render partial: 'form', + locals: { service: @service } diff --git a/app/views/new_administrateur/services/index.html.haml b/app/views/new_administrateur/services/index.html.haml index 5a3140184..b02598129 100644 --- a/app/views/new_administrateur/services/index.html.haml +++ b/app/views/new_administrateur/services/index.html.haml @@ -1,12 +1,12 @@ .container %h1 Liste des Services - %table.table + %table.table.table-service.hoverable %thead %tr %th nom - %th + %th.change = link_to('Nouveau service', new_service_path, class: 'button') %tbody @@ -14,4 +14,5 @@ %tr %td = service.nom - %td + %td.change + = link_to('modifier', edit_service_path(service)) diff --git a/config/routes.rb b/config/routes.rb index 27eedef16..d8e1276df 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -287,7 +287,7 @@ Rails.application.routes.draw do end end - resources :services, only: [:index, :new, :create] + resources :services, except: [:destroy, :show] end apipie diff --git a/spec/controllers/new_administrateur/services_controller_spec.rb b/spec/controllers/new_administrateur/services_controller_spec.rb index 91a74a67d..d87aeb2ab 100644 --- a/spec/controllers/new_administrateur/services_controller_spec.rb +++ b/spec/controllers/new_administrateur/services_controller_spec.rb @@ -24,4 +24,29 @@ describe NewAdministrateur::ServicesController, type: :controller do it { expect(response).to render_template(:new) } end end + + describe '#update' do + let!(:service) { create(:service, administrateur: admin) } + let(:service_params) { { nom: 'nom', type_organisme: 'region' } } + + before do + sign_in admin + patch :update, params: { id: service.id, service: service_params } + end + + context 'when updating a service' do + it { expect(flash.alert).to be_nil } + it { expect(flash.notice).to eq('nom modifié') } + it { expect(Service.last.nom).to eq('nom') } + it { expect(Service.last.type_organisme).to eq('region') } + it { expect(response).to redirect_to(services_path) } + end + + context 'when updating a service with invalid data' do + let(:service_params) { { nom: '', type_organisme: 'region' } } + + it { expect(flash.alert).not_to be_nil } + it { expect(response).to render_template(:edit) } + end + end end diff --git a/spec/factories/service.rb b/spec/factories/service.rb new file mode 100644 index 000000000..bffd5dc44 --- /dev/null +++ b/spec/factories/service.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :service do + nom 'service' + type_organisme 'commune' + administrateur { create(:administrateur) } + end +end From ec21f78274aff4a0d36cccc82e397908ab69f38f Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 19 Apr 2018 15:22:52 +0200 Subject: [PATCH 06/41] Cosmetic refactor left procedure admin panel --- ...nel_admin_procedurescontroller_navbar.html.haml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 24bace7a6..39519751c 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 @@ -10,7 +10,7 @@ #menu-block .split-hr-left #procedure-list - %a#onglet-infos{ :href => "#{url_for admin_procedure_path(@procedure)}" } + %a#onglet-infos{ href: url_for(admin_procedure_path(@procedure)) } .procedure-list-element{ class: ('active' if active == 'Informations') } Informations @@ -18,30 +18,30 @@ .procedure-list-element{ class: ('active' if active == 'Accompagnateurs') } = t('dynamics.admin.procedure.onglets.accompagnateurs') - %a#onglet-description{ :href => "#{url_for edit_admin_procedure_path(@procedure)}" } + %a#onglet-description{ href: url_for(edit_admin_procedure_path(@procedure)) } .procedure-list-element{ class: ('active' if active == 'Description') } Description - if !@procedure.locked? - %a#onglet-champs{ :href => "#{url_for admin_procedure_types_de_champ_path(@procedure)}" } + %a#onglet-champs{ href: url_for(admin_procedure_types_de_champ_path(@procedure)) } .procedure-list-element{ class: ('active' if active == 'Champs') } Champs - if !@procedure.locked? - %a#onglet-pieces{ :href => "#{url_for admin_procedure_pieces_justificatives_path(@procedure)}" } + %a#onglet-pieces{ href: url_for(admin_procedure_pieces_justificatives_path(@procedure)) } .procedure-list-element{ class: ('active' if active == 'Pieces') } Pièces jointes - if !@procedure.locked? - %a#onglet-private-champs{ :href => "#{url_for admin_procedure_types_de_champ_private_path(@procedure)}" } + %a#onglet-private-champs{ href: url_for(admin_procedure_types_de_champ_private_path(@procedure)) } .procedure-list-element{ class: ('active' if active == 'Annotations privées') } Annotations privées - %a#onglet-inemailsfos{ :href => "#{url_for admin_procedure_mail_templates_path(@procedure)}" } + %a#onglet-inemailsfos{ href: url_for(admin_procedure_mail_templates_path(@procedure)) } .procedure-list-element{ class: ('active' if active == 'E-mails') } E-mails - %a#onglet-preview{ :href => "#{url_for admin_procedure_previsualisation_path(@procedure)}" } + %a#onglet-preview{ href: url_for(admin_procedure_previsualisation_path(@procedure)) } .procedure-list-element{ class: ('active' if active == 'Prévisualisation') } Prévisualisation From a8f2528dcdaecb2799573ac15d657fc8318f91d2 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 19 Apr 2018 15:23:27 +0200 Subject: [PATCH 07/41] Add services to procedure admin menu --- .../_left_panel_admin_procedurescontroller_navbar.html.haml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 39519751c..d6b31b3ba 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 @@ -14,7 +14,11 @@ .procedure-list-element{ class: ('active' if active == 'Informations') } Informations - %a#onglet-accompagnateurs{ :href => "#{url_for admin_procedure_accompagnateurs_path(@procedure)}" } + %a#onglet-services{ href: url_for(services_path(procedure_id: @procedure.id)) } + .procedure-list-element + Services + + %a#onglet-accompagnateurs{ href: url_for(admin_procedure_accompagnateurs_path(@procedure)) } .procedure-list-element{ class: ('active' if active == 'Accompagnateurs') } = t('dynamics.admin.procedure.onglets.accompagnateurs') From 5d7455f436f2f0d28b63c5ef2d85724ba06c21fd Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 19 Apr 2018 15:59:11 +0200 Subject: [PATCH 08/41] Service: keep procedure_id --- .../new_administrateur/services_controller.rb | 6 ++++-- .../services/_form.html.haml | 3 +++ .../services/edit.html.haml | 2 +- .../services/index.html.haml | 4 ++-- .../new_administrateur/services/new.html.haml | 2 +- .../services_controller_spec.rb | 21 +++++++++++++++---- 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/app/controllers/new_administrateur/services_controller.rb b/app/controllers/new_administrateur/services_controller.rb index 01f9484a7..9e3fbf6f1 100644 --- a/app/controllers/new_administrateur/services_controller.rb +++ b/app/controllers/new_administrateur/services_controller.rb @@ -12,7 +12,8 @@ module NewAdministrateur new_service.administrateur = current_administrateur if new_service.save - redirect_to services_path, notice: "#{new_service.nom} créé" + redirect_to services_path(procedure_id: params[:procedure_id]), + notice: "#{new_service.nom} créé" else flash[:alert] = new_service.errors.full_messages render :new @@ -27,7 +28,8 @@ module NewAdministrateur @service = service if @service.update(service_params) - redirect_to services_path, notice: "#{@service.nom} modifié" + redirect_to services_path(procedure_id: params[:procedure_id]), + notice: "#{@service.nom} modifié" else flash[:alert] = @service.errors.full_messages render :edit diff --git a/app/views/new_administrateur/services/_form.html.haml b/app/views/new_administrateur/services/_form.html.haml index ae4559947..f0e40cf1e 100644 --- a/app/views/new_administrateur/services/_form.html.haml +++ b/app/views/new_administrateur/services/_form.html.haml @@ -11,5 +11,8 @@ = f.select :type_organisme, Service.type_organismes.keys.map { |key| [ I18n.t("type_organisme.#{key}"), key] } + - if procedure_id.present? + = hidden_field_tag :procedure_id, procedure_id + .send-wrapper = f.submit "Valider", class: 'button send' diff --git a/app/views/new_administrateur/services/edit.html.haml b/app/views/new_administrateur/services/edit.html.haml index bcb573318..2f3b9f129 100644 --- a/app/views/new_administrateur/services/edit.html.haml +++ b/app/views/new_administrateur/services/edit.html.haml @@ -2,4 +2,4 @@ %h1 Modifier le service = render partial: 'form', - locals: { service: @service } + locals: { service: @service, procedure_id: params[:procedure_id] } diff --git a/app/views/new_administrateur/services/index.html.haml b/app/views/new_administrateur/services/index.html.haml index b02598129..4c468e8bc 100644 --- a/app/views/new_administrateur/services/index.html.haml +++ b/app/views/new_administrateur/services/index.html.haml @@ -7,7 +7,7 @@ %th nom %th.change - = link_to('Nouveau service', new_service_path, class: 'button') + = link_to('Nouveau service', new_service_path(procedure_id: params[:procedure_id]), class: 'button') %tbody - @services.each do |service| @@ -15,4 +15,4 @@ %td = service.nom %td.change - = link_to('modifier', edit_service_path(service)) + = link_to('modifier', edit_service_path(service, procedure_id: params[:procedure_id])) diff --git a/app/views/new_administrateur/services/new.html.haml b/app/views/new_administrateur/services/new.html.haml index 26e2778ec..34ef8027c 100644 --- a/app/views/new_administrateur/services/new.html.haml +++ b/app/views/new_administrateur/services/new.html.haml @@ -2,4 +2,4 @@ %h1 Nouveau Service = render partial: 'form', - locals: { service: Service.new } + locals: { service: Service.new, procedure_id: params[:procedure_id] } diff --git a/spec/controllers/new_administrateur/services_controller_spec.rb b/spec/controllers/new_administrateur/services_controller_spec.rb index d87aeb2ab..a65ffce25 100644 --- a/spec/controllers/new_administrateur/services_controller_spec.rb +++ b/spec/controllers/new_administrateur/services_controller_spec.rb @@ -8,13 +8,21 @@ describe NewAdministrateur::ServicesController, type: :controller do end context 'when submitting a new service' do - let(:params) { { service: { nom: 'super service', type_organisme: 'region' } } } + let(:params) do + { + service: { + nom: 'super service', + type_organisme: 'region' + }, + procedure_id: 12 + } + end it { expect(flash.alert).to be_nil } it { expect(flash.notice).to eq('super service créé') } it { expect(Service.last.nom).to eq('super service') } it { expect(Service.last.type_organisme).to eq('region') } - it { expect(response).to redirect_to(services_path) } + it { expect(response).to redirect_to(services_path(procedure_id: 12)) } end context 'when submitting an invalid service' do @@ -31,7 +39,12 @@ describe NewAdministrateur::ServicesController, type: :controller do before do sign_in admin - patch :update, params: { id: service.id, service: service_params } + params = { + id: service.id, + service: service_params, + procedure_id: 12 + } + patch :update, params: params end context 'when updating a service' do @@ -39,7 +52,7 @@ describe NewAdministrateur::ServicesController, type: :controller do it { expect(flash.notice).to eq('nom modifié') } it { expect(Service.last.nom).to eq('nom') } it { expect(Service.last.type_organisme).to eq('region') } - it { expect(response).to redirect_to(services_path) } + it { expect(response).to redirect_to(services_path(procedure_id: 12)) } end context 'when updating a service with invalid data' do From af7be5813267bcdeb29fd61711d0f02b1d4aba6f Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 20 Apr 2018 12:03:02 +0200 Subject: [PATCH 09/41] Service: add service to procedure --- .../new_design/services-index.scss | 7 ++++ .../new_administrateur/services_controller.rb | 19 +++++++++++ .../services/index.html.haml | 14 +++++++- config/routes.rb | 6 +++- .../services_controller_spec.rb | 32 +++++++++++++++++++ 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 app/assets/stylesheets/new_design/services-index.scss diff --git a/app/assets/stylesheets/new_design/services-index.scss b/app/assets/stylesheets/new_design/services-index.scss new file mode 100644 index 000000000..840be9ff3 --- /dev/null +++ b/app/assets/stylesheets/new_design/services-index.scss @@ -0,0 +1,7 @@ +@import "constants"; + +#services-index { + h1 { + margin-top: 2 * $default-padding; + } +} diff --git a/app/controllers/new_administrateur/services_controller.rb b/app/controllers/new_administrateur/services_controller.rb index 9e3fbf6f1..95dad3eb9 100644 --- a/app/controllers/new_administrateur/services_controller.rb +++ b/app/controllers/new_administrateur/services_controller.rb @@ -2,6 +2,7 @@ module NewAdministrateur class ServicesController < AdministrateurController def index @services = services.ordered + @procedure = procedure end def new @@ -36,6 +37,16 @@ module NewAdministrateur end end + def add_to_procedure + procedure = current_administrateur.procedures.find(procedure_params[:id]) + service = services.find(procedure_params[:service_id]) + + procedure.update(service: service) + + redirect_to admin_procedure_path(procedure.id), + notice: "service affecté : #{procedure.service.nom}" + end + private def service_params @@ -49,5 +60,13 @@ module NewAdministrateur def services current_administrateur.services end + + def procedure_params + params.require(:procedure).permit(:id, :service_id) + end + + def procedure + current_administrateur.procedures.find(params[:procedure_id]) + end end end diff --git a/app/views/new_administrateur/services/index.html.haml b/app/views/new_administrateur/services/index.html.haml index 4c468e8bc..0d24f4476 100644 --- a/app/views/new_administrateur/services/index.html.haml +++ b/app/views/new_administrateur/services/index.html.haml @@ -1,4 +1,16 @@ -.container +#services-index.container + %h1 Choix du service pour la procédure + + = form_for @procedure, url: { controller: "new_administrateur/services", action: :add_to_procedure } , html: { class: 'form' } do |f| + = f.label :service_id, "La procédure #{@procedure.libelle} est affectée au service" + = f.select :service_id, + current_administrateur.services.map { |s| [ s.nom, s.id ] }, + { prompt: 'choisir un service', selected: @procedure.service&.id }, + required: true + + = f.hidden_field :id + = f.submit 'valider', class: 'button primary' + %h1 Liste des Services %table.table.table-service.hoverable diff --git a/config/routes.rb b/config/routes.rb index d8e1276df..0a1e0d0bd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -287,7 +287,11 @@ Rails.application.routes.draw do end end - resources :services, except: [:destroy, :show] + resources :services, except: [:destroy, :show] do + collection do + patch 'add_to_procedure' + end + end end apipie diff --git a/spec/controllers/new_administrateur/services_controller_spec.rb b/spec/controllers/new_administrateur/services_controller_spec.rb index a65ffce25..a8de6e206 100644 --- a/spec/controllers/new_administrateur/services_controller_spec.rb +++ b/spec/controllers/new_administrateur/services_controller_spec.rb @@ -62,4 +62,36 @@ describe NewAdministrateur::ServicesController, type: :controller do it { expect(response).to render_template(:edit) } end end + + describe '#add_to_procedure' do + let!(:procedure) { create(:procedure, administrateur: admin) } + let!(:service) { create(:service, administrateur: admin) } + + def post_add_to_procedure + sign_in admin + params = { + procedure: { + id: procedure.id, + service_id: service.id + } + } + patch :add_to_procedure, params: params + procedure.reload + end + + context 'when adding a service to a procedure' do + before { post_add_to_procedure } + + it { expect(flash.alert).to be_nil } + it { expect(flash.notice).to eq("service affecté : #{service.nom}") } + it { expect(procedure.service_id).to eq(service.id) } + it { expect(response).to redirect_to(admin_procedure_path(procedure.id)) } + end + + context 'when stealing a service to add it to a procedure' do + let!(:service) { create(:service) } + + it { expect { post_add_to_procedure }.to raise_error(ActiveRecord::RecordNotFound) } + end + end end From 6b8a878ec167ee6b6abf0489937611ab801e0d7d Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 23 Apr 2018 15:32:27 +0200 Subject: [PATCH 10/41] Service: can be destroyed --- .../new_administrateur/services_controller.rb | 18 +++++++++++ .../services/index.html.haml | 4 +++ config/routes.rb | 2 +- .../services_controller_spec.rb | 30 +++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/app/controllers/new_administrateur/services_controller.rb b/app/controllers/new_administrateur/services_controller.rb index 95dad3eb9..c147dde38 100644 --- a/app/controllers/new_administrateur/services_controller.rb +++ b/app/controllers/new_administrateur/services_controller.rb @@ -47,6 +47,24 @@ module NewAdministrateur notice: "service affecté : #{procedure.service.nom}" end + def destroy + service_to_destroy = service + + if service_to_destroy.procedures.present? + if service_to_destroy.procedures.count == 1 + message = "la procédure #{service_to_destroy.procedures.first.libelle} utilise encore le service #{service_to_destroy.nom}. Veuillez l'affecter à un autre service avant de pouvoir le supprimer" + else + message = "les procédures #{service_to_destroy.procedures.map(&:libelle).join(', ')} utilisent encore le service #{service.nom}. Veuillez les affecter à un autre service avant de pouvoir le supprimer" + end + flash[:alert] = message + redirect_to services_path(procedure_id: params[:procedure_id]) + else + service_to_destroy.destroy + redirect_to services_path(procedure_id: params[:procedure_id]), + notice: "#{service_to_destroy.nom} est supprimé" + end + end + private def service_params diff --git a/app/views/new_administrateur/services/index.html.haml b/app/views/new_administrateur/services/index.html.haml index 0d24f4476..13926644a 100644 --- a/app/views/new_administrateur/services/index.html.haml +++ b/app/views/new_administrateur/services/index.html.haml @@ -28,3 +28,7 @@ = service.nom %td.change = link_to('modifier', edit_service_path(service, procedure_id: params[:procedure_id])) + = link_to 'supprimer', + service_path(service, procedure_id: params[:procedure_id]), + method: :delete, + data: { confirm: "Confirmez vous la suppression de #{service.nom}" } diff --git a/config/routes.rb b/config/routes.rb index 0a1e0d0bd..2b94d7953 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -287,7 +287,7 @@ Rails.application.routes.draw do end end - resources :services, except: [:destroy, :show] do + resources :services, except: [:show] do collection do patch 'add_to_procedure' end diff --git a/spec/controllers/new_administrateur/services_controller_spec.rb b/spec/controllers/new_administrateur/services_controller_spec.rb index a8de6e206..da1df6dad 100644 --- a/spec/controllers/new_administrateur/services_controller_spec.rb +++ b/spec/controllers/new_administrateur/services_controller_spec.rb @@ -94,4 +94,34 @@ describe NewAdministrateur::ServicesController, type: :controller do it { expect { post_add_to_procedure }.to raise_error(ActiveRecord::RecordNotFound) } end end + + describe '#destroy' do + let!(:service) { create(:service, administrateur: admin) } + + context 'when a service has no related procedure' do + before do + sign_in admin + delete :destroy, params: { id: service.id, procedure_id: 12 } + end + + it { expect{ service.reload }.to raise_error(ActiveRecord::RecordNotFound) } + it { expect(flash.alert).to be_nil } + it { expect(flash.notice).to eq("#{service.nom} est supprimé") } + it { expect(response).to redirect_to(services_path(procedure_id: 12)) } + end + + context 'when a service still has some related procedures' do + let!(:procedure) { create(:procedure, service: service) } + + before do + sign_in admin + delete :destroy, params: { id: service.id, procedure_id: 12 } + end + + it { expect(service.reload).not_to be_nil } + it { expect(flash.alert).to eq("la procédure #{procedure.libelle} utilise encore le service service. Veuillez l'affecter à un autre service avant de pouvoir le supprimer") } + it { expect(flash.notice).to be_nil } + it { expect(response).to redirect_to(services_path(procedure_id: 12)) } + end + end end From abccdab6ab0ae20a283e519f494f8276d5c8474f Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 23 Apr 2018 16:06:30 +0200 Subject: [PATCH 11/41] Admin Procedure Show: simple cleaning --- app/views/admin/procedures/show.html.haml | 40 ++++++++++++----------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index 7dcbb1d6a..c71ab2fd1 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -1,8 +1,10 @@ +- procedure = @facade.procedure + = render partial: 'admin/closed_mail_template_attestation_inconsistency_alert' .row.white-back #procedure_show - - if @facade.procedure.brouillon? - - if @facade.procedure.gestionnaires.size == 0 + - if procedure.brouillon? + - if procedure.gestionnaires.size == 0 %a.action_button.btn.btn-success#publish-procedure{ style: 'float: right; margin-top: 10px;', disabled: 'disabled', 'data-toggle' => :tooltip, title: 'Vous ne pouvez pas publier une procédure sans qu\'aucun accompagnateur ne soit affecté à celle-ci.' } %i.fa.fa-eraser Publier @@ -19,15 +21,15 @@ = render partial: '/admin/procedures/modal_transfer' - - if @facade.procedure.archivee? + - if procedure.archivee? %a#reenable.btn.btn-small.btn-default.text-info{ "data-target" => "#publish-modal", "data-toggle" => "modal", :type => "button", style: 'float: right; margin-top: 10px;' } %i.fa.fa-eraser Réactiver = render partial: '/admin/procedures/modal_publish' - - elsif @facade.procedure.publiee? - = form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archivee?), method: :put, style: 'float: right; margin-top: 10px;' do + - elsif procedure.publiee? + = form_tag admin_procedure_archive_path(procedure_id: procedure.id, archive: !procedure.archivee?), method: :put, style: 'float: right; margin-top: 10px;' do %button#archive.btn.btn-small.btn-default.text-info{ type: :button } %i.fa.fa-eraser Archiver @@ -39,7 +41,7 @@ %i.fa.fa-remove Annuler - - if @facade.procedure.locked? + - if procedure.locked? #procedure_locked .alert.alert-info Cette procédure a été publiée, certains éléments ne peuvent plus être modifiés. @@ -47,8 +49,8 @@ %div %h3 Lien procédure %div{ style: 'margin-left: 3%;' } - - if @facade.procedure.publiee_ou_archivee? - = link_to @facade.procedure.lien, sanitize_url(@facade.procedure.lien), target: :blank + - if procedure.publiee_ou_archivee? + = link_to procedure.lien, sanitize_url(procedure.lien), target: :blank - else %b Cette procédure n'a pas encore été publiée et n'est donc pas accessible par le public. @@ -59,34 +61,34 @@ .row{ style: 'margin-right: 3%; margin-left: 3%;' } .description.col-xs-6.col-md-3.procedure-description %h4.text-info - = @facade.procedure.libelle + = procedure.libelle - = h sanitize(@facade.procedure.description) + = h sanitize(procedure.description) .champs.col-xs-6.col-md-3 %h4.text-info Champs .badge.progress-bar-info - = @facade.procedure.types_de_champ.size + = procedure.types_de_champ.size %ul - - @facade.procedure.types_de_champ.order(:order_place).each do |champ| + - procedure.types_de_champ.order(:order_place).each do |champ| %li= champ.libelle .champs_private.col-xs-6.col-md-3 %h4.text-info Annotations privées .badge.progress-bar-info - = @facade.procedure.types_de_champ_private.size + = procedure.types_de_champ_private.size %ul - - @facade.procedure.types_de_champ_private.order(:order_place).each do |champ| + - procedure.types_de_champ_private.order(:order_place).each do |champ| %li= champ.libelle .pieces-justificatives.col-xs-6.col-md-3 %h4.text-info Pièces jointes .badge.progress-bar-info - = @facade.procedure.types_de_piece_justificative.size - - @facade.procedure.types_de_piece_justificative.each do |piece_justificative| + = procedure.types_de_piece_justificative.size + - procedure.types_de_piece_justificative.each do |piece_justificative| = piece_justificative.libelle %br %br @@ -123,19 +125,19 @@ - else = pie_chart @facade.dossiers_for_pie_highchart - - if @facade.procedure.publiee_ou_archivee? + - if procedure.publiee_ou_archivee? %h3 Supprimer la procédure .alert.alert-danger %p Attention : la suppression d'une procédure est définitive. - - dossiers_count = @facade.procedure.dossiers.count + - dossiers_count = procedure.dossiers.count - if dossiers_count > 0 %p = pluralize(dossiers_count, "dossier est rattaché", "dossiers sont rattachés") à cette procédure, la suppression de cette procédure entrainera également leur suppression. %p.text-right = link_to "J'ai compris, je supprime la procédure", - hide_admin_procedure_path(@facade.procedure), + hide_admin_procedure_path(procedure), method: :post, class: "btn btn-danger", data: { confirm: "Voulez-vous supprimer la procédure ?", disable_with: "Suppression..." } From f2357acb27335b6aaa61bff80b9774d80a90ff00 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 23 Apr 2018 16:14:29 +0200 Subject: [PATCH 12/41] Service: cannot published a procedure without a service --- app/views/admin/procedures/show.html.haml | 9 +++++++-- spec/features/admin/procedure_creation_spec.rb | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index c71ab2fd1..521fa4329 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -4,8 +4,13 @@ .row.white-back #procedure_show - if procedure.brouillon? - - if procedure.gestionnaires.size == 0 - %a.action_button.btn.btn-success#publish-procedure{ style: 'float: right; margin-top: 10px;', disabled: 'disabled', 'data-toggle' => :tooltip, title: 'Vous ne pouvez pas publier une procédure sans qu\'aucun accompagnateur ne soit affecté à celle-ci.' } + - if procedure.gestionnaires.empty? || procedure.service.nil? + - message = '' + - if procedure.gestionnaires.empty? + - message += 'Affectez des accompagnateurs à votre procédure.' + - if procedure.service.nil? + - message += 'Affectez un service à votre procédure.' + %a.action_button.btn.btn-success#publish-procedure{ style: 'float: right; margin-top: 10px;', disabled: 'disabled', 'data-toggle' => :tooltip, title: message } %i.fa.fa-eraser Publier - else diff --git a/spec/features/admin/procedure_creation_spec.rb b/spec/features/admin/procedure_creation_spec.rb index 6599b832b..cf38eb266 100644 --- a/spec/features/admin/procedure_creation_spec.rb +++ b/spec/features/admin/procedure_creation_spec.rb @@ -53,6 +53,9 @@ feature 'As an administrateur I wanna create a new procedure', js: true do page.execute_script("$('#procedure_description').val('description de la procedure')") fill_in 'procedure_organisation', with: 'organisme de la procedure' page.find_by_id('save-procedure').click + + procedure = Procedure.last + procedure.update(service: create(:service)) end scenario 'Add champ, add file, visualize them in procedure preview' do From 304c04275cf08fc77f29fa464d8c63278ff3dc64 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 23 Apr 2018 16:22:14 +0200 Subject: [PATCH 13/41] Admin Nav Bar: link to new service if no service available --- .../_left_panel_admin_procedurescontroller_navbar.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d6b31b3ba..eee01da5b 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 @@ -14,7 +14,7 @@ .procedure-list-element{ class: ('active' if active == 'Informations') } Informations - %a#onglet-services{ href: url_for(services_path(procedure_id: @procedure.id)) } + %a#onglet-services{ href: current_administrateur.services.present? ? url_for(services_path(procedure_id: @procedure.id)) : url_for(new_service_path(procedure_id: @procedure.id)) } .procedure-list-element Services From 30513bcb4fa95f080054913e008ee3199e44183e Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 23 Apr 2018 16:29:32 +0200 Subject: [PATCH 14/41] Procedure Clone: ensure the service is kept --- spec/models/procedure_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 444759a5f..643ee9d45 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -262,7 +262,8 @@ describe Procedure do describe 'clone' do let(:archived_at) { nil } let(:published_at) { nil } - let(:procedure) { create(:procedure, archived_at: archived_at, published_at: published_at, received_mail: received_mail) } + let!(:service) { create(:service) } + let(:procedure) { create(:procedure, archived_at: archived_at, published_at: published_at, received_mail: received_mail, service: service) } let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } let!(:type_de_champ_2) { create(:type_de_champ_drop_down_list, procedure: procedure, order_place: 2) } @@ -328,6 +329,10 @@ describe Procedure do it { expect(subject.cloned_from_library).to be(true) } end + it 'should keep service_id' do + expect(subject.service).to eq(service) + end + it 'should duplicate existing mail_templates' do expect(subject.received_mail.attributes.except("id", "procedure_id", "created_at", "updated_at")).to eq procedure.received_mail.attributes.except("id", "procedure_id", "created_at", "updated_at") expect(subject.received_mail.id).not_to eq procedure.received_mail.id From 0cb910f38a72756f9f9a1bc593247802d1764854 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 23 Apr 2018 17:22:20 +0200 Subject: [PATCH 15/41] Style: extract and rename accompagnateur-header to sub-header --- .../stylesheets/new_design/accompagnateur.scss | 11 ----------- app/assets/stylesheets/new_design/print.scss | 2 +- app/assets/stylesheets/new_design/sub_header.scss | 13 +++++++++++++ .../new_administrateur/procedures/apercu.html.haml | 2 +- app/views/new_gestionnaire/avis/_header.html.haml | 2 +- app/views/new_gestionnaire/avis/index.html.haml | 2 +- .../new_gestionnaire/dossiers/_header.html.haml | 2 +- .../new_gestionnaire/procedures/show.html.haml | 2 +- app/views/new_user/dossiers/index.html.haml | 2 +- app/views/root/patron.html.haml | 2 +- 10 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 app/assets/stylesheets/new_design/sub_header.scss diff --git a/app/assets/stylesheets/new_design/accompagnateur.scss b/app/assets/stylesheets/new_design/accompagnateur.scss index d5538c10b..c70e0da35 100644 --- a/app/assets/stylesheets/new_design/accompagnateur.scss +++ b/app/assets/stylesheets/new_design/accompagnateur.scss @@ -19,17 +19,6 @@ margin-bottom: 2 * $default-padding; } -.accompagnateur-header { - background-color: $light-grey; - padding-top: $default-padding; - margin-bottom: 3 * $default-spacer; - border-bottom: 1px solid $border-grey; - - .container { - margin-bottom: -1px; - } -} - .mixed-buttons-bar { flex-shrink: 0; diff --git a/app/assets/stylesheets/new_design/print.scss b/app/assets/stylesheets/new_design/print.scss index 71c4bbe4c..0a62ad243 100644 --- a/app/assets/stylesheets/new_design/print.scss +++ b/app/assets/stylesheets/new_design/print.scss @@ -2,7 +2,7 @@ @import "fonts"; .new-header, -.accompagnateur-header, +.sub-header, footer { display: none; } diff --git a/app/assets/stylesheets/new_design/sub_header.scss b/app/assets/stylesheets/new_design/sub_header.scss new file mode 100644 index 000000000..84121b6dd --- /dev/null +++ b/app/assets/stylesheets/new_design/sub_header.scss @@ -0,0 +1,13 @@ +@import "colors"; +@import "constants"; + +.sub-header { + background-color: $light-grey; + padding-top: $default-padding; + margin-bottom: 3 * $default-spacer; + border-bottom: 1px solid $border-grey; + + .container { + margin-bottom: -1px; + } +} diff --git a/app/views/new_administrateur/procedures/apercu.html.haml b/app/views/new_administrateur/procedures/apercu.html.haml index b5a8dcc4d..5e9d1732d 100644 --- a/app/views/new_administrateur/procedures/apercu.html.haml +++ b/app/views/new_administrateur/procedures/apercu.html.haml @@ -1,4 +1,4 @@ -.dossiers-headers.accompagnateur-header +.dossiers-headers.sub-header .container %h1.page-title Prévisualisation de la procédure #{@dossier.procedure.libelle} diff --git a/app/views/new_gestionnaire/avis/_header.html.haml b/app/views/new_gestionnaire/avis/_header.html.haml index aac10ae17..38bfab5b3 100644 --- a/app/views/new_gestionnaire/avis/_header.html.haml +++ b/app/views/new_gestionnaire/avis/_header.html.haml @@ -1,4 +1,4 @@ -.accompagnateur-header +.sub-header .container %ul.breadcrumbs %li= link_to('Avis', gestionnaire_avis_index_path) diff --git a/app/views/new_gestionnaire/avis/index.html.haml b/app/views/new_gestionnaire/avis/index.html.haml index 2a7c6c0a3..d62c1fd69 100644 --- a/app/views/new_gestionnaire/avis/index.html.haml +++ b/app/views/new_gestionnaire/avis/index.html.haml @@ -1,7 +1,7 @@ - avis_statut = (@statut == NewGestionnaire::AvisController::A_DONNER_STATUS) ? 'à donner' : 'rendus' - content_for(:title, "Avis #{avis_statut}") -.accompagnateur-header +.sub-header .container.flex .width-100 %h1.tab-title Avis diff --git a/app/views/new_gestionnaire/dossiers/_header.html.haml b/app/views/new_gestionnaire/dossiers/_header.html.haml index d54b07596..e30b6d7cd 100644 --- a/app/views/new_gestionnaire/dossiers/_header.html.haml +++ b/app/views/new_gestionnaire/dossiers/_header.html.haml @@ -1,4 +1,4 @@ -.accompagnateur-header +.sub-header .container .flex.justify-between %ul.breadcrumbs diff --git a/app/views/new_gestionnaire/procedures/show.html.haml b/app/views/new_gestionnaire/procedures/show.html.haml index e8a25a443..3425f5ac8 100644 --- a/app/views/new_gestionnaire/procedures/show.html.haml +++ b/app/views/new_gestionnaire/procedures/show.html.haml @@ -1,7 +1,7 @@ - content_for(:title, "#{@procedure.libelle}") #procedure-show - .accompagnateur-header + .sub-header .container.flex .procedure-logo{ style: @procedure.logo.present? ? "background-image: url(#{@procedure.logo.url})" : nil, diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml index 5c7bf13cc..cd6779443 100644 --- a/app/views/new_user/dossiers/index.html.haml +++ b/app/views/new_user/dossiers/index.html.haml @@ -1,4 +1,4 @@ -.dossiers-headers.accompagnateur-header +.dossiers-headers.sub-header .container %h1.page-title Les dossiers diff --git a/app/views/root/patron.html.haml b/app/views/root/patron.html.haml index 21ef9951e..c6802ab98 100644 --- a/app/views/root/patron.html.haml +++ b/app/views/root/patron.html.haml @@ -131,7 +131,7 @@ %td Table Data 3 %h1 Header - .accompagnateur-header + .sub-header .container Titre %ul.tabs From 0be21395ace93c29187c8dab21f4e159916225e8 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 24 Apr 2018 10:07:20 +0200 Subject: [PATCH 16/41] [fix #1829] Service: add breadcrumbs --- .../new_administrateur/services_controller.rb | 2 ++ app/views/new_administrateur/_breadcrumbs.html.haml | 5 +++++ app/views/new_administrateur/services/edit.html.haml | 8 +++++++- app/views/new_administrateur/services/index.html.haml | 11 ++++++++--- app/views/new_administrateur/services/new.html.haml | 8 +++++++- 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 app/views/new_administrateur/_breadcrumbs.html.haml diff --git a/app/controllers/new_administrateur/services_controller.rb b/app/controllers/new_administrateur/services_controller.rb index c147dde38..293e7f608 100644 --- a/app/controllers/new_administrateur/services_controller.rb +++ b/app/controllers/new_administrateur/services_controller.rb @@ -6,6 +6,7 @@ module NewAdministrateur end def new + @procedure = procedure end def create @@ -23,6 +24,7 @@ module NewAdministrateur def edit @service = service + @procedure = procedure end def update diff --git a/app/views/new_administrateur/_breadcrumbs.html.haml b/app/views/new_administrateur/_breadcrumbs.html.haml new file mode 100644 index 000000000..c6a77d41a --- /dev/null +++ b/app/views/new_administrateur/_breadcrumbs.html.haml @@ -0,0 +1,5 @@ +.sub-header + .container + %ul.breadcrumbs + - steps.each do |step| + %li= step diff --git a/app/views/new_administrateur/services/edit.html.haml b/app/views/new_administrateur/services/edit.html.haml index 2f3b9f129..e23460425 100644 --- a/app/views/new_administrateur/services/edit.html.haml +++ b/app/views/new_administrateur/services/edit.html.haml @@ -1,5 +1,11 @@ += render partial: 'new_administrateur/breadcrumbs', + locals: { steps: [link_to('Procedures', admin_procedures_path), + link_to(@procedure.libelle, admin_procedure_path(@procedure)), + link_to('choix du service', services_path(procedure_id: @procedure.id)), + 'modifier le service'] } + .container %h1 Modifier le service = render partial: 'form', - locals: { service: @service, procedure_id: params[:procedure_id] } + locals: { service: @service, procedure_id: @procedure.id } diff --git a/app/views/new_administrateur/services/index.html.haml b/app/views/new_administrateur/services/index.html.haml index 13926644a..2a3df9771 100644 --- a/app/views/new_administrateur/services/index.html.haml +++ b/app/views/new_administrateur/services/index.html.haml @@ -1,3 +1,8 @@ += render partial: 'new_administrateur/breadcrumbs', + locals: { steps: [link_to('Procedures', admin_procedures_path), + link_to(@procedure.libelle, admin_procedure_path(@procedure)), + 'choix du service'] } + #services-index.container %h1 Choix du service pour la procédure @@ -19,7 +24,7 @@ %th nom %th.change - = link_to('Nouveau service', new_service_path(procedure_id: params[:procedure_id]), class: 'button') + = link_to('Nouveau service', new_service_path(procedure_id: @procedure.id), class: 'button') %tbody - @services.each do |service| @@ -27,8 +32,8 @@ %td = service.nom %td.change - = link_to('modifier', edit_service_path(service, procedure_id: params[:procedure_id])) + = link_to('modifier', edit_service_path(service, procedure_id: @procedure.id)) = link_to 'supprimer', - service_path(service, procedure_id: params[:procedure_id]), + service_path(service, procedure_id: @procedure.id), method: :delete, data: { confirm: "Confirmez vous la suppression de #{service.nom}" } diff --git a/app/views/new_administrateur/services/new.html.haml b/app/views/new_administrateur/services/new.html.haml index 34ef8027c..635c38373 100644 --- a/app/views/new_administrateur/services/new.html.haml +++ b/app/views/new_administrateur/services/new.html.haml @@ -1,5 +1,11 @@ += render partial: 'new_administrateur/breadcrumbs', + locals: { steps: [link_to('Procedures', admin_procedures_path), + link_to(@procedure.libelle, admin_procedure_path(@procedure)), + link_to('choix du service', services_path(procedure_id: @procedure.id)), + 'nouveau service'] } + .container %h1 Nouveau Service = render partial: 'form', - locals: { service: Service.new, procedure_id: params[:procedure_id] } + locals: { service: Service.new, procedure_id: @procedure.id } From 39bb56d1d9803e369783df64bc7d51e3171c67cb Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 10 May 2018 11:38:11 +0200 Subject: [PATCH 17/41] Service: add organisme, email, tel, horaires, adresse --- .../new_administrateur/services_controller.rb | 2 +- app/models/service.rb | 5 ++++ .../services/_form.html.haml | 25 +++++++++++++++++++ .../20180509152919_add_columns_to_service.rb | 9 +++++++ db/schema.rb | 5 ++++ .../services_controller_spec.rb | 12 ++++++++- spec/factories/service.rb | 5 ++++ spec/models/service_spec.rb | 5 ++++ 8 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20180509152919_add_columns_to_service.rb diff --git a/app/controllers/new_administrateur/services_controller.rb b/app/controllers/new_administrateur/services_controller.rb index 293e7f608..4e1538fad 100644 --- a/app/controllers/new_administrateur/services_controller.rb +++ b/app/controllers/new_administrateur/services_controller.rb @@ -70,7 +70,7 @@ module NewAdministrateur private def service_params - params.require(:service).permit(:nom, :type_organisme) + params.require(:service).permit(:nom, :organisme, :type_organisme, :email, :telephone, :horaires, :adresse) end def service diff --git a/app/models/service.rb b/app/models/service.rb index 0ea150b8a..2521a4f04 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -17,6 +17,11 @@ class Service < ApplicationRecord validates :nom, presence: { message: 'doit être renseigné' }, allow_nil: false validates :nom, uniqueness: { scope: :administrateur, message: 'existe déjà' } + validates :organisme, presence: { message: 'doit être renseigné' }, allow_nil: false validates :type_organisme, presence: { message: 'doit être renseigné' }, allow_nil: false + validates :email, presence: { message: 'doit être renseigné' }, allow_nil: false + validates :telephone, presence: { message: 'doit être renseigné' }, allow_nil: false + validates :horaires, presence: { message: 'doivent être renseignés' }, allow_nil: false + validates :adresse, presence: { message: 'doit être renseignée' }, allow_nil: false validates :administrateur, presence: { message: 'doit être renseigné' }, allow_nil: false end diff --git a/app/views/new_administrateur/services/_form.html.haml b/app/views/new_administrateur/services/_form.html.haml index f0e40cf1e..6654678a9 100644 --- a/app/views/new_administrateur/services/_form.html.haml +++ b/app/views/new_administrateur/services/_form.html.haml @@ -5,12 +5,37 @@ %span.mandatory * = f.text_field :nom, placeholder: 'service jeunesse et prévention, direction des affaires maritimes', required: true + = f.label :organisme do + Organisme + %span.mandatory * + = f.text_field :organisme, placeholder: "mairie de Mours, préfecture de l'Oise, ministère de la Culture", required: true + = f.label :type_organisme do Type d’organisme %span.mandatory * = f.select :type_organisme, Service.type_organismes.keys.map { |key| [ I18n.t("type_organisme.#{key}"), key] } + = f.label :email do + Courriel + %span.mandatory * + = f.email_field :email, placeholder: 'contact@mon-service.fr', required: true + + = f.label :telephone do + Numéro de téléphone + %span.mandatory * + = f.telephone_field :telephone, placeholder: '04 12 24 42 37', required: true + + = f.label :horaires do + Horaires + %span.mandatory * + = f.text_area :horaires, placeholder: "Du lundi au vendredi de 9 h 30 à 17 h 30\nLe samedi de 9 h 30 à 12 h", required: true + + = f.label :adresse do + Adresse + %span.mandatory * + = f.text_area :adresse, placeholder: "20 avenue de Ségur\n75007 Paris", required: true + - if procedure_id.present? = hidden_field_tag :procedure_id, procedure_id diff --git a/db/migrate/20180509152919_add_columns_to_service.rb b/db/migrate/20180509152919_add_columns_to_service.rb new file mode 100644 index 000000000..00ced36ec --- /dev/null +++ b/db/migrate/20180509152919_add_columns_to_service.rb @@ -0,0 +1,9 @@ +class AddColumnsToService < ActiveRecord::Migration[5.2] + def change + add_column :services, :organisme, :string + add_column :services, :email, :string + add_column :services, :telephone, :string + add_column :services, :horaires, :text + add_column :services, :adresse, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 57f898afe..ee11226de 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -519,6 +519,11 @@ ActiveRecord::Schema.define(version: 2018_05_15_135415) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.bigint "administrateur_id" + t.string "organisme" + t.string "email" + t.string "telephone" + t.text "horaires" + t.text "adresse" t.index ["administrateur_id", "nom"], name: "index_services_on_administrateur_id_and_nom", unique: true t.index ["administrateur_id"], name: "index_services_on_administrateur_id" end diff --git a/spec/controllers/new_administrateur/services_controller_spec.rb b/spec/controllers/new_administrateur/services_controller_spec.rb index da1df6dad..c3fb96838 100644 --- a/spec/controllers/new_administrateur/services_controller_spec.rb +++ b/spec/controllers/new_administrateur/services_controller_spec.rb @@ -12,7 +12,12 @@ describe NewAdministrateur::ServicesController, type: :controller do { service: { nom: 'super service', - type_organisme: 'region' + organisme: 'organisme', + type_organisme: 'region', + email: 'email@toto.com', + telephone: '1234', + horaires: 'horaires', + adresse: 'adresse' }, procedure_id: 12 } @@ -21,7 +26,12 @@ describe NewAdministrateur::ServicesController, type: :controller do it { expect(flash.alert).to be_nil } it { expect(flash.notice).to eq('super service créé') } it { expect(Service.last.nom).to eq('super service') } + it { expect(Service.last.organisme).to eq('organisme') } it { expect(Service.last.type_organisme).to eq('region') } + it { expect(Service.last.email).to eq('email@toto.com') } + it { expect(Service.last.telephone).to eq('1234') } + it { expect(Service.last.horaires).to eq('horaires') } + it { expect(Service.last.adresse).to eq('adresse') } it { expect(response).to redirect_to(services_path(procedure_id: 12)) } end diff --git a/spec/factories/service.rb b/spec/factories/service.rb index bffd5dc44..55512ba4d 100644 --- a/spec/factories/service.rb +++ b/spec/factories/service.rb @@ -1,7 +1,12 @@ FactoryBot.define do factory :service do nom 'service' + organisme 'organisme' type_organisme 'commune' administrateur { create(:administrateur) } + email 'email@toto.com' + telephone '1234' + horaires 'de 9 h à 18 h' + adresse 'adresse' end end diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index 64802d55e..cffd5e8e1 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -4,7 +4,12 @@ describe Service, type: :model do let(:params) do { nom: 'service des jardins', + organisme: 'mairie des iles', type_organisme: 'commune', + email: 'super@email.com', + telephone: '1212202', + horaires: 'du lundi au vendredi', + adresse: '12 rue des schtroumpfs', administrateur_id: administrateur.id } end From 928227a61029ff1ed69fe4a6eabdc17949064cf9 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 11 May 2018 12:09:32 +0200 Subject: [PATCH 18/41] Procedure: remove now duplicate organisation and direction --- app/models/procedure.rb | 1 - app/views/admin/procedures/_informations.html.haml | 2 +- .../20180511100229_allow_procedure_organisme_to_be_null.rb | 5 +++++ db/schema.rb | 2 +- spec/features/admin/procedure_cloning_spec.rb | 1 - spec/features/admin/procedure_creation_spec.rb | 2 -- spec/models/procedure_spec.rb | 2 -- 7 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20180511100229_allow_procedure_organisme_to_be_null.rb diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 2744623dd..0dda498e1 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -46,7 +46,6 @@ class Procedure < ApplicationRecord validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :description, presence: true, allow_blank: false, allow_nil: false - validates :organisation, presence: true, allow_blank: false, allow_nil: false # Warning: dossier after_save build_default_champs must be removed # to save a dossier created from this method diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index 9494f21eb..314a454ef 100644 --- a/app/views/admin/procedures/_informations.html.haml +++ b/app/views/admin/procedures/_informations.html.haml @@ -2,7 +2,7 @@ .alert.alert-info Cette procédure est publiée, certains éléments de la description ne sont plus modifiables -- { libelle: 'Libellé*', description: 'Description*', organisation: 'Organisme*', direction: 'Direction', lien_site_web: 'Lien site internet', web_hook_url: 'Lien de rappel HTTP' }.each do |key, value| +- { libelle: 'Libellé*', description: 'Description*', lien_site_web: 'Lien site internet', web_hook_url: 'Lien de rappel HTTP' }.each do |key, value| - if key != :web_hook_url || Flipflop.web_hook? .form-group %h4 diff --git a/db/migrate/20180511100229_allow_procedure_organisme_to_be_null.rb b/db/migrate/20180511100229_allow_procedure_organisme_to_be_null.rb new file mode 100644 index 000000000..bb60fa2c3 --- /dev/null +++ b/db/migrate/20180511100229_allow_procedure_organisme_to_be_null.rb @@ -0,0 +1,5 @@ +class AllowProcedureOrganismeToBeNull < ActiveRecord::Migration[5.2] + def change + change_column_null :procedures, :organisation, true + end +end diff --git a/db/schema.rb b/db/schema.rb index ee11226de..5b4dbd414 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -441,7 +441,7 @@ ActiveRecord::Schema.define(version: 2018_05_15_135415) do create_table "procedures", id: :serial, force: :cascade do |t| t.string "libelle" t.string "description" - t.string "organisation", null: false + t.string "organisation" t.string "direction" t.string "lien_demarche" t.datetime "created_at", null: false diff --git a/spec/features/admin/procedure_cloning_spec.rb b/spec/features/admin/procedure_cloning_spec.rb index 149bf0242..6cb94edf7 100644 --- a/spec/features/admin/procedure_cloning_spec.rb +++ b/spec/features/admin/procedure_cloning_spec.rb @@ -14,7 +14,6 @@ feature 'As an administrateur I wanna clone a procedure', js: true do page.find_by_id('from-scratch').click fill_in 'procedure_libelle', with: 'libelle de la procedure' page.execute_script("$('#procedure_description').val('description de la procedure')") - fill_in 'procedure_organisation', with: 'organisme de la procedure' page.find_by_id('save-procedure').click end diff --git a/spec/features/admin/procedure_creation_spec.rb b/spec/features/admin/procedure_creation_spec.rb index cf38eb266..9523f3681 100644 --- a/spec/features/admin/procedure_creation_spec.rb +++ b/spec/features/admin/procedure_creation_spec.rb @@ -39,7 +39,6 @@ feature 'As an administrateur I wanna create a new procedure', js: true do page.find_by_id('flash_message').visible? fill_in 'procedure_libelle', with: 'libelle de la procedure' page.execute_script("$('#procedure_description').val('description de la procedure')") - fill_in 'procedure_organisation', with: 'organisme de la procedure' page.find_by_id('save-procedure').click expect(page).to have_current_path(admin_procedure_types_de_champ_path(Procedure.first.id.to_s)) end @@ -51,7 +50,6 @@ feature 'As an administrateur I wanna create a new procedure', js: true do page.find_by_id('from-scratch').click fill_in 'procedure_libelle', with: 'libelle de la procedure' page.execute_script("$('#procedure_description').val('description de la procedure')") - fill_in 'procedure_organisation', with: 'organisme de la procedure' page.find_by_id('save-procedure').click procedure = Procedure.last diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 643ee9d45..0f3aec2f7 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -171,8 +171,6 @@ describe Procedure do end context 'organisation' do - it { is_expected.not_to allow_value(nil).for(:organisation) } - it { is_expected.not_to allow_value('').for(:organisation) } it { is_expected.to allow_value('URRSAF').for(:organisation) } end end From cbf0a9b34061041927e05708e40cbea42c3658e0 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 18 May 2018 17:41:03 +0200 Subject: [PATCH 19/41] Skylight: update gem Cause it's polluting the errors logs with invalid slq parsing error --- Gemfile.lock | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 532fc7acb..4b99aef14 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -695,8 +695,10 @@ GEM rack (~> 2.0) rack-protection (= 2.0.1) tilt (~> 2.0) - skylight (1.6.1) - activesupport (>= 3.0.0) + skylight (2.0.1) + skylight-core (= 2.0.1) + skylight-core (2.0.1) + activesupport (>= 4.2.0) smart_listing (1.2.2) coffee-rails jquery-rails From 682823ec938686fc4e2213d3ef33aaea43cf5b13 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 18 May 2018 18:06:48 +0200 Subject: [PATCH 20/41] Bump gems - apipie-rails - brakeman - dotenv-rails - openid_connect - openstack - rack-mini-profiler - rubocop - sentry-raven - web-console - webmock --- .rubocop.yml | 11 ++++-- Gemfile.lock | 38 +++++++++---------- .../api/v1/dossiers_controller_spec.rb | 22 +++++------ 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2683194bb..853e107d7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -79,6 +79,9 @@ Layout/EmptyLineBetweenDefs: Layout/EmptyLines: Enabled: true +Layout/EmptyLineAfterGuardClause: + Enabled: false + Layout/EmptyLinesAroundAccessModifier: Enabled: true @@ -899,9 +902,6 @@ Style/EmptyElse: Style/EmptyLambdaParameter: Enabled: true -Style/EmptyLineAfterGuardClause: - Enabled: false - Style/EmptyLiteral: Enabled: false @@ -995,7 +995,7 @@ Style/MethodCalledOnDoEndBlock: Style/MethodDefParentheses: Enabled: true -Style/MethodMissing: +Style/MethodMissingSuper: Enabled: false Style/MinMax: @@ -1004,6 +1004,9 @@ Style/MinMax: Style/MissingElse: Enabled: false +Style/MissingRespondToMissing: + Enabled: false + Style/MixinGrouping: Enabled: false diff --git a/Gemfile.lock b/Gemfile.lock index 4b99aef14..bac604e89 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,7 +95,7 @@ GEM sass-rails (~> 5.0) selectize-rails (~> 0.6) aes_key_wrap (1.0.1) - apipie-rails (0.5.7) + apipie-rails (0.5.8) rails (>= 4.1) arel (9.0.0) ast (2.4.0) @@ -114,7 +114,7 @@ GEM sass (>= 3.3.4) bootstrap-wysihtml5-rails (0.3.3.8) railties (>= 3.0) - brakeman (4.2.1) + brakeman (4.3.0) browser (2.5.3) builder (3.2.3) byebug (10.0.2) @@ -178,9 +178,9 @@ GEM diff-lcs (1.3) domain_name (0.5.20170404) unf (>= 0.0.5, < 1.0.0) - dotenv (2.3.0) - dotenv-rails (2.3.0) - dotenv (= 2.3.0) + dotenv (2.4.0) + dotenv-rails (2.4.0) + dotenv (= 2.4.0) railties (>= 3.2, < 6.0) draper (3.0.1) actionpack (~> 5.0) @@ -420,12 +420,10 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (2.1.0) - json-jwt (1.9.2) + json-jwt (1.9.4) activesupport aes_key_wrap bindata - securecompare - url_safe_base64 jsonapi-renderer (0.2.0) jwt (1.5.6) kaminari (1.1.1) @@ -486,7 +484,7 @@ GEM mustermann (1.0.2) nenv (0.3.0) netrc (0.11.0) - nio4r (2.3.0) + nio4r (2.3.1) nokogiri (1.8.2) mini_portile2 (~> 2.3.0) notiffany (0.1.1) @@ -508,7 +506,7 @@ GEM oauth2 (~> 1.1) omniauth (~> 1.2) open4 (1.3.4) - openid_connect (1.1.5) + openid_connect (1.1.6) activemodel attr_required (>= 1.0.0) json-jwt (>= 1.5.0) @@ -518,7 +516,7 @@ GEM validate_email validate_url webfinger (>= 1.0.1) - openstack (3.3.17) + openstack (3.3.18) json orm_adapter (0.5.0) parallel (1.12.1) @@ -540,12 +538,12 @@ GEM byebug (~> 10.0) pry (~> 0.10) public_suffix (3.0.2) - rack (2.0.4) + rack (2.0.5) rack-handlers (0.7.3) rack - rack-mini-profiler (0.10.7) + rack-mini-profiler (1.0.0) rack (>= 1.2.0) - rack-oauth2 (1.9.0) + rack-oauth2 (1.9.2) activesupport attr_required httpclient @@ -641,7 +639,7 @@ GEM rspec-support (3.7.1) rspec_junit_formatter (0.3.0) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (0.55.0) + rubocop (0.56.0) parallel (~> 1.10) parser (>= 2.5) powerpack (~> 0.1) @@ -674,14 +672,13 @@ GEM scss_lint (0.57.0) rake (>= 0.9, < 13) sass (~> 3.5.5) - securecompare (1.0.0) select2-rails (4.0.3) thor (~> 0.14) selectize-rails (0.12.4.1) selenium-webdriver (3.8.0) childprocess (~> 0.5) rubyzip (~> 1.0) - sentry-raven (2.7.2) + sentry-raven (2.7.3) faraday (>= 0.7.6, < 1.0) sexp_processor (4.11.0) shellany (0.0.1) @@ -745,12 +742,11 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.5) - unicode-display_width (1.3.0) + unicode-display_width (1.3.2) unicode_utils (1.4.0) unicorn (5.4.0) kgio (~> 2.6) raindrops (~> 0.7) - url_safe_base64 (0.2.2) validate_email (0.1.6) activemodel (>= 3.0) mail (>= 2.2.5) @@ -758,7 +754,7 @@ GEM activemodel (>= 3.0.0) addressable vcr (4.0.0) - web-console (3.6.1) + web-console (3.6.2) actionview (>= 5.0) activemodel (>= 5.0) bindex (>= 0.4.0) @@ -766,7 +762,7 @@ GEM webfinger (1.1.0) activesupport httpclient (>= 2.4) - webmock (3.3.0) + webmock (3.4.1) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index 33abe8bd3..3852b60eb 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -186,7 +186,7 @@ describe API::V1::DossiersController do describe 'first type de piece justificative' do subject { super().first } - it { expect(subject.keys.include?(:id)).to be_truthy } + it { expect(subject.key?(:id)).to be_truthy } it { expect(subject[:libelle]).to eq('RIB') } it { expect(subject[:description]).to eq('Releve identité bancaire') } end @@ -200,11 +200,11 @@ describe API::V1::DossiersController do let(:field_list) { [:url, :created_at, :type_de_piece_justificative_id] } subject { super()[:pieces_justificatives].first } - it { expect(subject.keys.include?(:content_url)).to be_truthy } + it { expect(subject.key?(:content_url)).to be_truthy } it { expect(subject[:created_at]).not_to be_nil } it { expect(subject[:type_de_piece_justificative_id]).not_to be_nil } - it { expect(subject.keys.include?(:user)).to be_truthy } + it { expect(subject.key?(:user)).to be_truthy } describe 'user' do subject { super()[:user] } @@ -222,8 +222,8 @@ describe API::V1::DossiersController do describe 'first champs' do subject { super().first } - it { expect(subject.keys.include?(:value)).to be_truthy } - it { expect(subject.keys.include?(:type_de_champ)).to be_truthy } + it { expect(subject.key?(:value)).to be_truthy } + it { expect(subject.key?(:type_de_champ)).to be_truthy } describe 'type de champ' do let(:field_list) { @@ -237,10 +237,10 @@ describe API::V1::DossiersController do } subject { super()[:type_de_champ] } - it { expect(subject.keys.include?(:id)).to be_truthy } + it { expect(subject.key?(:id)).to be_truthy } it { expect(subject[:libelle]).to include('Libelle du champ') } it { expect(subject[:description]).to include('description du champ') } - it { expect(subject.keys.include?(:order_place)).to be_truthy } + it { expect(subject.key?(:order_place)).to be_truthy } it { expect(subject[:type_champ]).to eq('text') } end end @@ -295,8 +295,8 @@ describe API::V1::DossiersController do describe 'first champs' do subject { super().first } - it { expect(subject.keys.include?(:value)).to be_truthy } - it { expect(subject.keys.include?(:type_de_champ)).to be_truthy } + it { expect(subject.key?(:value)).to be_truthy } + it { expect(subject.key?(:type_de_champ)).to be_truthy } describe 'type de champ' do let(:field_list) { @@ -310,10 +310,10 @@ describe API::V1::DossiersController do } subject { super()[:type_de_champ] } - it { expect(subject.keys.include?(:id)).to be_truthy } + it { expect(subject.key?(:id)).to be_truthy } it { expect(subject[:libelle]).to include('Libelle champ privé') } it { expect(subject[:description]).to include('description du champ privé') } - it { expect(subject.keys.include?(:order_place)).to be_truthy } + it { expect(subject.key?(:order_place)).to be_truthy } it { expect(subject[:type_champ]).to eq('text') } end end From 11d83e75792663d7945313628739d728948dd3b3 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Tue, 22 May 2018 12:22:07 +0200 Subject: [PATCH 21/41] Add translations for flipflop to avoid missing translation keys in feature screen in manager --- config/locales/flipflop.fr.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 config/locales/flipflop.fr.yml diff --git a/config/locales/flipflop.fr.yml b/config/locales/flipflop.fr.yml new file mode 100644 index 000000000..d0f9a6162 --- /dev/null +++ b/config/locales/flipflop.fr.yml @@ -0,0 +1,10 @@ +# These translations are used in the manager interface, which is in English, +# so we use English translations + +fr: + flipflop: + title: "%{application} features" + + feature_states: + enabled: "On" + disabled: "Off" From 0a07e9983a7e2d54c3aaae077a6812e6171f8f94 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 22 May 2018 16:24:24 +0200 Subject: [PATCH 22/41] Fix test with ordering failures --- app/controllers/admin/procedures_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index f7535fa7c..fa948bc78 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -232,15 +232,15 @@ class Admin::ProceduresController < AdminController def path_list json_path_list = ProcedurePath - .joins(', procedures') - .where("procedures.id = procedure_paths.procedure_id") - .where("procedures.archived_at" => nil) + .joins(:procedure) + .where(procedures: { archived_at: nil }) .where("path LIKE ?", "%#{params[:request]}%") + .order(:id) .pluck(:path, :administrateur_id) - .map do |value| + .map do |path, administrateur_id| { - label: value.first, - mine: value.second == current_administrateur.id + label: path, + mine: administrateur_id == current_administrateur.id } end.to_json From 6136e3a3f8f155ce759bf9924fd15ab5506e9642 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 22 May 2018 16:01:37 +0200 Subject: [PATCH 23/41] Update binstubs --- bin/rspec | 3 +++ bin/setup | 8 +++++--- bin/update | 6 ++++-- bin/yarn | 11 +++++++++++ 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100755 bin/rspec create mode 100755 bin/yarn diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 000000000..cf3d49c41 --- /dev/null +++ b/bin/rspec @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +load Gem.bin_path('rspec-core', 'rspec') diff --git a/bin/setup b/bin/setup index 04e288aec..94fd4d797 100755 --- a/bin/setup +++ b/bin/setup @@ -1,10 +1,9 @@ #!/usr/bin/env ruby -require 'pathname' require 'fileutils' include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../', __dir__) +APP_ROOT = File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -18,8 +17,11 @@ chdir APP_ROOT do system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + # puts "\n== Copying sample files ==" - # if !File.exist?('config/database.yml') + # unless File.exist?('config/database.yml') # cp 'config/database.yml.sample', 'config/database.yml' # end diff --git a/bin/update b/bin/update index f02dfd611..58bfaed51 100755 --- a/bin/update +++ b/bin/update @@ -1,10 +1,9 @@ #!/usr/bin/env ruby -require 'pathname' require 'fileutils' include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../', __dir__) +APP_ROOT = File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -18,6 +17,9 @@ chdir APP_ROOT do system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + puts "\n== Updating database ==" system! 'bin/rails db:migrate' diff --git a/bin/yarn b/bin/yarn new file mode 100755 index 000000000..542c351ad --- /dev/null +++ b/bin/yarn @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +APP_ROOT = File.expand_path('..', __dir__) +Dir.chdir(APP_ROOT) do + begin + exec "yarnpkg", *ARGV + rescue Errno::ENOENT + warn "Yarn executable was not detected in the system." + warn "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 + end +end From 5e2219416e588808fd2b60142af508e070a38af2 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 22 May 2018 17:12:17 +0200 Subject: [PATCH 24/41] Add the DOC_URL constant --- app/views/administration_mailer/invite_admin.html.haml | 2 +- app/views/gestionnaire_mailer/invite_gestionnaire.html.haml | 2 +- app/views/layouts/_new_footer.html.haml | 2 +- app/views/root/landing.html.haml | 2 +- config/initializers/constants.rb | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/views/administration_mailer/invite_admin.html.haml b/app/views/administration_mailer/invite_admin.html.haml index dfbf0cb3c..49be915cd 100644 --- a/app/views/administration_mailer/invite_admin.html.haml +++ b/app/views/administration_mailer/invite_admin.html.haml @@ -16,7 +16,7 @@ Vous pouvez me joindre au numéro suivant : 01 76 42 02 87. %br %br Je vous invite également à consulter notre site de documentation qui regroupe l'ensemble des informations relatives à demarches-simplifiees.fr ainsi que des tutoriels d’utilisation : -= link_to('https://demarches-simplifiees.gitbook.io/demarches-simplifiees/', 'https://demarches-simplifiees.gitbook.io/demarches-simplifiees/') += link_to(DOC_URL, DOC_URL) %br %br = render partial: "layouts/mailers/bizdev_signature" diff --git a/app/views/gestionnaire_mailer/invite_gestionnaire.html.haml b/app/views/gestionnaire_mailer/invite_gestionnaire.html.haml index 3b5fa28d3..56d39d440 100644 --- a/app/views/gestionnaire_mailer/invite_gestionnaire.html.haml +++ b/app/views/gestionnaire_mailer/invite_gestionnaire.html.haml @@ -10,7 +10,7 @@ Votre compte a été créé pour l'adresse email #{@gestionnaire.email}. Pour l %br %br Par ailleurs, notre site de documentation qui regroupe l'ensemble des informations relatives à demarches-simplifiees.fr ainsi que des tutoriels d’utilisation est à votre disposition :  -= link_to('https://demarches-simplifiees.gitbook.io/demarches-simplifiees/', 'https://demarches-simplifiees.gitbook.io/demarches-simplifiees/') += link_to(DOC_URL, DOC_URL) %br %br Bonne journée, diff --git a/app/views/layouts/_new_footer.html.haml b/app/views/layouts/_new_footer.html.haml index 264c5c331..8eedebb7a 100644 --- a/app/views/layouts/_new_footer.html.haml +++ b/app/views/layouts/_new_footer.html.haml @@ -33,7 +33,7 @@ "mailto:#{t('dynamics.contact_email')}", :class => "footer-link" %li.footer-link - = link_to "Documentation", "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/", :class => "footer-link", :target => "_blank", rel: "noopener noreferrer" + = link_to "Documentation", DOC_URL, :class => "footer-link", :target => "_blank", rel: "noopener noreferrer" %li.footer-link = link_to "Documentation de l'API", "/docs", :class => "footer-link", :target => "_blank", rel: "noopener noreferrer" %li.footer-link diff --git a/app/views/root/landing.html.haml b/app/views/root/landing.html.haml index f208b0a79..9aa8c71ed 100644 --- a/app/views/root/landing.html.haml +++ b/app/views/root/landing.html.haml @@ -74,7 +74,7 @@ onclick: "javascript: ga('send', 'pageview', '/demander-une-demo')" = link_to "Voir la documentation", - "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/", + DOC_URL, target: "_blank", rel: "noopener noreferrer", class: "role-panel-button-secondary" diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 95da3f7ed..360a8862e 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -1 +1,2 @@ +DOC_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/" CGU_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/cgu" From dc962f0c0a0286147609a99e12850eca3a1e97df Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 22 May 2018 17:12:51 +0200 Subject: [PATCH 25/41] Add LISTE_DES_DEMARCHES_URL --- app/views/root/landing.html.haml | 2 +- config/initializers/constants.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/root/landing.html.haml b/app/views/root/landing.html.haml index 9aa8c71ed..f518b3086 100644 --- a/app/views/root/landing.html.haml +++ b/app/views/root/landing.html.haml @@ -51,7 +51,7 @@ class: "role-panel-button-primary" = link_to "Voir les démarches disponibles", - "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/listes-des-demarches", + LISTE_DES_DEMARCHES_URL, target: "_blank", rel: "noopener noreferrer", class: "role-panel-button-secondary" diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 360a8862e..a6ab22e05 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -1,2 +1,3 @@ DOC_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/" +LISTE_DES_DEMARCHES_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/listes-des-demarches" CGU_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/cgu" From 5126503cfc8592086b56151b12ab4c80cec2edbd Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 22 May 2018 17:13:30 +0200 Subject: [PATCH 26/41] Add MENTIONS_LEGALES_URL --- app/views/layouts/_new_footer.html.haml | 2 +- config/initializers/constants.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/_new_footer.html.haml b/app/views/layouts/_new_footer.html.haml index 8eedebb7a..3568a88ac 100644 --- a/app/views/layouts/_new_footer.html.haml +++ b/app/views/layouts/_new_footer.html.haml @@ -24,7 +24,7 @@ %li.footer-link = link_to "CGU", CGU_URL, :class => "footer-link", :target => "_blank", rel: "noopener noreferrer" %li.footer-link - = link_to "Mentions légales", "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/cgu#4.-mentions-legales", :class => "footer-link", :target => "_blank", rel: "noopener noreferrer" + = link_to "Mentions légales", MENTIONS_LEGALES_URL, :class => "footer-link", :target => "_blank", rel: "noopener noreferrer" %li.footer-column %ul.footer-links diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index a6ab22e05..e4e9a50da 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -1,3 +1,4 @@ DOC_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/" LISTE_DES_DEMARCHES_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/listes-des-demarches" CGU_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/cgu" +MENTIONS_LEGALES_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/cgu#4.-mentions-legales" From 52d878fea85734a3baf52a3b139ecfa983dc66c8 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 22 May 2018 17:16:09 +0200 Subject: [PATCH 27/41] Remove trailing slash from DOC_URL --- config/initializers/constants.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index e4e9a50da..4a5920570 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -1,4 +1,4 @@ -DOC_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/" +DOC_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees" LISTE_DES_DEMARCHES_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/listes-des-demarches" CGU_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/cgu" MENTIONS_LEGALES_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/cgu#4.-mentions-legales" From b93ec30a2d4e88269e028b5cee1e66d5f9c6bc49 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 22 May 2018 17:17:14 +0200 Subject: [PATCH 28/41] Make the GitBook URLs depend on DOC_URL --- config/initializers/constants.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 4a5920570..963e7a9b8 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -1,4 +1,4 @@ DOC_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees" -LISTE_DES_DEMARCHES_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/listes-des-demarches" -CGU_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/cgu" -MENTIONS_LEGALES_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees/cgu#4.-mentions-legales" +LISTE_DES_DEMARCHES_URL = [DOC_URL, "listes-des-demarches"].join("/") +CGU_URL = [DOC_URL, "cgu"].join("/") +MENTIONS_LEGALES_URL = [CGU_URL, "4.-mentions-legales"].join("#") From 6ac8d6abf8fe9f8a68245e8651dee468fcade2b6 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 22 May 2018 17:17:42 +0200 Subject: [PATCH 29/41] Update the DOC_URL --- config/initializers/constants.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 963e7a9b8..373660a54 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -1,4 +1,4 @@ -DOC_URL = "https://demarches-simplifiees.gitbook.io/demarches-simplifiees" +DOC_URL = "https://doc.demarches-simplifiees.fr" LISTE_DES_DEMARCHES_URL = [DOC_URL, "listes-des-demarches"].join("/") CGU_URL = [DOC_URL, "cgu"].join("/") MENTIONS_LEGALES_URL = [CGU_URL, "4.-mentions-legales"].join("#") From de201fca0476baacde48b5af3f5b92aedd73425b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 22 May 2018 17:18:06 +0200 Subject: [PATCH 30/41] Add FAQ_URL --- app/views/layouts/_new_footer.html.haml | 2 +- config/initializers/constants.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/_new_footer.html.haml b/app/views/layouts/_new_footer.html.haml index 3568a88ac..462609955 100644 --- a/app/views/layouts/_new_footer.html.haml +++ b/app/views/layouts/_new_footer.html.haml @@ -37,6 +37,6 @@ %li.footer-link = link_to "Documentation de l'API", "/docs", :class => "footer-link", :target => "_blank", rel: "noopener noreferrer" %li.footer-link - = link_to "FAQ", "http://demarches-simplifiees.helpscoutdocs.com/", :class => "footer-link", :target => "_blank", rel: "noopener noreferrer" + = link_to "FAQ", FAQ_URL, :class => "footer-link", :target => "_blank", rel: "noopener noreferrer" %li.footer-link = link_to "Accessibilité", accessibilite_index_path, :class => "footer-link" diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 373660a54..f9541e56f 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -2,3 +2,5 @@ DOC_URL = "https://doc.demarches-simplifiees.fr" LISTE_DES_DEMARCHES_URL = [DOC_URL, "listes-des-demarches"].join("/") CGU_URL = [DOC_URL, "cgu"].join("/") MENTIONS_LEGALES_URL = [CGU_URL, "4.-mentions-legales"].join("#") + +FAQ_URL = "http://demarches-simplifiees.helpscoutdocs.com/" From a98ab683aa641a10718e01188ba99c9d822bbe85 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 22 May 2018 17:18:33 +0200 Subject: [PATCH 31/41] Update FAQ_URL --- config/initializers/constants.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index f9541e56f..2a942a275 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -3,4 +3,4 @@ LISTE_DES_DEMARCHES_URL = [DOC_URL, "listes-des-demarches"].join("/") CGU_URL = [DOC_URL, "cgu"].join("/") MENTIONS_LEGALES_URL = [CGU_URL, "4.-mentions-legales"].join("#") -FAQ_URL = "http://demarches-simplifiees.helpscoutdocs.com/" +FAQ_URL = "https://faq.demarches-simplifiees.fr" From 5757782d29511c670ff04b6da8a772e0599e5345 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 22 May 2018 17:28:17 +0200 Subject: [PATCH 32/41] Fix the mentions legales link --- config/initializers/constants.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 2a942a275..a1408744f 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -1,6 +1,6 @@ DOC_URL = "https://doc.demarches-simplifiees.fr" LISTE_DES_DEMARCHES_URL = [DOC_URL, "listes-des-demarches"].join("/") CGU_URL = [DOC_URL, "cgu"].join("/") -MENTIONS_LEGALES_URL = [CGU_URL, "4.-mentions-legales"].join("#") +MENTIONS_LEGALES_URL = [CGU_URL, "4-mentions-legales"].join("#") FAQ_URL = "https://faq.demarches-simplifiees.fr" From 0b35bfffa53e0ea37160984c8e8a5e2d68a193ba Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 22 May 2018 17:35:11 +0200 Subject: [PATCH 33/41] Move constants to urls.rb --- config/initializers/constants.rb | 6 ------ config/initializers/urls.rb | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 config/initializers/constants.rb diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb deleted file mode 100644 index a1408744f..000000000 --- a/config/initializers/constants.rb +++ /dev/null @@ -1,6 +0,0 @@ -DOC_URL = "https://doc.demarches-simplifiees.fr" -LISTE_DES_DEMARCHES_URL = [DOC_URL, "listes-des-demarches"].join("/") -CGU_URL = [DOC_URL, "cgu"].join("/") -MENTIONS_LEGALES_URL = [CGU_URL, "4-mentions-legales"].join("#") - -FAQ_URL = "https://faq.demarches-simplifiees.fr" diff --git a/config/initializers/urls.rb b/config/initializers/urls.rb index 7d9eb1124..82bdcf98f 100644 --- a/config/initializers/urls.rb +++ b/config/initializers/urls.rb @@ -1,3 +1,10 @@ API_ENTREPRISE_URL = 'https://entreprise.api.gouv.fr/v2' PIPEDRIVE_API_URL = 'https://api.pipedrive.com/v1' + +DOC_URL = "https://doc.demarches-simplifiees.fr" +LISTE_DES_DEMARCHES_URL = [DOC_URL, "listes-des-demarches"].join("/") +CGU_URL = [DOC_URL, "cgu"].join("/") +MENTIONS_LEGALES_URL = [CGU_URL, "4-mentions-legales"].join("#") + +FAQ_URL = "https://faq.demarches-simplifiees.fr" From 785fe3410e3b49bef726537bdc0b40d4f93f2c2c Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 26 Apr 2018 14:36:27 +0200 Subject: [PATCH 34/41] Clone procedure notice --- app/controllers/application_controller.rb | 5 +++++ app/models/procedure.rb | 10 ++++++++++ spec/controllers/admin/procedures_controller_spec.rb | 10 ++++++++-- spec/factories/procedure.rb | 9 +++++++++ spec/spec_helper.rb | 3 +++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4db6b6ab2..4acf4caa2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,6 +10,7 @@ class ApplicationController < ActionController::Base before_action :reject, if: -> { Flipflop.maintenance_mode? } before_action :staging_authenticate + before_action :set_active_storage_host def staging_authenticate if StagingAuthService.enabled? && !authenticate_with_http_basic { |username, password| StagingAuthService.authenticate(username, password) } @@ -57,6 +58,10 @@ class ApplicationController < ActionController::Base private + def set_active_storage_host + ActiveStorage::Current.host = request.base_url + end + def logged_users @logged_users ||= [ current_user, diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 0dda498e1..1a6e41566 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -135,6 +135,16 @@ class Procedure < ApplicationRecord procedure.logo_secure_token = nil procedure.remote_logo_url = self.logo_url + if notice.attached? + response = Typhoeus.get(notice.service_url, timeout: 5) + if response.success? + procedure.notice.attach( + io: StringIO.new(response.body), + filename: notice.filename + ) + end + end + procedure.administrateur = admin procedure.initiated_mail = initiated_mail.try(:dup) procedure.received_mail = received_mail.try(:dup) diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index ac665c5ab..c21a9ae00 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -455,10 +455,15 @@ describe Admin::ProceduresController, type: :controller do end describe 'PUT #clone' do - let!(:procedure) { create(:procedure, administrateur: admin) } + let!(:procedure) { create(:procedure, :with_notice, administrateur: admin) } let(:params) { { procedure_id: procedure.id } } subject { put :clone, params: params } + before do + response = Typhoeus::Response.new(code: 200, body: 'Hello world') + Typhoeus.stub(/active_storage\/disk/).and_return(response) + end + it { expect { subject }.to change(Procedure, :count).by(1) } context 'when admin is the owner of the procedure' do @@ -466,7 +471,8 @@ describe Admin::ProceduresController, type: :controller do it 'creates a new procedure and redirect to it' do expect(response).to redirect_to edit_admin_procedure_path(id: Procedure.last.id) - expect(Procedure.last.cloned_from_library).to be(false) + expect(Procedure.last.cloned_from_library).to be_falsey + expect(Procedure.last.notice.attached?).to be_truthy expect(flash[:notice]).to have_content 'Procédure clonée' end diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index e8b73a57e..a48a054c8 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -111,6 +111,15 @@ FactoryBot.define do end end + trait :with_notice do + after(:create) do |procedure, _evaluator| + procedure.notice.attach( + io: StringIO.new('Hello World'), + filename: 'hello.txt' + ) + end + end + trait :with_all_champs_mandatory do after(:build) do |procedure, _evaluator| tdcs = [] diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e17a971ae..f73820cc5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -64,6 +64,7 @@ VCR.configure do |c| c.hook_into :webmock c.cassette_library_dir = 'spec/fixtures/cassettes' c.configure_rspec_metadata! + c.ignore_hosts 'test.host' end DatabaseCleaner.strategy = :transaction @@ -119,6 +120,8 @@ RSpec.configure do |config| config.before(:all) { Warden.test_mode! + Typhoeus::Expectation.clear + if Flipflop.remote_storage? VCR.use_cassette("ovh_storage_init") do CarrierWave.configure do |config| From 678baaf3624808a822c3217a6cfc78b63d89d7ff Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Tue, 22 May 2018 18:35:23 +0200 Subject: [PATCH 35/41] Unroll loop with ifs --- .../admin/procedures/_informations.html.haml | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index 314a454ef..eeadb6cb3 100644 --- a/app/views/admin/procedures/_informations.html.haml +++ b/app/views/admin/procedures/_informations.html.haml @@ -2,19 +2,24 @@ .alert.alert-info Cette procédure est publiée, certains éléments de la description ne sont plus modifiables -- { libelle: 'Libellé*', description: 'Description*', lien_site_web: 'Lien site internet', web_hook_url: 'Lien de rappel HTTP' }.each do |key, value| - - if key != :web_hook_url || Flipflop.web_hook? - .form-group - %h4 - = value - - if key == :web_hook_url - %p - Un lien de rappel HTTP (aussi appelé webhook) est utilisé pour notifier un service tiers du changement de l'état d’un dossier sur demarches-simplifiees.fr. À chaque changement d’état d'un dossier, notre site va effectuer une requête sur le lien renseigné avec en paramètres : le nouvel état du dossier, l’identifiant de la procédure, l'identifiant dossier et la date du changement. Vous pourrez alors utiliser notre API pour récupérer les nouvelles informations du dossier concerné. - - if key == :description - = f.text_area key, rows: '6', placeholder: 'Description du projet', class: 'form-control' +.form-group + %h4 Libellé* + = f.text_field :libelle, class: 'form-control', placeholder: 'Libellé de la procédure' - - else - = f.text_field key, class: 'form-control', placeholder: value +.form-group + %h4 Description* + = f.text_area :description, rows: '6', placeholder: 'Description du projet', class: 'form-control' + +.form-group + %h4 Lien site internet + = f.text_field :lien_site_web, class: 'form-control', placeholder: 'https://www.exemple.fr/' + +- if Flipflop.web_hook? + .form-group + %h4 Lien de rappel HTTP + %p + Un lien de rappel HTTP (aussi appelé webhook) est utilisé pour notifier un service tiers du changement de l'état d’un dossier sur demarches-simplifiees.fr. À chaque changement d’état d'un dossier, notre site va effectuer une requête sur le lien renseigné avec en paramètres : le nouvel état du dossier, l’identifiant de la procédure, l'identifiant dossier et la date du changement. Vous pourrez alors utiliser notre API pour récupérer les nouvelles informations du dossier concerné. + = f.text_field :web_hook_url, class: 'form-control', placeholder: 'https://callback.exemple.fr/' .form-group %h4 Notice explicative de la procédure From 1839269dd9533d5ca1eab010735e6ba9e4ce5bc4 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 22 May 2018 17:38:33 +0200 Subject: [PATCH 36/41] Add API_CARTO_URL --- app/lib/carto/sgmap/api.rb | 12 ++++-------- config/initializers/urls.rb | 2 ++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/lib/carto/sgmap/api.rb b/app/lib/carto/sgmap/api.rb index 9ab7a9d9e..e084caebd 100644 --- a/app/lib/carto/sgmap/api.rb +++ b/app/lib/carto/sgmap/api.rb @@ -3,13 +3,13 @@ class CARTO::SGMAP::API end def self.search_qp(geojson) - endpoint = "/quartiers-prioritaires/search" - call(base_url + endpoint, { geojson: geojson.to_s }) + url = [API_CARTO_URL, "quartiers-prioritaires", "search"].join("/") + call(url, { geojson: geojson.to_s }) end def self.search_cadastre(geojson) - endpoint = "/cadastre/geometrie" - call(base_url + endpoint, { geojson: geojson.to_s }) + url = [API_CARTO_URL, "cadastre", "geometrie"].join("/") + call(url, { geojson: geojson.to_s }) end private @@ -25,8 +25,4 @@ class CARTO::SGMAP::API rescue RestClient::InternalServerError raise RestClient::ResourceNotFound end - - def self.base_url - 'https://apicarto.sgmap.fr' - end end diff --git a/config/initializers/urls.rb b/config/initializers/urls.rb index 82bdcf98f..f9419be37 100644 --- a/config/initializers/urls.rb +++ b/config/initializers/urls.rb @@ -1,3 +1,5 @@ +API_CARTO_URL = "https://apicarto.sgmap.fr" + API_ENTREPRISE_URL = 'https://entreprise.api.gouv.fr/v2' PIPEDRIVE_API_URL = 'https://api.pipedrive.com/v1' From a246181afd2279bcf54da8ad5aca3c38805fe11c Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 22 May 2018 19:01:04 +0200 Subject: [PATCH 37/41] Add API_GEO_URL --- app/lib/carto/geo_api/driver.rb | 14 ++++---------- config/initializers/urls.rb | 2 ++ spec/lib/carto/geo_api/driver_spec.rb | 12 ------------ 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/app/lib/carto/geo_api/driver.rb b/app/lib/carto/geo_api/driver.rb index 45f664427..4ae2c38dd 100644 --- a/app/lib/carto/geo_api/driver.rb +++ b/app/lib/carto/geo_api/driver.rb @@ -2,25 +2,19 @@ module Carto module GeoAPI class Driver def self.regions - call regions_url + url = [API_GEO_URL, "regions"].join("/") + call url end def self.departements - call departements_url + url = [API_GEO_URL, "departements"].join("/") + call url end def self.pays File.open('app/lib/carto/geo_api/pays.json').read end - def self.departements_url - 'https://geo.api.gouv.fr/departements' - end - - def self.regions_url - 'https://geo.api.gouv.fr/regions' - end - private def self.call(api_url) diff --git a/config/initializers/urls.rb b/config/initializers/urls.rb index f9419be37..447f5eb63 100644 --- a/config/initializers/urls.rb +++ b/config/initializers/urls.rb @@ -2,6 +2,8 @@ API_CARTO_URL = "https://apicarto.sgmap.fr" API_ENTREPRISE_URL = 'https://entreprise.api.gouv.fr/v2' +API_GEO_URL = "https://geo.api.gouv.fr" + PIPEDRIVE_API_URL = 'https://api.pipedrive.com/v1' DOC_URL = "https://doc.demarches-simplifiees.fr" diff --git a/spec/lib/carto/geo_api/driver_spec.rb b/spec/lib/carto/geo_api/driver_spec.rb index e146e1c26..67cd7da7c 100644 --- a/spec/lib/carto/geo_api/driver_spec.rb +++ b/spec/lib/carto/geo_api/driver_spec.rb @@ -18,16 +18,4 @@ describe Carto::GeoAPI::Driver do it { is_expected.to eq File.open('app/lib/carto/geo_api/pays.json').read } end - - describe '.departements_url' do - subject { described_class.departements_url } - - it { is_expected.to eq 'https://geo.api.gouv.fr/departements' } - end - - describe '.regions_url' do - subject { described_class.regions_url } - - it { is_expected.to eq 'https://geo.api.gouv.fr/regions' } - end end From 44754418f8a59452d717194b6d734596d2d23ddf Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 22 May 2018 17:40:13 +0200 Subject: [PATCH 38/41] Add parentheses --- app/lib/carto/geo_api/driver.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/lib/carto/geo_api/driver.rb b/app/lib/carto/geo_api/driver.rb index 4ae2c38dd..8f580cf9c 100644 --- a/app/lib/carto/geo_api/driver.rb +++ b/app/lib/carto/geo_api/driver.rb @@ -3,12 +3,12 @@ module Carto class Driver def self.regions url = [API_GEO_URL, "regions"].join("/") - call url + call(url) end def self.departements url = [API_GEO_URL, "departements"].join("/") - call url + call(url) end def self.pays From 4ad3932c053e9c4596af79b5e8f7f4ed644e25fb Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 17 May 2018 15:31:45 +0200 Subject: [PATCH 39/41] Add test_procedure to procedure_path --- app/models/procedure_path.rb | 1 + .../20180516155238_add_test_procedure_to_procedure_paths.rb | 5 +++++ db/schema.rb | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20180516155238_add_test_procedure_to_procedure_paths.rb diff --git a/app/models/procedure_path.rb b/app/models/procedure_path.rb index 62dc924b3..bfe75ef04 100644 --- a/app/models/procedure_path.rb +++ b/app/models/procedure_path.rb @@ -3,6 +3,7 @@ class ProcedurePath < ApplicationRecord validates :administrateur_id, presence: true, allow_blank: false, allow_nil: false validates :procedure_id, presence: true, allow_blank: false, allow_nil: false + belongs_to :test_procedure, class_name: 'Procedure' belongs_to :procedure belongs_to :administrateur end diff --git a/db/migrate/20180516155238_add_test_procedure_to_procedure_paths.rb b/db/migrate/20180516155238_add_test_procedure_to_procedure_paths.rb new file mode 100644 index 000000000..fbc80c7d0 --- /dev/null +++ b/db/migrate/20180516155238_add_test_procedure_to_procedure_paths.rb @@ -0,0 +1,5 @@ +class AddTestProcedureToProcedurePaths < ActiveRecord::Migration[5.2] + def change + add_reference :procedure_paths, :test_procedure + end +end diff --git a/db/schema.rb b/db/schema.rb index 5b4dbd414..5cb37ac59 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: 2018_05_15_135415) do +ActiveRecord::Schema.define(version: 2018_05_16_155238) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -425,7 +425,9 @@ ActiveRecord::Schema.define(version: 2018_05_15_135415) do t.integer "administrateur_id" t.datetime "created_at" t.datetime "updated_at" + t.bigint "test_procedure_id" t.index ["path"], name: "index_procedure_paths_on_path" + t.index ["test_procedure_id"], name: "index_procedure_paths_on_test_procedure_id" end create_table "procedure_presentations", id: :serial, force: :cascade do |t| From ffef1a644cfa38e5e209a28a18d3b909c4db5f3b Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 17 May 2018 15:32:36 +0200 Subject: [PATCH 40/41] procedure_path should check for test and regular procedure --- app/dashboards/procedure_dashboard.rb | 1 - app/models/procedure.rb | 6 ++++-- app/models/procedure_path.rb | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/dashboards/procedure_dashboard.rb b/app/dashboards/procedure_dashboard.rb index 87eff4600..dc7c3681d 100644 --- a/app/dashboards/procedure_dashboard.rb +++ b/app/dashboards/procedure_dashboard.rb @@ -12,7 +12,6 @@ class ProcedureDashboard < Administrate::BaseDashboard types_de_champ: TypesDeChampCollectionField, path: ProcedureLinkField, dossiers: Field::HasMany, - procedure_path: Field::HasOne, administrateur: Field::BelongsTo, id: Field::Number, libelle: Field::String, diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 1a6e41566..bae4d72f3 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -4,8 +4,6 @@ class Procedure < ApplicationRecord has_many :types_de_champ_private, -> { private_only }, class_name: 'TypeDeChamp', dependent: :destroy has_many :dossiers - has_one :procedure_path, dependent: :destroy - has_one :module_api_carto, dependent: :destroy has_one :attestation_template, dependent: :destroy @@ -61,6 +59,10 @@ class Procedure < ApplicationRecord Dossier.new(procedure: self, champs: champs, champs_private: champs_private) end + def procedure_path + ProcedurePath.find_with_procedure(self) + end + def hide! now = DateTime.now self.update(hidden_at: now, aasm_state: :hidden) diff --git a/app/models/procedure_path.rb b/app/models/procedure_path.rb index bfe75ef04..5b6ca20c2 100644 --- a/app/models/procedure_path.rb +++ b/app/models/procedure_path.rb @@ -6,4 +6,8 @@ class ProcedurePath < ApplicationRecord belongs_to :test_procedure, class_name: 'Procedure' belongs_to :procedure belongs_to :administrateur + + def self.find_with_procedure(procedure) + where(procedure: procedure).or(where(test_procedure: procedure)).last + end end From 94d253c6dc0669f3b07d81586588c9380c707f8c Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 17 May 2018 15:34:51 +0200 Subject: [PATCH 41/41] Add commencer/test/:procedure_path route --- .../admin/procedures_controller.rb | 5 --- app/controllers/users/dossiers_controller.rb | 40 +++++++++++-------- app/models/procedure.rb | 5 ++- app/models/procedure_path.rb | 12 ++++++ config/routes.rb | 1 + .../admin/procedures_controller_spec.rb | 12 +++--- 6 files changed, 45 insertions(+), 30 deletions(-) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index fa948bc78..c75f7aafd 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -63,11 +63,6 @@ class Admin::ProceduresController < AdminController def hide procedure = current_administrateur.procedures.find(params[:id]) procedure.hide! - # procedure should no longer be reachable so we delete its procedure_path - # that way it is also available for another procedure - # however, sometimes the path has already been deleted (ex: stolen by another procedure), - # so we're not certain the procedure has a procedure_path anymore - procedure.procedure_path.try(:destroy) flash.notice = "Procédure supprimée, en cas d'erreur contactez nous : contact@demarches-simplifiees.fr" redirect_to admin_procedures_draft_path diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index f02b3b992..4c30d3344 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -41,28 +41,34 @@ class Users::DossiersController < UsersController array: true end + def commencer_test + procedure_path = ProcedurePath.find_by(path: params[:procedure_path]) + procedure = procedure_path.test_procedure + + if procedure.present? + redirect_to new_users_dossier_path(procedure_id: procedure.id) + else + flash.alert = "Procédure inconnue" + redirect_to root_path + end + end + def commencer - if params[:procedure_path].present? - procedure_path = ProcedurePath.where(path: params[:procedure_path]).last + procedure_path = ProcedurePath.find_by(path: params[:procedure_path]) + procedure = procedure_path.procedure - if procedure_path.nil? || procedure_path.procedure.nil? - flash.alert = "Procédure inconnue" - return redirect_to root_path + if procedure.present? + if procedure.archivee? + @dossier = Dossier.new(procedure: procedure) + + render 'commencer/archived' else - procedure = procedure_path.procedure + redirect_to new_users_dossier_path(procedure_id: procedure.id) end + else + flash.alert = "Procédure inconnue" + redirect_to root_path end - - if procedure.archivee? - - @dossier = Dossier.new(procedure: procedure) - - return render 'commencer/archived' - end - - redirect_to new_users_dossier_path(procedure_id: procedure.id) - rescue ActiveRecord::RecordNotFound - error_procedure end def new diff --git a/app/models/procedure.rb b/app/models/procedure.rb index bae4d72f3..5b4dc03fc 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -65,8 +65,9 @@ class Procedure < ApplicationRecord def hide! now = DateTime.now - self.update(hidden_at: now, aasm_state: :hidden) - self.dossiers.update_all(hidden_at: now) + update(hidden_at: now, aasm_state: :hidden) + procedure_path&.hide!(self) + dossiers.update_all(hidden_at: now) end def path diff --git a/app/models/procedure_path.rb b/app/models/procedure_path.rb index 5b6ca20c2..c1cccb775 100644 --- a/app/models/procedure_path.rb +++ b/app/models/procedure_path.rb @@ -10,4 +10,16 @@ class ProcedurePath < ApplicationRecord def self.find_with_procedure(procedure) where(procedure: procedure).or(where(test_procedure: procedure)).last end + + def hide!(procedure) + if self.procedure == procedure + update(procedure: nil) + end + if self.test_procedure == procedure + update(test_procedure: nil) + end + if procedure.nil? && test_procedure.nil? + destroy + end + end end diff --git a/config/routes.rb b/config/routes.rb index 2b94d7953..2c1f00ca1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -211,6 +211,7 @@ Rails.application.routes.draw do end namespace :commencer do + get '/test/:procedure_path' => '/users/dossiers#commencer_test', as: :test get '/:procedure_path' => '/users/dossiers#commencer' end diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index c21a9ae00..77ed13327 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -547,7 +547,7 @@ describe Admin::ProceduresController, type: :controller do end end - describe 'POST transfer' do + describe 'POST #transfer' do let!(:procedure) { create :procedure, administrateur: admin } subject { post :transfer, params: { email_admin: email_admin, procedure_id: procedure.id } } @@ -587,17 +587,17 @@ describe Admin::ProceduresController, type: :controller do end end - describe "POST hide" do + describe "POST #hide" do subject { post :hide, params: { id: procedure.id } } context "when procedure is not owned by administrateur" do - let!(:procedure) { create :procedure, administrateur: create(:administrateur) } + let(:procedure) { create :procedure, administrateur: create(:administrateur) } it { expect{ subject }.to raise_error(ActiveRecord::RecordNotFound) } end context "when procedure is owned by administrateur" do - let!(:procedure) { create :procedure, :published, administrateur: admin } + let(:procedure) { create :procedure, :published, administrateur: admin } before do subject @@ -605,11 +605,11 @@ describe Admin::ProceduresController, type: :controller do end it { expect(procedure.hidden_at).not_to be_nil } - it { expect(procedure.procedure_path).to be_nil } + it { expect(procedure.procedure_path.procedure).to be_nil } end context "when procedure has no path" do - let!(:procedure) { create :procedure, administrateur: admin } + let(:procedure) { create :procedure, administrateur: admin } it { expect{ subject }.not_to raise_error } it do