Merge pull request #88 from sgmap/show_archived_dossier_to_user

Show archived dossier to user
This commit is contained in:
Mathieu Magnin 2017-04-21 14:48:13 +02:00 committed by GitHub
commit b77a3c723c
15 changed files with 116 additions and 188 deletions

View file

@ -10,19 +10,29 @@ class Users::DossiersController < UsersController
end
def index
cookies[:liste] = param_liste
@liste ||= params[:liste] || 'a_traiter'
@dossiers_list_facade = DossiersListFacades.new current_user, param_liste
@user_dossiers = current_user.dossiers
unless DossiersListUserService.dossiers_liste_libelle.include?(param_liste)
cookies[:liste] = 'a_traiter'
@dossiers_filtered = case @liste
when 'brouillon'
@user_dossiers.brouillon.order_by_updated_at
when 'a_traiter'
@user_dossiers.en_construction.order_by_updated_at
when 'en_instruction'
@user_dossiers.en_instruction.order_by_updated_at
when 'termine'
@user_dossiers.termine.order_by_updated_at
when 'invite'
current_user.invites
else
return redirect_to users_dossiers_path
end
@dossiers = smart_listing_create :dossiers,
@dossiers_list_facade.dossiers_to_display,
partial: "users/dossiers/list",
array: true
@dossiers_filtered,
partial: "users/dossiers/list",
array: true
end
def commencer
@ -222,8 +232,4 @@ class Users::DossiersController < UsersController
def facade id = params[:id]
DossierFacades.new id, current_user.email
end
def param_liste
@liste ||= params[:liste] || cookies[:liste] || 'a_traiter'
end
end

View file

@ -10,11 +10,7 @@ class DossiersListFacades
end
def service
if gestionnaire?
@service ||= DossiersListGestionnaireService.new @current_devise_profil, @liste, @procedure
elsif user?
@service ||= DossiersListUserService.new @current_devise_profil, @liste
end
@service ||= DossiersListGestionnaireService.new @current_devise_profil, @liste, @procedure
end
def total_dossier
@ -63,84 +59,24 @@ class DossiersListFacades
preference_list_dossiers_filter.where(table: :champs).where.not(filter: '').size == 0
end
def all_state_class
(@liste == 'all_state' ? 'active' : '')
end
def brouillon_class
(@liste == 'brouillon' ? 'active' : '')
end
def en_construction_class
(@liste == 'a_traiter' ? 'active' : '')
end
def valides_class
(@liste == 'valides' ? 'active' : '')
end
def en_instruction_class
(@liste == 'en_instruction' ? 'active' : '')
end
def termine_class
(@liste == 'termine' ? 'active' : '')
end
def invite_class
(@liste == 'invite' ? 'active' : '')
end
def all_state_total
service.all_state.count
end
def brouillon_total
service.brouillon.count
end
def nouveaux_total
service.nouveaux.count
end
def en_construction_total
service.en_construction.count
end
def valides_total
service.valides.count
end
def en_instruction_total
service.en_instruction.count
end
def termine_total
service.termine.count
end
def suivi_total
service.suivi.count
end
def invite_total
service.invite.count
end
def filter_url
@procedure.nil? ? backoffice_dossiers_filter_path(liste: liste) : backoffice_dossiers_procedure_filter_path(id: @procedure.id, liste: liste)
end
private
def gestionnaire?
@current_devise_profil.class == Gestionnaire
end
def user?
@current_devise_profil.class == User
end
def base_url liste
@procedure.nil? ? backoffice_dossiers_path(liste: liste) : backoffice_dossiers_procedure_path(id: @procedure.id, liste: liste)
end

View file

