Merge pull request #7211 from betagouv/main

2022-04-28-02
This commit is contained in:
Paul Chavard 2022-04-28 15:12:08 +02:00 committed by GitHub
commit bf89cf6490
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 94 additions and 61 deletions

View file

@ -23,7 +23,6 @@ gem 'delayed_cron_job' # Cron jobs
gem 'delayed_job_active_record'
gem 'delayed_job_web', '>= 1.4.4'
gem 'devise' # Gestion des comptes utilisateurs
gem 'devise-async'
gem 'devise-i18n'
gem 'devise-two-factor'
gem 'discard'

View file

@ -200,9 +200,6 @@ GEM
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
devise-async (1.0.0)
activejob (>= 5.0)
devise (>= 4.0)
devise-i18n (1.9.2)
devise (>= 4.7.1)
devise-two-factor (4.0.2)
@ -820,7 +817,6 @@ DEPENDENCIES
delayed_job_active_record
delayed_job_web (>= 1.4.4)
devise
devise-async
devise-i18n
devise-two-factor
discard

View file

@ -44,7 +44,7 @@ module Administrateurs
end
def apercu
@dossier = procedure_without_control.draft_revision.new_dossier
@dossier = procedure_without_control.draft_revision.dossier_for_preview(current_user)
@tab = apercu_tab
end

View file

@ -45,11 +45,9 @@ class Champs::SiretController < ApplicationController
end
def find_etablisement
if params[:champ_id].present?
@champ = policy_scope(Champ).find(params[:champ_id])
@etablissement = @champ&.etablissement
end
@procedure_id = @champ&.dossier&.procedure&.id || 'aperçu'
@champ = policy_scope(Champ).find(params[:champ_id])
@etablissement = @champ.etablissement
@procedure_id = @champ.dossier.procedure.id
end
def find_etablissement_with_siret
@ -57,7 +55,7 @@ class Champs::SiretController < ApplicationController
end
def clear_siret_and_etablissement
@champ&.update!(value: '')
@champ.update!(value: '')
@etablissement&.destroy
end

View file

@ -84,8 +84,8 @@ module Users
def generate_empty_pdf(revision)
@dossier = revision.new_dossier
s = render_to_string(template: 'dossiers/dossier_vide', formats: [:pdf])
send_data(s, :filename => "#{revision.procedure.libelle}.pdf")
data = render_to_string(template: 'dossiers/dossier_vide', formats: [:pdf])
send_data(data, filename: "#{revision.procedure.libelle}.pdf")
end
end
end

View file

@ -62,7 +62,7 @@ module ApplicationHelper
def render_champ(champ)
champ_selector = "##{champ.input_group_id}"
form_html = render 'shared/dossiers/edit', dossier: champ.dossier, apercu: false
form_html = render 'shared/dossiers/edit', dossier: champ.dossier
champ_html = Nokogiri::HTML.fragment(form_html).at_css(champ_selector).to_s
# rubocop:disable Rails/OutputSafety
raw("document.querySelector('#{champ_selector}').outerHTML = \"#{escape_javascript(champ_html)}\";")

View file

