2019-07-29-01 (#4149)

2019-07-29-01
This commit is contained in:
Pierre de La Morinerie 2019-07-29 16:51:08 +02:00 committed by GitHub
commit 357a886720
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 103 additions and 61 deletions

View file

@ -38,10 +38,6 @@
} }
} }
.button.edit-form {
float: right;
}
.messagerie-explanation { .messagerie-explanation {
margin-bottom: $default-padding * 2; margin-bottom: $default-padding * 2;
} }

View file

@ -107,17 +107,20 @@ class Admin::ProceduresController < AdminController
def publish def publish
path = params[:path] path = params[:path]
lien_site_web = params[:lien_site_web]
procedure = current_administrateur.procedures.find(params[:procedure_id]) procedure = current_administrateur.procedures.find(params[:procedure_id])
procedure.path = path procedure.path = path
procedure.lien_site_web = lien_site_web
if !procedure.validate if !procedure.validate
flash.alert = 'Lien de la démarche invalide' flash.alert = 'Lien de la démarche invalide ou lien vers la démarche manquant'
return redirect_to admin_procedures_path return redirect_to admin_procedures_path
else else
procedure.path = nil procedure.path = nil
end end
if procedure.publish_or_reopen!(current_administrateur, path) if procedure.publish_or_reopen!(current_administrateur, path, lien_site_web)
flash.notice = "Démarche publiée" flash.notice = "Démarche publiée"
redirect_to admin_procedures_path redirect_to admin_procedures_path
else else

View file

@ -107,12 +107,12 @@ class Procedure < ApplicationRecord
end end
end end
def publish_or_reopen!(administrateur, path) def publish_or_reopen!(administrateur, path, lien_site_web)
if archivee? && may_reopen?(administrateur, path) if archivee? && may_reopen?(administrateur, path, lien_site_web)
reopen!(administrateur, path) reopen!(administrateur, path, lien_site_web)
elsif may_publish?(administrateur, path) elsif may_publish?(administrateur, path, lien_site_web)
reset! reset!
publish!(administrateur, path) publish!(administrateur, path, lien_site_web)
end end
end end
@ -216,7 +216,7 @@ class Procedure < ApplicationRecord
types_de_champ: [:drop_down_list, types_de_champ: :drop_down_list], types_de_champ: [:drop_down_list, types_de_champ: :drop_down_list],
types_de_champ_private: [:drop_down_list, types_de_champ: :drop_down_list] types_de_champ_private: [:drop_down_list, types_de_champ: :drop_down_list]
}, &method(:clone_attachments)) }, &method(:clone_attachments))
procedure.path = nil procedure.path = SecureRandom.uuid
procedure.aasm_state = :brouillon procedure.aasm_state = :brouillon
procedure.test_started_at = nil procedure.test_started_at = nil
procedure.archived_at = nil procedure.archived_at = nil
@ -488,33 +488,29 @@ class Procedure < ApplicationRecord
update!(path: path) update!(path: path)
end end
def can_publish?(administrateur, path) def can_publish?(administrateur, path, lien_site_web)
path_availability(administrateur, path).in?(PATH_CAN_PUBLISH) path_availability(administrateur, path).in?(PATH_CAN_PUBLISH) && lien_site_web.present?
end end
def can_reopen?(administrateur, path) def after_publish(administrateur, path, lien_site_web)
path_availability(administrateur, path).in?(PATH_CAN_PUBLISH)
end
def after_publish(administrateur, path)
update!(published_at: Time.zone.now) update!(published_at: Time.zone.now)
claim_path_ownership!(path) claim_path_ownership!(path)
end end
def after_reopen(administrateur, path) def after_reopen(administrateur, path, lien_site_web)
update!(published_at: Time.zone.now, archived_at: nil) update!(published_at: Time.zone.now, archived_at: nil)
claim_path_ownership!(path) claim_path_ownership!(path)
end end
def after_archive def after_archive
update!(archived_at: Time.zone.now, path: nil) update!(archived_at: Time.zone.now, path: SecureRandom.uuid)
end end
def after_hide def after_hide
now = Time.zone.now now = Time.zone.now
update!(hidden_at: now, path: nil) update!(hidden_at: now, path: SecureRandom.uuid)
dossiers.update_all(hidden_at: now) dossiers.update_all(hidden_at: now)
end end

