Merge branch 'develop' into staging

This commit is contained in:
Xavier J 2016-03-14 16:50:35 +01:00
commit f293a860f0
21 changed files with 292 additions and 21 deletions

View file

@ -64,17 +64,17 @@ class Backoffice::DossiersController < ApplicationController
def waiting_for_gestionnaire def waiting_for_gestionnaire
@a_traiter_class = (@liste == 'a_traiter' ? 'active' : '') @a_traiter_class = (@liste == 'a_traiter' ? 'active' : '')
@waiting_for_gestionnaire ||= current_gestionnaire.dossiers.waiting_for_gestionnaire @waiting_for_gestionnaire ||= current_gestionnaire.dossiers_filter.waiting_for_gestionnaire
end end
def waiting_for_user def waiting_for_user
@en_attente_class = (@liste == 'en_attente' ? 'active' : '') @en_attente_class = (@liste == 'en_attente' ? 'active' : '')
@waiting_for_user ||= current_gestionnaire.dossiers.waiting_for_user @waiting_for_user ||= current_gestionnaire.dossiers_filter.waiting_for_user
end end
def termine def termine
@termine_class = (@liste == 'termine' ? 'active' : '') @termine_class = (@liste == 'termine' ? 'active' : '')
@termine ||= current_gestionnaire.dossiers.termine @termine ||= current_gestionnaire.dossiers_filter.termine
end end
def total_dossiers_per_state def total_dossiers_per_state

View file

@ -0,0 +1,16 @@
class Backoffice::ProcedureFilterController < ApplicationController
before_action :authenticate_gestionnaire!
def index
@gestionnaire = current_gestionnaire
@procedures = current_gestionnaire.procedures
end
def update
current_gestionnaire.update_attribute(:procedure_filter, (params[:procedure_filter].nil? ? [] : params[:procedure_filter]))
flash.notice = 'Filtre mis à jour'
redirect_to backoffice_filtres_path
end
end

View file

@ -174,12 +174,12 @@ class Dossier < ActiveRecord::Base
#TODO refactor #TODO refactor
composed_scope = composed_scope.where( composed_scope = composed_scope.where(
dossiers[:id].eq_any(current_gestionnaire.dossiers.ids).and\ dossiers[:id].eq_any(current_gestionnaire.dossiers_filter.ids).and\
dossiers[:state].does_not_match('draft').and\ dossiers[:state].does_not_match('draft').and\
dossiers[:archived].eq(false)) dossiers[:archived].eq(false))
begin begin
if Float(terms) && terms.to_i <= 2147483647 && current_gestionnaire.dossiers.ids.include?(terms.to_i) if Float(terms) && terms.to_i <= 2147483647 && current_gestionnaire.dossiers_filter.ids.include?(terms.to_i)
dossier = Dossier.where("state != 'draft'").find(terms.to_i) dossier = Dossier.where("state != 'draft'").find(terms.to_i)
end end
rescue ArgumentError, ActiveRecord::RecordNotFound rescue ArgumentError, ActiveRecord::RecordNotFound

View file

@ -8,4 +8,12 @@ class Gestionnaire < ActiveRecord::Base
has_many :procedures, through: :administrateur has_many :procedures, through: :administrateur
has_many :dossiers, through: :procedures has_many :dossiers, through: :procedures
def dossiers_filter
dossiers.where(procedure_id: procedure_filter_list)
end
def procedure_filter_list
procedure_filter.empty? ? procedures.pluck(:id) : procedure_filter
end
end end

View file

@ -1,4 +1,5 @@
class CerfaSerializer < ActiveModel::Serializer class CerfaSerializer < ActiveModel::Serializer
attributes :content_url => :url attributes :content_url => :url
end end

View file

@ -0,0 +1,5 @@
class CommentaireSerializer < ActiveModel::Serializer
attributes :email,
:body,
:created_at
end

View file