@ -157,18 +157,18 @@ class Dossier < ActiveRecord::Base
state
end
def brouillon?
BROUILLON.include?(state)
end
def self.all_state order = 'ASC'
where(state: ALL_STATE, archived: false).order("updated_at #{order}")
end
def self.brouillon order = 'ASC'
where(state: BROUILLON, archived: false).order("updated_at #{order}")
def brouillon?
BROUILLON.include?(state)
end
scope :brouillon, -> { where(state: BROUILLON) }
scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) }
def self.nouveaux order = 'ASC'
where(state: NOUVEAUX, archived: false).order("updated_at #{order}")
end
@ -181,7 +181,7 @@ class Dossier < ActiveRecord::Base
where(state: WAITING_FOR_USER, archived: false).order("updated_at #{order}")
end
scope :en_construction, -> { where(state: EN_CONSTRUCTION, archived: false).order(updated_at: :asc) }
scope :en_construction, -> { where(state: EN_CONSTRUCTION) }
def self.ouvert order = 'ASC'
where(state: OUVERT, archived: false).order("updated_at #{order}")
@ -191,15 +191,12 @@ class Dossier < ActiveRecord::Base
where(state: A_INSTRUIRE, archived: false).order("updated_at #{order}")
end
def self.en_instruction order = 'ASC'
where(state: EN_INSTRUCTION, archived: false).order("updated_at #{order}")
end
scope :en_instruction, -> { where(state: EN_INSTRUCTION) }
def self.termine order = 'ASC'
where(state: TERMINE, archived: false).order("updated_at #{order}")
end
scope :termine, -> { where(state: TERMINE) }
scope :archived, -> { where(archived: true) }
scope :not_archived, -> { where(archived: false) }
scope :downloadable, -> { all_state }

View file

@ -45,7 +45,7 @@ class DossiersListGestionnaireService
end
def termine
@termine ||= filter_dossiers.termine
@termine ||= filter_dossiers.termine.not_archived
end
def filter_dossiers

View file

@ -1,43 +0,0 @@
class DossiersListUserService
def initialize current_devise_profil, liste
@current_devise_profil = current_devise_profil
@liste = liste
end
def dossiers_to_display
{'brouillon' => brouillon,
'a_traiter' => en_construction,
'en_instruction' => en_instruction,
'termine' => termine,
'invite' => invite,
'all_state' => all_state}[@liste]
end
def self.dossiers_liste_libelle
['brouillon', 'a_traiter', 'en_instruction', 'termine', 'invite', 'all_state']
end
def all_state
@all_state ||= @current_devise_profil.dossiers.all_state
end
def brouillon
@brouillon ||= @current_devise_profil.dossiers.brouillon
end
def en_construction
@en_construction ||= @current_devise_profil.dossiers.en_construction
end
def invite
@invite ||= @current_devise_profil.invites
end
def en_instruction
@en_instruction ||= @current_devise_profil.dossiers.en_instruction
end
def termine
@termine ||= @current_devise_profil.dossiers.termine
end
end

View file

@ -12,34 +12,34 @@
#procedure-list
- unless current_user.dossiers.count == 0
%a{ :href => "#{url_for users_dossiers_path(liste: 'brouillon')}", 'data-toggle' => :tooltip, title: 'Les dossiers jamais proposés à la relecture.' }
.procedure-list-element{ class: @dossiers_list_facade.brouillon_class, id: 'brouillon' }
.procedure-list-element{ class: ('active' if @liste == 'brouillon'), id: 'brouillon' }
Brouillons
.badge.progress-bar-default
= @dossiers_list_facade.brouillon_total
= @user_dossiers.brouillon.count
%a{ :href => "#{url_for users_dossiers_path(liste: 'a_traiter')}", 'data-toggle' => :tooltip, title: 'Les dossiers qui requièrent une action de votre part.' }
.procedure-list-element{ class: @dossiers_list_facade.en_construction_class, id: 'a_traiter' }
.procedure-list-element{ class: ('active' if @liste == 'a_traiter'), id: 'a_traiter' }
En construction
.badge.progress-bar-danger
= @dossiers_list_facade.en_construction_total
= @user_dossiers.en_construction.count
%a{ :href => "#{url_for users_dossiers_path(liste: 'en_instruction')}", 'data-toggle' => :tooltip, title: 'Les dossiers en cours d\'examen par l\'administration compétante.' }
.procedure-list-element{ class: @dossiers_list_facade.en_instruction_class, id: 'en_instruction' }
.procedure-list-element{ class: ('active' if @liste == 'en_instruction'), id: 'en_instruction' }
En instruction
.badge.progress-bar-default
= @dossiers_list_facade.en_instruction_total
= @user_dossiers.en_instruction.count
%a{ :href => "#{url_for users_dossiers_path(liste: 'termine')}", 'data-toggle' => :tooltip, title: 'Les dossiers cloturés qui peuvent être "Accepté", "Refusé" ou "Sans suite".' }
.procedure-list-element{ class: @dossiers_list_facade.termine_class, id: 'termine' }
.procedure-list-element{ class: ('active' if @liste == 'termine'), id: 'termine' }
Terminé
.badge.progress-bar-success
= @dossiers_list_facade.termine_total
= @user_dossiers.termine.count
%a{ :href => "#{url_for users_dossiers_path(liste: 'invite')}" }
.procedure-list-element{ class: @dossiers_list_facade.invite_class, id: 'invite' }
.procedure-list-element{ class: ('active' if @liste == 'invite'), id: 'invite' }
Invitation
.badge.progress-bar-warning
= @dossiers_list_facade.invite_total
= current_user.invites.count
.split-hr-left

View file

@ -5,7 +5,7 @@
.col-md-1.col-lg-1.col-sm-1.col-xs-1
.fa.fa-info-circle.text-info{ style: 'font-size: 2em; margin-top: 20%;' }
.col-xs-11
- case dossiers_list_facade.liste
- case liste
- when 'brouillon'
Les dossiers présents dans cette liste
%b

View file

@ -12,4 +12,4 @@
.body
= smart_listing_render :dossiers
= render partial: 'state_description', locals: { dossiers_list_facade: @dossiers_list_facade }
= render partial: 'state_description', locals: { liste: @liste }

View file