@ -23,7 +23,7 @@ export type DeleteFeatures = (params: {
export function useFeatureCollection(
initialFeatureCollection: FeatureCollection,
{ url, enabled = true }: { url: string; enabled: boolean }
{ url }: { url: string }
) {
const [error, onError] = useError();
const [featureCollection, setFeatureCollection] = useState(
@ -96,9 +96,6 @@ export function useFeatureCollection(
source = SOURCE_SELECTION_UTILISATEUR,
external = false
}) => {
if (!enabled) {
return;
}
try {
const newFeatures: Feature[] = [];
for (const feature of features) {
@ -117,7 +114,7 @@ export function useFeatureCollection(
onError('Le polygone dessiné nest pas valide.');
}
},
[enabled, url, updateFeatureCollection, addFeatures, onError]
[url, updateFeatureCollection, addFeatures, onError]
);
const updateFeatures = useCallback<UpdateFatures>(
@ -126,9 +123,6 @@ export function useFeatureCollection(
source = SOURCE_SELECTION_UTILISATEUR,
external = false
}) => {
if (!enabled) {
return;
}
try {
const newFeatures: Feature[] = [];
for (const feature of features) {
@ -154,14 +148,11 @@ export function useFeatureCollection(
onError('Le polygone dessiné nest pas valide.');
}
},
[enabled, url, updateFeatureCollection, addFeatures, onError]
[url, updateFeatureCollection, addFeatures, onError]
);
const deleteFeatures = useCallback<DeleteFeatures>(
async ({ features, external = false }) => {
if (!enabled) {
return;
}
try {
const deletedFeatures = [];
for (const feature of features) {
@ -183,7 +174,7 @@ export function useFeatureCollection(
onError('Le polygone na pas pu être supprimé.');
}
},
[enabled, url, updateFeatureCollection, removeFeatures, onError]
[url, updateFeatureCollection, removeFeatures, onError]
);
return {

View file

@ -16,19 +16,17 @@ import { FlashMessage } from '../shared/FlashMessage';
export default function MapEditor({
featureCollection: initialFeatureCollection,
url,
options,
preview
options
}: {
featureCollection: FeatureCollection;
url: string;
preview: boolean;
options: { layers: string[] };
}) {
const [cadastreEnabled, setCadastreEnabled] = useState(false);
const { featureCollection, error, ...actions } = useFeatureCollection(
initialFeatureCollection,
{ url, enabled: !preview }
{ url }
);
return (
@ -54,14 +52,14 @@ export default function MapEditor({
<DrawLayer
featureCollection={featureCollection}
{...actions}
enabled={!preview && !cadastreEnabled}
enabled={!cadastreEnabled}
/>
{options.layers.includes('cadastres') ? (
<>
<CadastreLayer
featureCollection={featureCollection}
{...actions}
enabled={!preview && cadastreEnabled}
enabled={cadastreEnabled}
/>
<div className="cadastres-selection-control mapboxgl-ctrl-group">
<button

View file

@ -1,5 +1,5 @@
import { Controller } from '@hotwired/stimulus';
import React, { lazy, Suspense, FunctionComponent, StrictMode } from 'react';
import React, { lazy, Suspense, FunctionComponent } from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import invariant from 'tiny-invariant';
@ -44,12 +44,7 @@ export class ReactController extends Controller {
Component,
`Cannot find a React component with class "${componentName}"`
);
render(
<StrictMode>
<Component {...props} />
</StrictMode>,
node
);
render(<Component {...props} />, node);
}
private getComponent(componentName: string): FunctionComponent<Props> | null {

View file

@ -26,6 +26,7 @@
# last_commentaire_updated_at :datetime
# motivation :text
# private_search_terms :text
# for_procedure_preview :boolean
# processed_at :datetime
# search_terms :text
# state :string
@ -205,13 +206,14 @@ class Dossier < ApplicationRecord
scope :not_archived, -> { where(archived: false) }
scope :hidden_by_user, -> { where.not(hidden_by_user_at: nil) }
scope :hidden_by_administration, -> { where.not(hidden_by_administration_at: nil) }
scope :visible_by_user, -> { where(hidden_by_user_at: nil) }
scope :visible_by_user, -> { where(for_procedure_preview: false).or(where(for_procedure_preview: nil)).where(hidden_by_user_at: nil) }
scope :visible_by_administration, -> {
state_not_brouillon
.where(hidden_by_administration_at: nil)
.merge(visible_by_user.or(state_not_en_construction))
}
scope :visible_by_user_or_administration, -> { visible_by_user.or(visible_by_administration) }
scope :for_procedure_preview, -> { where(for_procedure_preview: true) }
scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) }
scope :order_by_created_at, -> (order = :asc) { order(depose_at: order, created_at: order, id: order) }
@ -542,7 +544,7 @@ class Dossier < ApplicationRecord
end
def can_transition_to_en_construction?
brouillon? && procedure.dossier_can_transition_to_en_construction?
brouillon? && procedure.dossier_can_transition_to_en_construction? && !for_procedure_preview?
end
def can_repasser_en_instruction?
@ -1244,7 +1246,7 @@ class Dossier < ApplicationRecord
end
def send_draft_notification_email
if brouillon? && !procedure.declarative?
if brouillon? && !procedure.declarative? && !for_procedure_preview?
DossierMailer.notify_new_draft(self).deliver_later
end
end

View file

@ -132,6 +132,19 @@ class ProcedureRevision < ApplicationRecord
)
end
def dossier_for_preview(user)
dossier = Dossier
.create_with(groupe_instructeur: procedure.defaut_groupe_instructeur_for_new_dossier)
.find_or_initialize_by(revision: self, user: user, for_procedure_preview: true, state: Dossier.states.fetch(:brouillon))
if dossier.new_record?
dossier.build_default_individual
dossier.save!
end
dossier
end
private
def compare_attestation_template(from_at, to_at)

View file

@ -27,7 +27,7 @@
class SuperAdmin < ApplicationRecord
include PasswordComplexityConcern
devise :rememberable, :trackable, :validatable, :lockable, :async, :recoverable,
devise :rememberable, :trackable, :validatable, :lockable, :recoverable,
:two_factor_authenticatable, :otp_secret_encryption_key => Rails.application.secrets.otp_secret_key
def enable_otp!
@ -58,4 +58,8 @@ class SuperAdmin < ApplicationRecord
user
end
def send_devise_notification(notification, *args)
devise_mailer.send(notification, self, *args).deliver_later
end
end

View file

@ -38,7 +38,7 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :async,
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable, :lockable
self.ignored_columns = [:administrateur_id, :instructeur_id, :expert_id]
@ -249,6 +249,10 @@ class User < ApplicationRecord
end
end
def send_devise_notification(notification, *args)
devise_mailer.send(notification, self, *args).deliver_later
end
private
def does_not_merge_on_self

View file

@ -13,7 +13,7 @@
active: @tab == 'annotations-privees')
- if @tab == 'dossier'
= render partial: "shared/dossiers/edit", locals: { dossier: @dossier, apercu: true }
= render partial: "shared/dossiers/edit", locals: { dossier: @dossier }
- else
.container
= form_for @dossier, url: '', method: :get, html: { class: 'form' } do |f|

View file

@ -185,7 +185,7 @@ prawn_document(page_size: "A4") do |pdf|
pdf.move_down(40)
render_in_2_columns(pdf, 'Démarche', @dossier.procedure.libelle)
render_in_2_columns(pdf, 'Organisme', @dossier.procedure.organisation_name)
render_in_2_columns(pdf, 'Organisme', @dossier.procedure.organisation_name || "En attente de saisi")
pdf.text "\n"
add_title(pdf, "Identité du demandeur")

View file

@ -1,7 +1,7 @@
.dossier-edit.container
= render partial: "shared/dossiers/submit_is_over", locals: { dossier: dossier }
- if apercu
- if dossier.for_procedure_preview?
- form_options = { url: '', method: :get }
- elsif dossier.brouillon?
- form_options = { url: brouillon_dossier_url(dossier), method: :patch }
@ -18,7 +18,7 @@
= t('views.shared.dossiers.edit.autosave')
- else
Pour enregistrer votre dossier et le reprendre plus tard, cliquez sur le bouton « Enregistrer le brouillon » en bas à gauche du formulaire.
- if !apercu && dossier.france_connect_information.present?
- if dossier.france_connect_information.present?
= render partial: "shared/dossiers/france_connect_informations", locals: { user_information: dossier.france_connect_information }
- if notice_url(dossier.procedure).present?
= link_to notice_url(dossier.procedure), target: '_blank', rel: 'noopener', class: 'button notice', title: "Pour vous aider à remplir votre dossier, vous pouvez consulter le guide de cette démarche." do
@ -40,7 +40,7 @@
= render partial: "shared/dossiers/editable_champs/editable_champ",
locals: { champ: champ, form: champ_form }
- if !apercu
- if !dossier.for_procedure_preview?
.dossier-edit-sticky-footer
.send-dossier-actions-bar
- if dossier.brouillon?

View file

@ -1,6 +1,4 @@
- preview = !champ.persisted?
- url = champs_carte_features_path(preview ? 'preview' : champ)
= react_component("MapEditor", { featureCollection: champ.to_feature_collection, url: url, preview: preview, options: champ.render_options }, class: "carte-#{champ.id}")
= react_component("MapEditor", { featureCollection: champ.to_feature_collection, url: champs_carte_features_path(champ), options: champ.render_options }, class: "carte-#{champ.id}")
.geo-areas
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, editing: true }

View file

@ -7,6 +7,6 @@
.dossier-container
.dossier-header.sub-header
.container
= render partial: "shared/dossiers/header", locals: { dossier: @dossier, apercu: false }
= render partial: "shared/dossiers/header", locals: { dossier: @dossier }
= render partial: "shared/dossiers/edit", locals: { dossier: @dossier, apercu: false }
= render partial: "shared/dossiers/edit", locals: { dossier: @dossier }

View file

@ -7,4 +7,4 @@
= render partial: 'users/dossiers/show/header', locals: { dossier: @dossier }
.container
= render partial: "shared/dossiers/edit", locals: { dossier: @dossier, apercu: false }
= render partial: "shared/dossiers/edit", locals: { dossier: @dossier }

View file

@ -0,0 +1,6 @@
class AddPreviewToDossiers < ActiveRecord::Migration[6.1]
def change
add_column :dossiers, :for_procedure_preview, :boolean
change_column_default :dossiers, :for_procedure_preview, false
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_04_25_140107) do
ActiveRecord::Schema.define(version: 2022_04_26_140107) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -314,6 +314,7 @@ ActiveRecord::Schema.define(version: 2022_04_25_140107) do
t.datetime "en_construction_close_to_expiration_notice_sent_at"
t.interval "en_construction_conservation_extension", default: "PT0S"
t.datetime "en_instruction_at"
t.boolean "for_procedure_preview", default: false
t.bigint "groupe_instructeur_id"
t.datetime "groupe_instructeur_updated_at"
t.datetime "hidden_at"

View file

@ -0,0 +1,16 @@
namespace :after_party do
desc 'Deployment task: set_default_for_procedure_preview_on_dossiers'
task set_default_for_procedure_preview_on_dossiers: :environment do
puts "Running deploy task 'set_default_for_procedure_preview_on_dossiers'"
Dossier
.where(for_procedure_preview: nil)
.in_batches(of: 5_000)
.update_all(for_procedure_preview: false)
# 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: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

View file

@ -23,7 +23,11 @@ describe Administrateurs::ProceduresController, type: :controller do
get :apercu, params: { id: procedure.id }
end
it { expect(response).to have_http_status(:ok) }
it do
expect(response).to have_http_status(:ok)
expect(procedure.dossiers.visible_by_user).to be_empty
expect(procedure.dossiers.for_procedure_preview).not_to be_empty
end
end
let(:procedure_params) {

View file

@ -181,15 +181,23 @@ describe Users::CommencerController, type: :controller do
end
describe '#dossier_vide_test_pdf' do
before { get :dossier_vide_pdf_test, params: { path: procedure.path } }
render_views
before { get :dossier_vide_pdf_test, params: { path: procedure.path }, format: :pdf }
context 'not published procedure' do
context 'not published procedure with service' do
let(:procedure) { create(:procedure, :with_service, :with_path) }
it 'works' do
expect(response).to have_http_status(:success)
end
end
context 'not published procedure without service' do
let(:procedure) { create(:procedure, :with_path, service: nil, organisation: nil) }
it 'works' do
expect(response).to have_http_status(:success)
end
end
context 'published procedure' do
let(:procedure) { create(:procedure, :published, :with_service, :with_path) }
it 'redirect to procedure not found' do