Add archive button on recapitulative page user dossier

This commit is contained in:
Xavier J 2015-11-27 13:56:54 +01:00
parent b541e74422
commit a79ecbba6d
9 changed files with 89 additions and 35 deletions

View file

@ -8,4 +8,10 @@ h5 span {
#insee_infogreffe {
font-size:17px;
}
#recap_dossier{
#validate_button {
float: right;
}
}

View file

@ -78,6 +78,18 @@ class Users::DossiersController < UsersController
end
end
def archive
@dossier = current_user.dossiers.find(params[:dossier_id])
@dossier.update_attributes({archived: true})
flash.notice = 'Dossier archivé'
redirect_to users_dossiers_path
rescue ActiveRecord::RecordNotFound
flash.alert = 'Dossier inéxistant'
redirect_to users_dossiers_path
end
private
def update_params

View file

@ -1,22 +1,32 @@
.row#recap_dossier
.col-md-2.col-lg-2
%h2
='Récapitulatif'
.col-md-4.col-lg-4
.row
.col-md-6.col-lg-6
%h2 Récapitulatif
.col-md-6.col-lg-6
= form_tag "/users/dossiers/#{@dossier.id}/archive", style:'margin-top:21px', action: :archive, method: :put do
%button#archive.btn.btn-sm.btn-default.text-info{type: :button}
%i.fa.fa-eraser
Archiver
#confirm
%button#valid.btn.btn-sm.btn-success{type: :submit}
%i.fa.fa-check
Valider
%button#cancel.btn.btn-sm.btn-danger{type: :button}
%i.fa.fa-remove
Annuler
.col-md-7.col-lg-7
.col-md-5.col-lg-5
.col-md-3.col-lg-3
%h2#dossier_id{:class => 'text-info', :style => 'text-align:right; margin-bottom:15px'}
= "Dossier n°#{@dossier.id}"
- unless gestionnaire_signed_in?
-if @dossier.draft?
= form_tag(url_for({controller: :recapitulatif, action: :initiate, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
%button#action_button.btn.btn-success
= 'Soumettre mon dossier'
-elsif @dossier.validated?
= form_tag(url_for({controller: :recapitulatif, action: :submit, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
%button#action_button.btn.btn-success
-if @dossier.validated?
%br
= form_tag(url_for({controller: :recapitulatif, action: :submit, dossier_id: @dossier.id}), method: 'POST') do
%button#validate_button.btn.btn-success
= 'Déposer mon dossier'
-else
%h3{:class => 'text-success', :style => 'text-align:right'}

View file

@ -37,6 +37,8 @@ Rails.application.routes.draw do
get '/carte' => 'carte#show'
post '/carte' => 'carte#save'
put '/archive' => 'dossiers#archive'
end
resource :dossiers
end

View file

@ -0,0 +1,5 @@
class AddArchivedToDossier < ActiveRecord::Migration
def change
add_column :dossiers, :archived, :boolean, default: false
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151126153425) do
ActiveRecord::Schema.define(version: 20151127103412) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -67,6 +67,7 @@ ActiveRecord::Schema.define(version: 20151126153425) do
t.string "state"
t.integer "user_id"
t.text "json_latlngs"
t.boolean "archived", default: false
end
add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree

View file

@ -2,6 +2,7 @@ require 'spec_helper'
describe Users::DossiersController, type: :controller do
let(:user) { create(:user) }
describe '.index' do
let!(:dossier) { create(:dossier, :with_entreprise, :with_procedure, user: user) }
subject { get :index }
@ -17,7 +18,6 @@ describe Users::DossiersController, type: :controller do
end
end
let(:use_api_carto) { false }
let(:procedure) { create(:procedure, use_api_carto: use_api_carto) }
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
@ -30,7 +30,7 @@ describe Users::DossiersController, type: :controller do
describe 'GET #show' do
before do
sign_in dossier.user
sign_in dossier.user
end
it 'returns http success with dossier_id valid' do
get :show, id: dossier_id
@ -46,13 +46,13 @@ describe Users::DossiersController, type: :controller do
describe 'POST #create' do
before do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret_not_found}?token=#{SIADETOKEN}")
.to_return(status: 404, body: 'fake body')
.to_return(status: 404, body: 'fake body')
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
.to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/exercices.json'))
@ -66,7 +66,7 @@ describe Users::DossiersController, type: :controller do
sign_in user
end
subject { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }
subject { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }
it 'create a dossier' do
@ -138,7 +138,7 @@ describe Users::DossiersController, type: :controller do
describe 'PUT #update' do
before do
sign_in dossier.user
put :update, id: dossier_id, dossier: { autorisation_donnees: autorisation_donnees }
put :update, id: dossier_id, dossier: {autorisation_donnees: autorisation_donnees}
end
context 'when Checkbox is checked' do
let(:autorisation_donnees) { '1' }
@ -153,7 +153,7 @@ describe Users::DossiersController, type: :controller do
let(:use_api_carto) { true }
before do
put :update, id: dossier_id, dossier: { autorisation_donnees: autorisation_donnees }
put :update, id: dossier_id, dossier: {autorisation_donnees: autorisation_donnees}
end
it 'redirects to carte' do
expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier.id)
@ -178,4 +178,34 @@ describe Users::DossiersController, type: :controller do
end
end
end
describe 'PUT #archive' do
let(:dossier) { create(:dossier, user: user) }
context 'when user is the owner of the file' do
before do
sign_in user
put :archive, dossier_id: dossier.id
dossier.reload
end
it { expect(dossier.archived).to be_truthy }
it { expect(response).to redirect_to :users_dossiers }
it { expect(flash[:notice]).to have_content 'Dossier archivé' }
end
context 'when user is not the owner of the file' do
let(:user_2) { create(:user) }
before do
sign_in user_2
put :archive, dossier_id: dossier.id
procedure.reload
end
it { expect(response).to redirect_to :users_dossiers }
it { expect(flash[:alert]).to have_content 'Dossier inéxistant' }
end
end
end

View file

@ -5,8 +5,8 @@ describe 'users/dossiers/index.html.haml', type: :view do
describe 'list dossiers' do
let(:user) { create(:user) }
let!(:dossier1) { create(:dossier, user: user, state: 'initiated') }
let!(:dossier2) { create(:dossier, user: user, state: 'initiated') }
let!(:dossier1) { create(:dossier, :with_procedure, user: user, state: 'initiated') }
let!(:dossier2) { create(:dossier, :with_procedure, user: user, state: 'initiated') }
let(:dossiers) { user.dossiers.where("state NOT IN ('draft')").order(updated_at: 'DESC') }

View file

@ -53,18 +53,6 @@ describe 'users/recapitulatif/show.html.haml', type: :view do
end
context 'buttons to change dossier state' do
context 'when dossier state is draft' do
before do
dossier.draft!
render
end
it 'button Soumettre mon dossier est present' do
expect(rendered).to have_css('#action_button')
expect(rendered).to have_content('Soumettre mon dossier')
end
end
context 'when dossier state is initiated' do
before do
dossier.initiated!
@ -100,7 +88,7 @@ describe 'users/recapitulatif/show.html.haml', type: :view do
end
it 'button Déposer mon dossier est present' do
expect(rendered).to have_css('#action_button')
expect(rendered).to have_css('#validate_button')
expect(rendered).to have_content('Déposer mon dossier')
end