Merge pull request #2963 from tchak/dossier-state-serialization
Cleanup dossier state
This commit is contained in:
commit
39526f57b5
16 changed files with 140 additions and 183 deletions
|
@ -1,19 +0,0 @@
|
|||
class Admin::ChangeDossierStateController < AdminController
|
||||
def index
|
||||
@dossier = Dossier.new
|
||||
end
|
||||
|
||||
def change
|
||||
@dossier = Dossier.find(params[:dossier][:id])
|
||||
@dossier.update state: params[:next_state]
|
||||
end
|
||||
|
||||
def check
|
||||
@dossier = Dossier.find(params[:dossier][:id])
|
||||
|
||||
if @dossier.procedure.administrateur.email != current_administrateur.email
|
||||
flash.alert = 'Dossier introuvable'
|
||||
return redirect_to admin_change_dossier_state_path
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,4 @@
|
|||
class DossierDecorator < Draper::Decorator
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
delegate :current_page, :limit_value, :total_pages
|
||||
delegate_all
|
||||
|
||||
|
@ -11,12 +9,4 @@ class DossierDecorator < Draper::Decorator
|
|||
def last_update
|
||||
updated_at.strftime('%d/%m/%Y %H:%M')
|
||||
end
|
||||
|
||||
def display_state
|
||||
DossierDecorator.case_state_fr state
|
||||
end
|
||||
|
||||
def self.case_state_fr(state = self.state)
|
||||
h.t("activerecord.attributes.dossier.state.#{state}")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,4 +26,26 @@ module DossierHelper
|
|||
def dossier_submission_is_closed?(dossier)
|
||||
dossier.brouillon? && dossier.procedure.archivee?
|
||||
end
|
||||
|
||||
def dossier_display_state(dossier, lower: false)
|
||||
state = I18n.t(dossier.state, scope: [:activerecord, :attributes, :dossier, :state])
|
||||
lower ? state.downcase : state
|
||||
end
|
||||
|
||||
def dossier_legacy_state(dossier)
|
||||
case dossier.state
|
||||
when Dossier.states.fetch(:en_construction)
|
||||
'initiated'
|
||||
when Dossier.states.fetch(:en_instruction)
|
||||
'received'
|
||||
when Dossier.states.fetch(:accepte)
|
||||
'closed'
|
||||
when Dossier.states.fetch(:refuse)
|
||||
'refused'
|
||||
when Dossier.states.fetch(:sans_suite)
|
||||
'without_continuation'
|
||||
else
|
||||
dossier.state
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -245,16 +245,6 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def statut
|
||||
if accepte?
|
||||
'accepté'
|
||||
elsif sans_suite?
|
||||
'classé sans suite'
|
||||
elsif refuse?
|
||||
'refusé'
|
||||
end
|
||||
end
|
||||
|
||||
def user_geometry
|
||||
if json_latlngs.present?
|
||||
UserGeometry.new(json_latlngs)
|
||||
|
@ -308,23 +298,6 @@ class Dossier < ApplicationRecord
|
|||
DossierMailer.notify_deletion_to_user(deleted_dossier, user.email).deliver_later
|
||||
end
|
||||
|
||||
def old_state_value
|
||||
case state
|
||||
when Dossier.states.fetch(:en_construction)
|
||||
'initiated'
|
||||
when Dossier.states.fetch(:en_instruction)
|
||||
'received'
|
||||
when Dossier.states.fetch(:accepte)
|
||||
'closed'
|
||||
when Dossier.states.fetch(:refuse)
|
||||
'refused'
|
||||
when Dossier.states.fetch(:sans_suite)
|
||||
'without_continuation'
|
||||
else
|
||||
state
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_state_dates
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class DossierSerializer < ActiveModel::Serializer
|
||||
include DossierHelper
|
||||
|
||||
attributes :id,
|
||||
:created_at,
|
||||
:updated_at,
|
||||
|
@ -42,11 +44,11 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
end
|
||||
|
||||
def state
|
||||
object.old_state_value
|
||||
dossier_legacy_state(object)
|
||||
end
|
||||
|
||||
def simplified_state
|
||||
object.decorate.display_state
|
||||
dossier_display_state(object)
|
||||
end
|
||||
|
||||
def initiated_at
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class DossierTableExportSerializer < ActiveModel::Serializer
|
||||
include DossierHelper
|
||||
|
||||
attributes :id,
|
||||
:created_at,
|
||||
:updated_at,
|
||||
|
@ -22,20 +24,7 @@ class DossierTableExportSerializer < ActiveModel::Serializer
|
|||
end
|
||||
|
||||
def state
|
||||
case object.state
|
||||
when Dossier.states.fetch(:en_construction)
|
||||
'initiated'
|
||||
when Dossier.states.fetch(:en_instruction)
|
||||
'received'
|
||||
when Dossier.states.fetch(:accepte)
|
||||
'closed'
|
||||
when Dossier.states.fetch(:refuse)
|
||||
'refused'
|
||||
when Dossier.states.fetch(:sans_suite)
|
||||
'without_continuation'
|
||||
else
|
||||
object.state
|
||||
end
|
||||
dossier_legacy_state(object)
|
||||
end
|
||||
|
||||
def initiated_at
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class DossiersSerializer < ActiveModel::Serializer
|
||||
include DossierHelper
|
||||
|
||||
attributes :id,
|
||||
:updated_at,
|
||||
:initiated_at,
|
||||
|
@ -13,6 +15,6 @@ class DossiersSerializer < ActiveModel::Serializer
|
|||
end
|
||||
|
||||
def state
|
||||
object.old_state_value
|
||||
dossier_legacy_state(object)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
.center
|
||||
%h2 Outil de changement d'état d'un dossier
|
||||
|
||||
%h4.text-success
|
||||
Changement effectué
|
||||
|
||||
= form_for @dossier, url: 'change_dossier_state', action: :put do |f|
|
||||
Dossier ID :
|
||||
= @dossier.id
|
||||
%br
|
||||
État :
|
||||
= @dossier.decorate.display_state
|
||||
|
||||
%br
|
||||
%br
|
||||
= link_to 'Réaliser un autre dossier', 'change_dossier_state'
|
|
@ -1,17 +0,0 @@
|
|||
.center
|
||||
%h2 Outil de changement d'état d'un dossier
|
||||
|
||||
= form_for @dossier, url: 'change_dossier_state', action: :put do |f|
|
||||
Dossier ID :
|
||||
= @dossier.id
|
||||
= f.hidden_field :id
|
||||
%br
|
||||
État :
|
||||
= @dossier.decorate.display_state
|
||||
%br
|
||||
État souhaité :
|
||||
%select{ id: :next_state, name: :next_state }
|
||||
- Dossier.states.each do |state|
|
||||
%option{ value: state[0] }
|
||||
= DossierDecorator.case_state_fr state[1]
|
||||
= f.submit 'Valider'
|
|
@ -1,7 +0,0 @@
|
|||
.center
|
||||
%h2 Outil de changement d'état d'un dossier
|
||||
|
||||
= form_for @dossier, url: 'change_dossier_state', action: :post do |f|
|
||||
Dossier ID
|
||||
= f.text_field :id
|
||||
= f.submit 'Vérifier état'
|
|
@ -46,4 +46,4 @@
|
|||
.print-header
|
||||
= dossier.procedure.libelle.truncate_words(10)
|
||||
>
|
||||
= "Dossier nº #{dossier.id} (#{dossier.statut})"
|
||||
= "Dossier nº #{dossier.id} (#{dossier_display_state(dossier, lower: true)})"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
- if dossier.en_construction? || dossier.en_instruction?
|
||||
%span.dropdown
|
||||
%button.button.primary.dropdown-button
|
||||
= dossier.decorate.display_state
|
||||
= dossier_display_state dossier
|
||||
.dropdown-content.fade-in-down
|
||||
%ul.dropdown-items
|
||||
- if dossier.en_construction?
|
||||
|
@ -55,7 +55,7 @@
|
|||
- if dossier.motivation.present? || dossier.attestation.present?
|
||||
%span.dropdown
|
||||
%button.button.dropdown-button{ class: button_or_label_class(dossier) }
|
||||
= dossier.statut
|
||||
= dossier_display_state(dossier, lower: true)
|
||||
.dropdown-content.fade-in-down.terminated
|
||||
- if dossier.motivation.present?
|
||||
%h4 Motivation
|
||||
|
@ -67,4 +67,4 @@
|
|||
= link_to "Voir l'attestation", attestation_gestionnaire_dossier_path(dossier.procedure, dossier), target: '_blank', class: 'button'
|
||||
- else
|
||||
%span.label{ class: button_or_label_class(dossier) }
|
||||
= dossier.statut
|
||||
= dossier_display_state(dossier, lower: true)
|
||||
|
|
|
@ -173,10 +173,6 @@ Rails.application.routes.draw do
|
|||
get 'procedures/path_list' => 'procedures#path_list'
|
||||
get 'procedures/available' => 'procedures#check_availability'
|
||||
|
||||
get 'change_dossier_state' => 'change_dossier_state#index'
|
||||
post 'change_dossier_state' => 'change_dossier_state#check'
|
||||
patch 'change_dossier_state' => 'change_dossier_state#change'
|
||||
|
||||
resources :procedures do
|
||||
collection do
|
||||
get 'new_from_existing' => 'procedures#new_from_existing', as: :new_from_existing
|
||||
|
|
|
@ -18,38 +18,4 @@ describe DossierDecorator do
|
|||
subject { super().last_update }
|
||||
it { is_expected.to eq('24/12/2015 14:10') }
|
||||
end
|
||||
|
||||
describe 'state_fr' do
|
||||
subject{ super().display_state }
|
||||
|
||||
it 'brouillon is brouillon' do
|
||||
dossier.brouillon!
|
||||
expect(subject).to eq('Brouillon')
|
||||
end
|
||||
|
||||
it 'en_construction is En construction' do
|
||||
dossier.en_construction!
|
||||
expect(subject).to eq('En construction')
|
||||
end
|
||||
|
||||
it 'accepte is traité' do
|
||||
dossier.accepte!
|
||||
expect(subject).to eq('Accepté')
|
||||
end
|
||||
|
||||
it 'en_instruction is reçu' do
|
||||
dossier.en_instruction!
|
||||
expect(subject).to eq('En instruction')
|
||||
end
|
||||
|
||||
it 'sans_suite is traité' do
|
||||
dossier.sans_suite!
|
||||
expect(subject).to eq('Sans suite')
|
||||
end
|
||||
|
||||
it 'refuse is traité' do
|
||||
dossier.refuse!
|
||||
expect(subject).to eq('Refusé')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -96,4 +96,108 @@ RSpec.describe DossierHelper, type: :helper do
|
|||
it_behaves_like "returns false"
|
||||
end
|
||||
end
|
||||
|
||||
describe '.dossier_display_state' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
|
||||
subject { dossier_display_state(dossier) }
|
||||
|
||||
it 'brouillon is brouillon' do
|
||||
dossier.brouillon!
|
||||
expect(subject).to eq('Brouillon')
|
||||
end
|
||||
|
||||
it 'en_construction is En construction' do
|
||||
dossier.en_construction!
|
||||
expect(subject).to eq('En construction')
|
||||
end
|
||||
|
||||
it 'accepte is traité' do
|
||||
dossier.accepte!
|
||||
expect(subject).to eq('Accepté')
|
||||
end
|
||||
|
||||
it 'en_instruction is reçu' do
|
||||
dossier.en_instruction!
|
||||
expect(subject).to eq('En instruction')
|
||||
end
|
||||
|
||||
it 'sans_suite is traité' do
|
||||
dossier.sans_suite!
|
||||
expect(subject).to eq('Sans suite')
|
||||
end
|
||||
|
||||
it 'refuse is traité' do
|
||||
dossier.refuse!
|
||||
expect(subject).to eq('Refusé')
|
||||
end
|
||||
|
||||
context "lower: true" do
|
||||
subject { dossier_display_state(dossier, lower: true) }
|
||||
|
||||
it 'brouillon is brouillon' do
|
||||
dossier.brouillon!
|
||||
expect(subject).to eq('brouillon')
|
||||
end
|
||||
|
||||
it 'en_construction is En construction' do
|
||||
dossier.en_construction!
|
||||
expect(subject).to eq('en construction')
|
||||
end
|
||||
|
||||
it 'accepte is traité' do
|
||||
dossier.accepte!
|
||||
expect(subject).to eq('accepté')
|
||||
end
|
||||
|
||||
it 'en_instruction is reçu' do
|
||||
dossier.en_instruction!
|
||||
expect(subject).to eq('en instruction')
|
||||
end
|
||||
|
||||
it 'sans_suite is traité' do
|
||||
dossier.sans_suite!
|
||||
expect(subject).to eq('sans suite')
|
||||
end
|
||||
|
||||
it 'refuse is traité' do
|
||||
dossier.refuse!
|
||||
expect(subject).to eq('refusé')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.dossier_legacy_state' do
|
||||
subject { dossier_legacy_state(dossier) }
|
||||
|
||||
context 'when the dossier is en instruction' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
|
||||
it { is_expected.to eq('brouillon') }
|
||||
end
|
||||
|
||||
context 'when the dossier is en instruction' do
|
||||
let(:dossier) { create(:dossier, :en_instruction) }
|
||||
|
||||
it { is_expected.to eq('received') }
|
||||
end
|
||||
|
||||
context 'when the dossier is accepte' do
|
||||
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:accepte)) }
|
||||
|
||||
it { is_expected.to eq('closed') }
|
||||
end
|
||||
|
||||
context 'when the dossier is refuse' do
|
||||
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:refuse)) }
|
||||
|
||||
it { is_expected.to eq('refused') }
|
||||
end
|
||||
|
||||
context 'when the dossier is sans_suite' do
|
||||
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:sans_suite)) }
|
||||
|
||||
it { is_expected.to eq('without_continuation') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1000,32 +1000,4 @@ describe Dossier do
|
|||
it { expect(long_expired_dossier).to be_retention_expired }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'old_state_value' do
|
||||
subject { dossier.old_state_value }
|
||||
|
||||
context 'when the dossier is en instruction' do
|
||||
let(:dossier) { create(:dossier, :en_instruction) }
|
||||
|
||||
it { is_expected.to eq('received') }
|
||||
end
|
||||
|
||||
context 'when the dossier is accepte' do
|
||||
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:accepte)) }
|
||||
|
||||
it { is_expected.to eq('closed') }
|
||||
end
|
||||
|
||||
context 'when the dossier is refuse' do
|
||||
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:refuse)) }
|
||||
|
||||
it { is_expected.to eq('refused') }
|
||||
end
|
||||
|
||||
context 'when the dossier is sans_suite' do
|
||||
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:sans_suite)) }
|
||||
|
||||
it { is_expected.to eq('without_continuation') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue