diff --git a/app/assets/stylesheets/dossiers.scss b/app/assets/stylesheets/dossiers.scss index 3e4769e86..b9a121e11 100644 --- a/app/assets/stylesheets/dossiers.scss +++ b/app/assets/stylesheets/dossiers.scss @@ -8,4 +8,10 @@ h5 span { #insee_infogreffe { font-size:17px; +} + +#recap_dossier{ + #validate_button { + float: right; + } } \ No newline at end of file diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index a30a713d6..9aff13549 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -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 diff --git a/app/views/users/recapitulatif/show.html.haml b/app/views/users/recapitulatif/show.html.haml index 0881117b5..d8a5b44a1 100644 --- a/app/views/users/recapitulatif/show.html.haml +++ b/app/views/users/recapitulatif/show.html.haml @@ -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'} diff --git a/config/routes.rb b/config/routes.rb index cc3fecd3e..5f0dcbb15 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20151127103412_add_archived_to_dossier.rb b/db/migrate/20151127103412_add_archived_to_dossier.rb new file mode 100644 index 000000000..0ee816695 --- /dev/null +++ b/db/migrate/20151127103412_add_archived_to_dossier.rb @@ -0,0 +1,5 @@ +class AddArchivedToDossier < ActiveRecord::Migration + def change + add_column :dossiers, :archived, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 1b1c8fff1..35bb5b3c9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 7259aa68d..fccf82d3f 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/views/users/dossiers/index.html.haml_spec.rb b/spec/views/users/dossiers/index.html.haml_spec.rb index 2cd0df048..b2b63f804 100644 --- a/spec/views/users/dossiers/index.html.haml_spec.rb +++ b/spec/views/users/dossiers/index.html.haml_spec.rb @@ -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') } diff --git a/spec/views/users/recapitulatif/show.html.haml_spec.rb b/spec/views/users/recapitulatif/show.html.haml_spec.rb index c3c28efd3..a2e5f0587 100644 --- a/spec/views/users/recapitulatif/show.html.haml_spec.rb +++ b/spec/views/users/recapitulatif/show.html.haml_spec.rb @@ -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