View file

@ -19,7 +19,8 @@
= f.label :duree_conservation_dossiers_hors_ds, "Hors demarches-simplifiees.fr* (durée en mois après la fin de l'instruction)" = f.label :duree_conservation_dossiers_hors_ds, "Hors demarches-simplifiees.fr* (durée en mois après la fin de l'instruction)"
= f.number_field :duree_conservation_dossiers_hors_ds, class: 'form-control', placeholder: '6', required: true = f.number_field :duree_conservation_dossiers_hors_ds, class: 'form-control', placeholder: '6', required: true
.form-group - if @procedure.created_at.present?
.form-group
%h4 Où les usagers trouveront-ils le lien vers la démarche ? %h4 Où les usagers trouveront-ils le lien vers la démarche ?
= f.text_field :lien_site_web, class: 'form-control', placeholder: 'https://exemple.gouv.fr/ma_demarche' = f.text_field :lien_site_web, class: 'form-control', placeholder: 'https://exemple.gouv.fr/ma_demarche'

View file

@ -38,6 +38,14 @@
"https://vimeo.com/334463514", "https://vimeo.com/334463514",
target: "_blank" target: "_blank"
.form-group
%h4 Où les usagers trouveront-ils le lien vers cette démarche ? *
%p.center
= text_field_tag(:lien_site_web, @procedure.lien_site_web,
required: true,
class: 'form-control',
placeholder: 'https://exemple.gouv.fr/ma_demarche')
#path-messages #path-messages
#path_is_mine.text-warning.center.message #path_is_mine.text-warning.center.message
Ce lien est déjà utilisé par une de vos démarche. Ce lien est déjà utilisé par une de vos démarche.

View file

@ -1,4 +1,4 @@
%span.dropdown.invite-user-action{ :style => "float:right;right: 10px;" } %span.dropdown.invite-user-action
%button.button.dropdown-button %button.button.dropdown-button
%span.icon.person %span.icon.person
- if dossier.invites.count > 0 - if dossier.invites.count > 0

View file

@ -15,6 +15,7 @@
Les champs avec un astérisque ( Les champs avec un astérisque (
%span.mandatory> * %span.mandatory> *
) sont obligatoires. ) sont obligatoires.
- if dossier.brouillon?
%p.mandatory-explanation %p.mandatory-explanation
Pour enregistrer votre dossier et le reprendre plus tard, cliquez sur le bouton « Enregistrer le brouillon » en bas à gauche du formulaire. Pour enregistrer votre dossier et le reprendre plus tard, cliquez sur le bouton « Enregistrer le brouillon » en bas à gauche du formulaire.

View file

@ -11,9 +11,10 @@
= "- Déposé le #{l(dossier.en_construction_at, format: '%d %B %Y')}" = "- Déposé le #{l(dossier.en_construction_at, format: '%d %B %Y')}"
- if current_user.owns?(dossier) - if current_user.owns?(dossier)
= link_to "Modifier mon dossier", modifier_dossier_path(dossier.id), class: 'button accepted edit-form', 'title'=> "Vous pouvez modifier votre dossier tant qu'il n'est passé en instruction" .header-actions
= render partial: 'invites/dropdown', locals: { dossier: dossier } = render partial: 'invites/dropdown', locals: { dossier: dossier }
.clearfix - if dossier.can_be_updated_by_user? && !current_page?(modifier_dossier_path(dossier))
= link_to "Modifier mon dossier", modifier_dossier_path(dossier), class: 'button accepted edit-form', 'title'=> "Vous pouvez modifier votre dossier tant qu'il n'est passé en instruction"
%ul.tabs %ul.tabs
= dynamic_tab_item('Résumé', dossier_path(dossier)) = dynamic_tab_item('Résumé', dossier_path(dossier))

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_07_17_132452) do ActiveRecord::Schema.define(version: 2019_07_17_151228) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -430,6 +430,7 @@ ActiveRecord::Schema.define(version: 2019_07_17_132452) do
t.integer "user_id" t.integer "user_id"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.text "message"
end end
create_table "module_api_cartos", id: :serial, force: :cascade do |t| create_table "module_api_cartos", id: :serial, force: :cascade do |t|