@ -10,6 +10,7 @@ class DossierSerializer < ActiveModel::Serializer
has_one :entreprise has_one :entreprise
has_one :etablissement has_one :etablissement
has_one :cerfa has_one :cerfa
has_many :commentaires
has_many :champs has_many :champs
has_many :pieces_justificatives has_many :pieces_justificatives
end end

View file

@ -39,7 +39,7 @@ class CerfaUploader < CarrierWave::Uploader::Base
# Add a white list of extensions which are allowed to be uploaded. # Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this: # For images you might use something like this:
def extension_white_list def extension_white_list
%w(pdf) %w(pdf doc docxxls xlsx ppt pptx odt ods odp)
end end
# Override the filename of the uploaded files: # Override the filename of the uploaded files:

View file

@ -39,7 +39,7 @@ class PieceJustificativeUploader < CarrierWave::Uploader::Base
# Add a white list of extensions which are allowed to be uploaded. # Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this: # For images you might use something like this:
def extension_white_list def extension_white_list
%w(pdf xlsx xls doc docx) %w(pdf doc docxxls xlsx ppt pptx odt ods odp)
end end
# Override the filename of the uploaded files: # Override the filename of the uploaded files:

View file

@ -0,0 +1,16 @@
%h2.text-primary Filtre des procédures
%h4 Sélectionnez les procédures que vous souhaitez suivre.
= form_for @gestionnaire, url:{controller: 'backoffice/procedure_filter', action: :update } do |f|
.input-group
- @procedures.each do |procedure|
.checkbox
%label
= check_box_tag 'procedure_filter[]', procedure.id, (true if @gestionnaire.procedure_filter.include?(procedure.id))
= procedure.libelle
%br
= submit_tag 'Valider', class: 'btn btn-primary'
%br
%b
Aucune sélection = voir tout

View file

@ -0,0 +1,17 @@
%div{ style: "decorate:none; display: flex;box-shadow:none; float:right; display: flex" }
%div{ style: "vertical-align: middle; margin-right: 10px; margin-top: auto; margin-bottom: auto;" }
= current_gestionnaire.email
.dropdown#admin_menu
%button.btn.btn-default.dropdown-toggle#dropdownMenuAdmin{ type: :button, 'data-toggle' => 'dropdown', 'aria-haspopup' => true, 'aria-expanded' => false}
%i.fa.fa-cog
%span.caret
%ul.dropdown-menu.dropdown-menu-right
%li
= link_to(backoffice_filtres_path, id: :filter) do
%i.fa.fa-list
&nbsp;Filtre procédure
%li.divider{ role: :separator}
%li
= link_to('/gestionnaires/sign_out',id: :admin_sign_out, method: :delete) do
%i.fa.fa-power-off
&nbsp;Se déconnecter

View file

@ -21,9 +21,7 @@
#sign_out #sign_out
-if gestionnaire_signed_in? -if gestionnaire_signed_in?
%div = render partial: 'gestionnaires/login_banner'
= current_gestionnaire.email
= link_to "Déconnexion", '/gestionnaires/sign_out', method: :delete, :class => 'btn btn-md'
-elsif administrateur_signed_in? -elsif administrateur_signed_in?
= render partial: 'administrateurs/login_banner' = render partial: 'administrateurs/login_banner'
- elsif user_signed_in? - elsif user_signed_in?

View file