@ -3,8 +3,8 @@ require 'spec_helper'
describe DossiersListFacades do
let(:gestionnaire) { create :gestionnaire }
let(:procedure) { create :procedure }
let(:procedure_2) { create :procedure, libelle: 'plop' }
let(:procedure) { create :procedure, libelle: 'Ma procédure' }
let(:procedure_2) { create :procedure, libelle: 'Ma seconde procédure' }
let!(:preference) { create :preference_list_dossier,
gestionnaire: gestionnaire,
@ -48,14 +48,8 @@ describe DossiersListFacades do
it { expect(subject.size).to eq 2 }
it { expect(subject.first[:id]).to eq procedure.id }
it { expect(subject.first[:libelle]).to eq procedure.libelle }
it { expect(subject.first[:unread_notifications]).to eq 0 }
it { expect(subject.last[:id]).to eq procedure_2.id }
it { expect(subject.last[:libelle]).to eq procedure_2.libelle }
it { expect(subject.last[:unread_notifications]).to eq 0 }
it { expect(subject.first).to eq({ id: procedure.id, libelle: procedure.libelle, unread_notifications: 0 }) }
it { expect(subject.last).to eq({ id: procedure_2.id, libelle: procedure_2.libelle, unread_notifications: 0 }) }
end
describe '#active_filter?' do

View file

@ -47,6 +47,14 @@ FactoryGirl.define do
end
end
trait :archived do
archived true
end
trait :not_archived do
archived false
end
trait :replied do
state 'replied'
end

View file

@ -2,7 +2,7 @@ FactoryGirl.define do
sequence(:published_path) { |n| "fake_path#{n}" }
factory :procedure do
lien_demarche 'http://localhost'
libelle 'Demande de subvention'
sequence(:libelle) { |n| "Procedure #{n}" }
description "Demande de subvention à l'intention des associations"
organisation "Orga SGMAP"
direction "direction SGMAP"

View file

@ -1,15 +1,14 @@
require 'spec_helper'
feature 'user access to the list of his dossier' do
describe 'user access to the list of his dossier' do
let(:user) { create(:user) }
let!(:last_updated_dossier) { create(:dossier, :with_entreprise, user: user, state: 'replied')}
let!(:dossier1) { create(:dossier, :with_entreprise, user: user, state: 'replied') }
let!(:dossier2) { create(:dossier, :with_entreprise) }
let!(:dossier_archived) { create(:dossier, :with_entreprise, user: user, state: 'replied') }
before do
dossier1.update_column(:updated_at, "19/07/2052 15:35".to_time)
dossier1.procedure.update_column(:libelle, 'PLOP')
last_updated_dossier.procedure.update_column(:libelle, 'PLIP')
last_updated_dossier.update_column(:updated_at, "19/07/2052 15:35".to_time)
visit new_user_session_path
within('#new-user') do
@ -18,16 +17,21 @@ feature 'user access to the list of his dossier' do
page.click_on 'Se connecter'
end
end
scenario 'the list of dossier is displayed' do
it 'the list of dossier is displayed' do
expect(page).to have_content(dossier1.procedure.libelle)
expect(page).not_to have_content(dossier2.procedure.libelle)
end
scenario 'the list must be order by last updated' do
it 'the list must be order by last updated' do
expect(page.body).to match(/#{last_updated_dossier.procedure.libelle}.*#{dossier1.procedure.libelle}/m)
end
scenario 'the state of dossier is displayed' do
it 'should list archived dossier' do
expect(page).to have_content(dossier_archived.procedure.libelle)
end
it 'the state of dossier is displayed' do
expect(page).to have_css("#dossier_#{dossier1.id}_state")
end

View file

@ -8,7 +8,7 @@ describe MailTemplateConcern do
it 'works' do
initiated_mail.object = '[TPS] --numero_dossier-- --libelle_procedure-- --lien_dossier--'
expected =
"[TPS] #{dossier.id} Demande de subvention " +
"[TPS] #{dossier.id} #{dossier.procedure.libelle} " +
"<a target=\"_blank\" href=\"http://localhost:3000/users/dossiers/#{dossier.id}/recapitulatif\">http://localhost:3000/users/dossiers/#{dossier.id}/recapitulatif</a>"
expect(initiated_mail.object_for_dossier(dossier)).to eq(expected)

View file

@ -418,23 +418,23 @@ describe Dossier do
let(:procedure_admin) { create(:procedure, administrateur: admin) }
let(:procedure_admin_2) { create(:procedure, administrateur: admin_2) }
let!(:dossier) { create(:dossier, procedure: procedure_admin, state: 'draft') }
let!(:dossier2) { create(:dossier, procedure: procedure_admin, state: 'initiated') } #nouveaux
let!(:dossier3) { create(:dossier, procedure: procedure_admin, state: 'initiated') } #nouveaux
let!(:dossier4) { create(:dossier, procedure: procedure_admin, state: 'replied') } #en_attente
let!(:dossier5) { create(:dossier, procedure: procedure_admin, state: 'updated') } #a_traiter
let!(:dossier6) { create(:dossier, procedure: procedure_admin, state: 'received') } #a_instruire
let!(:dossier7) { create(:dossier, procedure: procedure_admin, state: 'received') } #a_instruire
let!(:dossier8) { create(:dossier, procedure: procedure_admin, state: 'closed') } #termine
let!(:dossier9) { create(:dossier, procedure: procedure_admin, state: 'refused') } #termine
let!(:dossier10) { create(:dossier, procedure: procedure_admin, state: 'without_continuation') } #termine
let!(:dossier11) { create(:dossier, procedure: procedure_admin_2, state: 'closed') } #termine
let!(:dossier12) { create(:dossier, procedure: procedure_admin, state: 'initiated', archived: true) } #a_traiter #archived
let!(:dossier13) { create(:dossier, procedure: procedure_admin, state: 'replied', archived: true) } #en_attente #archived
let!(:dossier14) { create(:dossier, procedure: procedure_admin, state: 'closed', archived: true) } #termine #archived
before do
create :assign_to, gestionnaire: gestionnaire, procedure: procedure_admin
create(:dossier, procedure: procedure_admin, state: 'draft')
create(:dossier, procedure: procedure_admin, state: 'initiated') #nouveaux
create(:dossier, procedure: procedure_admin, state: 'initiated') #nouveaux
create(:dossier, procedure: procedure_admin, state: 'replied') #en_attente
create(:dossier, procedure: procedure_admin, state: 'updated') #a_traiter
create(:dossier, procedure: procedure_admin, state: 'received') #a_instruire
create(:dossier, procedure: procedure_admin, state: 'received') #a_instruire
create(:dossier, procedure: procedure_admin, state: 'closed') #termine
create(:dossier, procedure: procedure_admin, state: 'refused') #termine
create(:dossier, procedure: procedure_admin, state: 'without_continuation') #termine
create(:dossier, procedure: procedure_admin_2, state: 'closed') #termine
create(:dossier, procedure: procedure_admin, state: 'initiated', archived: true) #a_traiter #archived
create(:dossier, procedure: procedure_admin, state: 'replied', archived: true) #en_attente #archived
create(:dossier, procedure: procedure_admin, state: 'closed', archived: true) #termine #archived
end
describe '#nouveaux' do
@ -455,19 +455,13 @@ describe Dossier do
it { expect(subject.size).to eq(1) }
end
describe '#a_instruire' do
subject { gestionnaire.dossiers.a_instruire }
describe '#en_instruction' do
subject { gestionnaire.dossiers.en_instruction }
it { expect(subject.size).to eq(2) }
end
describe '#termine' do
subject { gestionnaire.dossiers.termine }
it { expect(subject.size).to eq(3) }
it { expect(subject).to include(dossier6, dossier7) }
end
end
end
describe '#cerfa_available?' do

View file

@ -345,4 +345,36 @@ describe DossiersListGestionnaireService do
end
end
end
describe 'state filter methods' do
let!(:procedure) { create :procedure }
let!(:dossier) { create(:dossier, procedure: procedure, state: 'draft') }
let!(:dossier2) { create(:dossier, procedure: procedure, state: 'initiated') } #nouveaux
let!(:dossier3) { create(:dossier, procedure: procedure, state: 'initiated') } #nouveaux
let!(:dossier4) { create(:dossier, procedure: procedure, state: 'replied') } #en_attente
let!(:dossier5) { create(:dossier, procedure: procedure, state: 'updated') } #a_traiter
let!(:dossier6) { create(:dossier, procedure: procedure, state: 'received') } #a_instruire
let!(:dossier7) { create(:dossier, procedure: procedure, state: 'received') } #a_instruire
let!(:dossier8) { create(:dossier, procedure: procedure, state: 'closed') } #termine
let!(:dossier9) { create(:dossier, procedure: procedure, state: 'refused') } #termine
let!(:dossier10) { create(:dossier, procedure: procedure, state: 'without_continuation') } #termine
let!(:dossier11) { create(:dossier, procedure: procedure, state: 'closed') } #termine
let!(:dossier12) { create(:dossier, procedure: procedure, state: 'initiated', archived: true) } #a_traiter #archived
let!(:dossier13) { create(:dossier, procedure: procedure, state: 'replied', archived: true) } #en_attente #archived
let!(:dossier14) { create(:dossier, procedure: procedure, state: 'closed', archived: true) } #termine #archived
describe '#termine' do
subject { DossiersListGestionnaireService.new(gestionnaire, liste, procedure).termine }
it { expect(subject.size).to eq(4) }
it { expect(subject).to include(dossier8, dossier9, dossier10, dossier11) }
end
describe '#a_instruire' do
subject { DossiersListGestionnaireService.new(gestionnaire, liste, procedure).a_instruire }
it { expect(subject.size).to eq(2) }
it { expect(subject).to include(dossier6, dossier7) }
end
end
end