View file

@ -0,0 +1,18 @@
namespace :after_party do
desc 'Deployment task: create_dummy_paths_for_archived_and_hidden_procedures'
task create_dummy_paths_for_archived_and_hidden_procedures: :environment do
puts "Running deploy task 'create_dummy_paths_for_archived_procedures'"
Procedure.unscoped.archivees.where(path: nil).each do |p|
p.update_column(:path, SecureRandom.uuid)
end
Procedure.unscoped.hidden.where(path: nil).each do |p|
p.update_column(:path, SecureRandom.uuid)
end
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord.create version: '20190704133852'
end
end

View file

@ -15,6 +15,7 @@ describe Admin::ProceduresController, type: :controller do
let(:duree_conservation_dossiers_dans_ds) { 3 } let(:duree_conservation_dossiers_dans_ds) { 3 }
let(:duree_conservation_dossiers_hors_ds) { 6 } let(:duree_conservation_dossiers_hors_ds) { 6 }
let(:monavis_embed) { nil } let(:monavis_embed) { nil }
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
let(:procedure_params) { let(:procedure_params) {
{ {
@ -26,7 +27,8 @@ describe Admin::ProceduresController, type: :controller do
cadre_juridique: cadre_juridique, cadre_juridique: cadre_juridique,
duree_conservation_dossiers_dans_ds: duree_conservation_dossiers_dans_ds, duree_conservation_dossiers_dans_ds: duree_conservation_dossiers_dans_ds,
duree_conservation_dossiers_hors_ds: duree_conservation_dossiers_hors_ds, duree_conservation_dossiers_hors_ds: duree_conservation_dossiers_hors_ds,
monavis_embed: monavis_embed monavis_embed: monavis_embed,
lien_site_web: lien_site_web
} }
} }
@ -331,23 +333,26 @@ describe Admin::ProceduresController, type: :controller do
end end
describe 'PUT #publish' do describe 'PUT #publish' do
let(:procedure) { create(:procedure, administrateur: admin) } let(:procedure) { create(:procedure, administrateur: admin, lien_site_web: lien_site_web) }
let(:procedure2) { create(:procedure, :published, administrateur: admin) } let(:procedure2) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) }
let(:procedure3) { create(:procedure, :published) } let(:procedure3) { create(:procedure, :published, lien_site_web: lien_site_web) }
let(:lien_site_web) { 'http://some.administration/' }
context 'when admin is the owner of the procedure' do context 'when admin is the owner of the procedure' do
before do before do
put :publish, params: { procedure_id: procedure.id, path: path } put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web }
procedure.reload procedure.reload
procedure2.reload procedure2.reload
end end
context 'procedure path does not exist' do context 'procedure path does not exist' do
let(:path) { 'new_path' } let(:path) { 'new_path' }
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
it 'publish the given procedure' do it 'publish the given procedure' do
expect(procedure.publiee?).to be_truthy expect(procedure.publiee?).to be_truthy
expect(procedure.path).to eq(path) expect(procedure.path).to eq(path)
expect(procedure.lien_site_web).to eq(lien_site_web)
expect(response.status).to eq 302 expect(response.status).to eq 302
expect(flash[:notice]).to have_content 'Démarche publiée' expect(flash[:notice]).to have_content 'Démarche publiée'
end end
@ -355,26 +360,29 @@ describe Admin::ProceduresController, type: :controller do
context 'procedure path exists and is owned by current administrator' do context 'procedure path exists and is owned by current administrator' do
let(:path) { procedure2.path } let(:path) { procedure2.path }
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
it 'publish the given procedure' do it 'publish the given procedure' do
expect(procedure.publiee?).to be_truthy expect(procedure.publiee?).to be_truthy
expect(procedure.path).to eq(path) expect(procedure.path).to eq(path)
expect(procedure.lien_site_web).to eq(lien_site_web)
expect(response.status).to eq 302 expect(response.status).to eq 302
expect(flash[:notice]).to have_content 'Démarche publiée' expect(flash[:notice]).to have_content 'Démarche publiée'
end end
it 'archive previous procedure' do it 'archive previous procedure' do
expect(procedure2.archivee?).to be_truthy expect(procedure2.archivee?).to be_truthy
expect(procedure2.path).to be_nil
end end
end end
context 'procedure path exists and is not owned by current administrator' do context 'procedure path exists and is not owned by current administrator' do
let(:path) { procedure3.path } let(:path) { procedure3.path }
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
it 'does not publish the given procedure' do it 'does not publish the given procedure' do
expect(procedure.publiee?).to be_falsey expect(procedure.publiee?).to be_falsey
expect(procedure.path).not_to match(path) expect(procedure.path).not_to match(path)
expect(procedure.lien_site_web).to match(lien_site_web)
expect(response.status).to eq 200 expect(response.status).to eq 200
end end
@ -387,10 +395,12 @@ describe Admin::ProceduresController, type: :controller do
context 'procedure path is invalid' do context 'procedure path is invalid' do
let(:path) { 'Invalid Procedure Path' } let(:path) { 'Invalid Procedure Path' }
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
it 'does not publish the given procedure' do it 'does not publish the given procedure' do
expect(procedure.publiee?).to be_falsey expect(procedure.publiee?).to be_falsey
expect(procedure.path).not_to match(path) expect(procedure.path).not_to match(path)
expect(procedure.lien_site_web).to match(lien_site_web)
expect(response).to redirect_to :admin_procedures expect(response).to redirect_to :admin_procedures
expect(flash[:alert]).to have_content 'Lien de la démarche invalide' expect(flash[:alert]).to have_content 'Lien de la démarche invalide'
end end
@ -413,10 +423,25 @@ describe Admin::ProceduresController, type: :controller do
expect(flash[:alert]).to have_content 'Démarche inexistante' expect(flash[:alert]).to have_content 'Démarche inexistante'
end end
end end
context 'when the admin does not provide a lien_site_web' do
before do
put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web }
procedure.reload
end
context 'procedure path is valid but lien_site_web is missing' do
let(:path) { 'new_path2' }
let(:lien_site_web) { nil }
it 'does not publish the given procedure' do
expect(procedure.publiee?).to be_falsey
end
end
end
end end
describe 'PUT #archive' do describe 'PUT #archive' do
let(:procedure) { create(:procedure, :published, administrateur: admin) } let(:procedure) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) }
context 'when admin is the owner of the procedure' do context 'when admin is the owner of the procedure' do
before do before do
@ -432,7 +457,7 @@ describe Admin::ProceduresController, type: :controller do
context 'when owner want to re-enable procedure' do context 'when owner want to re-enable procedure' do
before do before do
put :publish, params: { procedure_id: procedure.id, path: 'fake_path' } put :publish, params: { procedure_id: procedure.id, path: 'fake_path', lien_site_web: lien_site_web }
procedure.reload procedure.reload
end end