@ -68,9 +68,27 @@
-if @dossier.cerfa_available? -if @dossier.cerfa_available?
%span.btn.btn-sm.btn-file.btn-success %span.btn.btn-sm.btn-file.btn-success
Modifier Modifier
%input{type: 'file', name:'cerfa_pdf', id:'cerfa_pdf', accept: "application/pdf,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document", :max_file_size => 3.megabytes } %input{type: 'file', name:'cerfa_pdf', id:'cerfa_pdf', accept: "application/pdf,
application/msword,
application/vnd.openxmlformats-officedocument.wordprocessingml.document,
application/vnd.ms-excel,
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
application/vnd.ms-powerpoint,
application/vnd.openxmlformats-officedocument.presentationml.presentation,
application/vnd.oasis.opendocument.text,
application/vnd.oasis.opendocument.presentation,
application/vnd.oasis.opendocument.spreadsheet", :max_file_size => 3.megabytes }
-else -else
%input{type: 'file', name:'cerfa_pdf', id:'cerfa_pdf', accept: "application/pdf,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document", :max_file_size => 3.megabytes } %input{type: 'file', name:'cerfa_pdf', id:'cerfa_pdf', accept: "application/pdf,
application/msword,
application/vnd.openxmlformats-officedocument.wordprocessingml.document,
application/vnd.ms-excel,
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
application/vnd.ms-powerpoint,
application/vnd.openxmlformats-officedocument.presentationml.presentation,
application/vnd.oasis.opendocument.text,
application/vnd.oasis.opendocument.presentation,
application/vnd.oasis.opendocument.spreadsheet", :max_file_size => 3.megabytes }
- @dossier.pieces_justificatives.each do |piece_justificative| - @dossier.pieces_justificatives.each do |piece_justificative|
%tr %tr
@ -81,11 +99,29 @@
%span.text-success{ id: "piece_justificative_#{piece_justificative.type}" } Nous l'avons récupéré pour vous. %span.text-success{ id: "piece_justificative_#{piece_justificative.type}" } Nous l'avons récupéré pour vous.
-else -else
-if piece_justificative.empty? -if piece_justificative.empty?
= file_field_tag "piece_justificative_#{piece_justificative.type}", accept: 'application/pdf,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document', :max_file_size => 3.megabytes = file_field_tag "piece_justificative_#{piece_justificative.type}", accept: " application/pdf,
application/msword,
application/vnd.openxmlformats-officedocument.wordprocessingml.document,
application/vnd.ms-excel,
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
application/vnd.ms-powerpoint,
application/vnd.openxmlformats-officedocument.presentationml.presentation,
application/vnd.oasis.opendocument.text,
application/vnd.oasis.opendocument.presentation,
application/vnd.oasis.opendocument.spreadsheet", :max_file_size => 3.megabytes
-else -else
%span.btn.btn-sm.btn-file.btn-success %span.btn.btn-sm.btn-file.btn-success
Modifier Modifier
= file_field_tag "piece_justificative_#{piece_justificative.type}", accept: 'application/pdf,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document', :max_file_size => 3.megabytes = file_field_tag "piece_justificative_#{piece_justificative.type}", accept: " application/pdf,
application/msword,
application/vnd.openxmlformats-officedocument.wordprocessingml.document,
application/vnd.ms-excel,
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
application/vnd.ms-powerpoint,
application/vnd.openxmlformats-officedocument.presentationml.presentation,
application/vnd.oasis.opendocument.text,
application/vnd.oasis.opendocument.presentation,
application/vnd.oasis.opendocument.spreadsheet", :max_file_size => 3.megabytes
%div{style: 'text-align:right'} %div{style: 'text-align:right'}
%h6 Tous les champs portant un * sont obligatoires. %h6 Tous les champs portant un * sont obligatoires.

View file

@ -98,6 +98,10 @@ Rails.application.routes.draw do
get 'dossiers/search' => 'dossiers#search' get 'dossiers/search' => 'dossiers#search'
get 'filtres' => 'procedure_filter#index'
patch 'filtres/update' => 'procedure_filter#update'
resources :dossiers do resources :dossiers do
post 'valid' => 'dossiers#valid' post 'valid' => 'dossiers#valid'
post 'close' => 'dossiers#close' post 'close' => 'dossiers#close'

View file

@ -0,0 +1,5 @@
class AddProcedureFilterToGestionnaire < ActiveRecord::Migration
def change
add_column :gestionnaires, :procedure_filter, :integer, array: true, default: []
end
end

View file

@ -11,7 +11,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: 20160223134354) do ActiveRecord::Schema.define(version: 20160314102523) 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"
@ -172,6 +172,7 @@ ActiveRecord::Schema.define(version: 20160223134354) do
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "administrateur_id" t.integer "administrateur_id"
t.integer "procedure_filter", default: [], array: true
end end
add_index "gestionnaires", ["email"], name: "index_gestionnaires_on_email", unique: true, using: :btree add_index "gestionnaires", ["email"], name: "index_gestionnaires_on_email", unique: true, using: :btree

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe API::V1::DossiersController do describe API::V1::DossiersController do
let(:admin) { create(:administrateur) } let(:admin) { create(:administrateur) }
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, administrateur: admin) } let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, administrateur: admin, cerfa_flag: true) }
let(:wrong_procedure) { create(:procedure) } let(:wrong_procedure) { create(:procedure) }
it { expect(described_class).to be < APIController } it { expect(described_class).to be < APIController }
@ -116,7 +116,7 @@ describe API::V1::DossiersController do
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } } let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:body) { JSON.parse(retour.body, symbolize_names: true) } let(:body) { JSON.parse(retour.body, symbolize_names: true) }
let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :pieces_justificatives, :champs] } let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :pieces_justificatives, :champs, :commentaires] }
subject { body[:dossier] } subject { body[:dossier] }
it 'return REST code 200', :show_in_doc do it 'return REST code 200', :show_in_doc do
@ -219,6 +219,32 @@ describe API::V1::DossiersController do
end end
end end
describe 'commentaires' do
let!(:commentaire) { create :commentaire, body: 'plop', created_at: '2016-03-14 14:00:00', email: 'plop@plip.com', dossier: dossier }
let!(:commentaire_2) { create :commentaire, body: 'plip', created_at: '2016-03-14 15:00:00', email: 'plip@plap.com', dossier: dossier }
subject { super()[:commentaires] }
it { expect(subject.size).to eq 2 }
it { expect(subject.first[:body]).to eq 'plop' }
it { expect(subject.first[:created_at]).to eq '2016-03-14T14:00:00.000Z' }
it { expect(subject.first[:email]).to eq 'plop@plip.com' }
end
describe 'cerfa' do
let(:content) { File.open('./spec/support/files/piece_justificative_388.pdf') }
before do
dossier.cerfa.content = content
dossier.cerfa.save
end
subject { super()[:cerfa] }
it { expect(subject[:url]).to match /^http:\/\/.*downloads.*_CERFA\.pdf$/ }
end
describe 'etablissement' do describe 'etablissement' do
let(:field_list) { [ let(:field_list) { [
:siret, :siret,

View file

@ -0,0 +1,62 @@
require 'spec_helper'
describe Backoffice::ProcedureFilterController, type: :controller do
let(:gestionnaire) { create :gestionnaire }
before do
sign_in gestionnaire
end
describe '#GET index' do
subject { get :index }
before do
subject
end
it { expect(response.status).to eq 200 }
end
describe '#PATCH update' do
context 'when procedure_filter params is not present' do
subject { patch :update }
before do
subject
end
it { is_expected.to redirect_to backoffice_filtres_path }
it { expect(gestionnaire.procedure_filter).to eq [] }
end
context 'when procedure_filter attribut is not empty and procedure_filter params is not present' do
let(:gestionnaire) { create :gestionnaire, procedure_filter: [3,2] }
subject { patch :update }
before do
subject
gestionnaire.reload
end
it { is_expected.to redirect_to backoffice_filtres_path }
it { expect(gestionnaire.procedure_filter).to eq [] }
end
context 'when procedure_filter params is present' do
let (:procedure_filter) { ["3", "1"] }
subject { patch :update, procedure_filter: procedure_filter }
before do
subject
gestionnaire.reload
end
it { is_expected.to redirect_to backoffice_filtres_path }
it { expect(gestionnaire.procedure_filter.size).to eq 2 }
it { expect(gestionnaire.procedure_filter).to include 1 }
it { expect(gestionnaire.procedure_filter).to include 3 }
end
end
end

View file

@ -21,4 +21,46 @@ describe Gestionnaire, type: :model do
it { is_expected.to have_many(:procedures) } it { is_expected.to have_many(:procedures) }
it { is_expected.to have_many(:dossiers) } it { is_expected.to have_many(:dossiers) }
end end
describe '#dossiers_filter' do
let(:admin) { create :administrateur }
let(:procedure) { create :procedure, administrateur: admin }
let(:procedure_2) { create :procedure, administrateur: admin }
let(:gestionnaire) { create :gestionnaire, procedure_filter: procedure_filter, administrateur: admin }
let!(:dossier) { create :dossier, procedure: procedure }
let(:procedure_filter) { [] }
subject { gestionnaire.dossiers_filter }
context 'before filter' do
it { expect(subject.size).to eq 1 }
end
context 'after filter' do
let(:procedure_filter) { [procedure_2.id] }
it { expect(subject.size).to eq 0 }
end
end
describe '#procedure_filter_list' do
let(:admin) { create :administrateur }
let!(:procedure) { create :procedure, administrateur: admin }
let!(:procedure_2) { create :procedure, administrateur: admin }
let(:gestionnaire) { create :gestionnaire, procedure_filter: procedure_filter, administrateur: admin }
let(:procedure_filter) { [] }
subject { gestionnaire.procedure_filter_list }
context 'when gestionnaire procedure_filter is empty' do
it { expect(subject).to eq [procedure.id, procedure_2.id] }
end
context 'when gestionnaire procedure_filter is no empty' do
let(:procedure_filter) { [procedure.id] }
it { expect(subject).to eq [procedure.id] }
end
end
end end

View file

@ -5,9 +5,10 @@ describe 'backoffice/dossiers/index.html.haml', type: :view do
let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) } let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) }
let!(:procedure) { create(:procedure, administrateur: administrateur) } let!(:procedure) { create(:procedure, administrateur: administrateur) }
let!(:decorate_dossier_initiated) { create(:dossier, procedure: procedure, nom_projet: 'projet initiated', state: 'initiated').decorate }
let!(:decorate_dossier_replied) { create(:dossier, procedure: procedure, nom_projet: 'projet replied', state: 'replied').decorate } let!(:decorate_dossier_initiated) { create(:dossier, procedure: procedure, nom_projet: 'projet initiated', state: 'initiated').decorate }
let!(:decorate_dossier_closed) { create(:dossier, procedure: procedure, nom_projet: 'projet closed', state: 'closed').decorate } let!(:decorate_dossier_replied) { create(:dossier, procedure: procedure, nom_projet: 'projet replied', state: 'replied').decorate }
let!(:decorate_dossier_closed) { create(:dossier, procedure: procedure, nom_projet: 'projet closed', state: 'closed').decorate }
describe 'on tab a_traiter' do describe 'on tab a_traiter' do
before do before do
@ -36,7 +37,6 @@ describe 'backoffice/dossiers/index.html.haml', type: :view do
end end
end end
describe 'on tab en_attente' do describe 'on tab en_attente' do
before do before do
assign(:dossiers, (smart_listing_create :dossiers, assign(:dossiers, (smart_listing_create :dossiers,

View file

@ -0,0 +1,33 @@
require 'spec_helper'
describe 'backoffice/procedure_filter/index.html.haml', type: :view do
let(:administrateur) { create :administrateur }
before do
create :procedure, libelle: 'plip', administrateur: administrateur
create :procedure, libelle: 'plop', administrateur: administrateur
create :procedure, libelle: 'plap', administrateur: administrateur
end
context 'when gestionnaire have already check procedure' do
let(:gestionnaire) { create(:gestionnaire,
administrateur: administrateur,
procedure_filter: [administrateur.procedures.first.id,
administrateur.procedures.last.id]) }
before do
sign_in gestionnaire
assign(:gestionnaire, gestionnaire)
assign(:procedures, gestionnaire.procedures)
render
end
subject { rendered }
it { is_expected.to have_content('Filtre des procédures') }
it { is_expected.to have_css("input[type=checkbox][value='#{gestionnaire.procedures.first.id}'][checked=checked]") }
it { is_expected.to have_css("input[type=checkbox][value='#{gestionnaire.procedures.last.id}'][checked=checked]") }
end
end