View file

@ -10,6 +10,7 @@ FactoryBot.define do
duree_conservation_dossiers_dans_ds { 3 } duree_conservation_dossiers_dans_ds { 3 }
duree_conservation_dossiers_hors_ds { 6 } duree_conservation_dossiers_hors_ds { 6 }
ask_birthday { false } ask_birthday { false }
lien_site_web { "https://mon-site.gouv" }
transient do transient do
administrateur {} administrateur {}
@ -37,7 +38,7 @@ FactoryBot.define do
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
procedure.for_individual = true procedure.for_individual = true
procedure.types_de_champ << create(:type_de_champ, libelle: 'Texte obligatoire', mandatory: true) procedure.types_de_champ << create(:type_de_champ, libelle: 'Texte obligatoire', mandatory: true)
procedure.publish!(procedure.administrateurs.first, generate(:published_path)) procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web)
end end
end end
@ -147,13 +148,13 @@ FactoryBot.define do
trait :published do trait :published do
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
procedure.publish!(procedure.administrateurs.first, generate(:published_path)) procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web)
end end
end end
trait :archived do trait :archived do
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
procedure.publish!(procedure.administrateurs.first, generate(:published_path)) procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web)
procedure.archive! procedure.archive!
end end
end end
@ -162,14 +163,14 @@ FactoryBot.define do
# For now the behavior is the same than :archived # For now the behavior is the same than :archived
# (it may be different in the future though) # (it may be different in the future though)
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
procedure.publish!(procedure.administrateurs.first, generate(:published_path)) procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web)
procedure.archive! procedure.archive!
end end
end end
trait :hidden do trait :hidden do
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
procedure.publish!(procedure.administrateurs.first, generate(:published_path)) procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web)
procedure.hide! procedure.hide!
end end
end end

View file

@ -123,6 +123,7 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
within '#publish-modal' do within '#publish-modal' do
expect(page).to have_field('procedure_path') expect(page).to have_field('procedure_path')
fill_in 'lien_site_web', with: 'http://some.website'
click_on 'publish' click_on 'publish'
end end

View file

@ -554,7 +554,7 @@ describe Procedure do
before do before do
Timecop.freeze(now) Timecop.freeze(now)
procedure.publish!(procedure.administrateurs.first, "example-path") procedure.publish!(procedure.administrateurs.first, "example-path", procedure.lien_site_web)
end end
after { Timecop.return } after { Timecop.return }
@ -690,21 +690,11 @@ describe Procedure do
subject { procedure.export_filename(:csv) } subject { procedure.export_filename(:csv) }
context "with a path" do
let(:procedure) { create(:procedure, :published) } let(:procedure) { create(:procedure, :published) }
it { is_expected.to eq("dossiers_#{procedure.path}_2018-01-02_23-11.csv") } it { is_expected.to eq("dossiers_#{procedure.path}_2018-01-02_23-11.csv") }
end end
context "without a path" do
let(:procedure) { create(:procedure, :archived) }
it do
is_expected.to eq("dossiers_procedure-#{procedure.id}_2018-01-02_23-11.csv")
end
end
end
describe '#new_dossier' do describe '#new_dossier' do
let(:procedure) do let(:procedure) do
procedure = create(:procedure) procedure = create(:procedure)

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe 'admin/procedures/edit.html.haml', type: :view, vcr: { cassette_name: 'admin_procedure_edit' } do describe 'admin/procedures/edit.html.haml', type: :view, vcr: { cassette_name: 'admin_procedure_edit' } do
let(:logo) { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') } let(:logo) { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') }
let(:procedure) { create(:procedure, logo: logo) } let(:procedure) { create(:procedure, logo: logo, lien_site_web: 'http://some.website') }
before do before do
assign(:procedure, procedure) assign(:procedure, procedure)

View file

@ -41,7 +41,7 @@ describe 'admin/procedures/show.html.haml', type: :view do
describe 'procedure is published' do describe 'procedure is published' do
before do before do
procedure.publish!(procedure.administrateurs.first, 'fake_path') procedure.publish!(procedure.administrateurs.first, 'fake_path', procedure.lien_site_web)
procedure.reload procedure.reload
render render
end end
@ -59,7 +59,7 @@ describe 'admin/procedures/show.html.haml', type: :view do
describe 'procedure is archived' do describe 'procedure is archived' do
before do before do
procedure.publish!(procedure.administrateurs.first, 'fake_path') procedure.publish!(procedure.administrateurs.first, 'fake_path', procedure.lien_site_web)
procedure.archive! procedure.archive!
procedure.reload procedure.reload
render render