Merge branch 'develop' into staging

This commit is contained in:
Xavier J 2016-06-20 14:06:45 +02:00
commit 1d88310996
43 changed files with 674 additions and 163 deletions

View file

@ -22,6 +22,8 @@ gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api. # bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc gem 'sdoc', '~> 0.4.0', group: :doc
# Enable deep clone of active record models
gem 'deep_cloneable', '~> 2.2.1'
# Use ActiveModel has_secure_password # Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7' # gem 'bcrypt', '~> 3.1.7'

View file

@ -119,6 +119,8 @@ GEM
sprockets (>= 2.0.0) sprockets (>= 2.0.0)
database_cleaner (1.4.1) database_cleaner (1.4.1)
debug_inspector (0.0.2) debug_inspector (0.0.2)
deep_cloneable (2.2.1)
activerecord (>= 3.1.0, < 5.2.0)
devise (3.4.1) devise (3.4.1)
bcrypt (~> 3.0) bcrypt (~> 3.0)
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
@ -634,6 +636,7 @@ DEPENDENCIES
coffee-rails (~> 4.1.0) coffee-rails (~> 4.1.0)
css_splitter css_splitter
database_cleaner database_cleaner
deep_cloneable (~> 2.2.1)
devise devise
draper draper
factory_girl factory_girl
@ -690,4 +693,4 @@ DEPENDENCIES
will_paginate-bootstrap will_paginate-bootstrap
BUNDLED WITH BUNDLED WITH
1.11.2 1.12.5

View file

@ -0,0 +1,34 @@
$(document).on('page:load', the_terms);
$(document).ready(the_terms);
function the_terms() {
var the_terms = $("#dossier_autorisation_donnees");
if(the_terms.size() == 0)
return;
check_value (the_terms);
the_terms.click(function () {
check_value (the_terms);
});
function check_value (the_terms){
if (the_terms.is(":checked")) {
$("#etape_suivante").removeAttr("disabled");
} else {
$("#etape_suivante").attr("disabled", "disabled");
}
}
}
function error_form_siret(invalid_siret){
$("input[type='submit']").removeClass('btn-success').addClass('btn-danger').val('Erreur SIRET');
$("#dossier_siret").addClass('input-error').val(invalid_siret).on('input', reset_form_siret);
}
function reset_form_siret(){
$("input[type='submit']").removeClass('btn-danger').addClass('btn-success').val('Valider');
$("#dossier_siret").removeClass('input-error');
}

View file

@ -186,7 +186,8 @@ div.pagination {
margin-bottom: 0px; margin-bottom: 0px;
} }
.alert.alert-success.move_up { .alert.alert-success.move_up,
.alert.alert-danger.siret{
position: absolute; position: absolute;
top: 0px; top: 0px;
left: 0; left: 0;

View file

@ -0,0 +1,29 @@
.etapes_menu{
h3 {
margin-left: 3%;
}
padding-right: 0 !important;
}
.etapes_informations {
padding-left: 0 !important;
}
.etape{
margin-bottom: 0px;
}
.etape_2{
.etapes_menu{
#dossier_siret{
width: 200px;
}
button{
margin-top: 8px;
}
}
.etapes_informations{
padding-top: 15px;
}
}

View file

@ -6,13 +6,6 @@
display: none; display: none;
} }
#dossier_siret {
margin-bottom: 10px;
margin-left: auto;
margin-right: auto;
width: 200px;
}
#titre_procedure { #titre_procedure {
margin-top: 3%; margin-top: 3%;
margin-bottom: 2%; margin-bottom: 2%;

View file

@ -83,6 +83,23 @@ class Admin::ProceduresController < AdminController
change_status({archived: params[:archive]}) change_status({archived: params[:archive]})
end end
def clone
@procedure = current_administrateur.procedures.find(params[:procedure_id])
new_procedure = @procedure.clone
if new_procedure
flash.notice = 'Procédure clonée'
redirect_to edit_admin_procedure_path(id: new_procedure.id)
else
flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe
render 'index'
end
rescue ActiveRecord::RecordNotFound
flash.alert = 'Procédure inéxistante'
redirect_to admin_procedures_path
end
def active_class def active_class
@active_class = 'active' @active_class = 'active'
end end

View file

@ -22,10 +22,11 @@ class CommentairesController < ApplicationController
end end
@commentaire.body = params['texte_commentaire'] @commentaire.body = params['texte_commentaire']
@commentaire.save unless flash.alert saved = false
saved = @commentaire.save unless flash.alert
if is_gestionnaire? if is_gestionnaire?
NotificationMailer.new_answer(@commentaire.dossier).deliver_now! NotificationMailer.new_answer(@commentaire.dossier).deliver_now! if saved
redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id']) redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id'])
elsif current_user.email != @commentaire.dossier.user.email elsif current_user.email != @commentaire.dossier.user.email
invite = Invite.where(dossier: @commentaire.dossier, user: current_user).first invite = Invite.where(dossier: @commentaire.dossier, user: current_user).first

View file

@ -6,7 +6,7 @@ class DemoController < ApplicationController
return redirect_to root_path if Rails.env.production? return redirect_to root_path if Rails.env.production?
smart_listing_create :procedures, smart_listing_create :procedures,
Procedure.where(archived: false), Procedure.where(archived: false, published: true),
partial: "demo/list", partial: "demo/list",
array: true array: true
end end

View file

@ -0,0 +1,32 @@
class Gestionnaires::PasswordsController < Devise::PasswordsController
# GET /resource/password/new
# def new
# super
# end
# POST /resource/password
# def create
# super
# end
# GET /resource/password/edit?reset_password_token=abcdef
# def edit
# super
# end
# PUT /resource/password
# def update
# super
# end
# protected
# def after_resetting_password_path_for(resource)
# super(resource)
# end
# The path used after sending reset password instructions
# def after_sending_reset_password_instructions_path_for(resource_name)
# super(resource_name)
# end
end

View file

@ -3,7 +3,7 @@ class Users::DossiersController < UsersController
helper SmartListing::Helper helper SmartListing::Helper
before_action :authenticate_user! before_action :authenticate_user!
before_action :check_siret, only: :create before_action :check_siret, only: :siret_informations
before_action only: [:show] do before_action only: [:show] do
authorized_routes? self.class authorized_routes? self.class
@ -25,50 +25,53 @@ class Users::DossiersController < UsersController
def new def new
procedure = Procedure.where(archived: false, published: true).find(params[:procedure_id]) procedure = Procedure.where(archived: false, published: true).find(params[:procedure_id])
@dossier = Dossier.new(procedure: procedure) dossier = Dossier.create(procedure: procedure, user: current_user, state: 'draft')
@siret = params[:siret] || current_user.siret siret = params[:siret] || current_user.siret
update_current_user_siret! siret unless siret.nil?
redirect_to users_dossier_path(id: dossier.id)
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
error_procedure error_procedure
end end
def show def show
@facade = DossierFacades.new params[:id], current_user.email @facade = facade
@siret = current_user.siret unless current_user.siret.nil?
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found') flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for users_dossiers_path redirect_to url_for users_dossiers_path
end end
def create def siret_informations
entreprise_adapter = SIADE::EntrepriseAdapter.new(siren) @facade = facade params[:dossier_id]
dossier = Dossier.create(user: current_user, update_current_user_siret! siret
state: 'draft',
procedure_id: create_params[:procedure_id],
mandataire_social: mandataire_social?(entreprise_adapter.mandataires_sociaux))
entreprise = dossier.create_entreprise(entreprise_adapter.to_params) DossierService.new(@facade.dossier, siret, current_user.france_connect_information).dossier_informations!
entreprise.create_rna_information(SIADE::RNAAdapter.new(siret).to_params) @facade = facade params[:dossier_id]
render '/dossiers/new_siret', formats: 'js'
etablissement = dossier.create_etablissement(SIADE::EtablissementAdapter.new(siret).to_params
.merge({entreprise_id: entreprise.id}))
etablissement.exercices.create(SIADE::ExercicesAdapter.new(siret).to_params)
redirect_to url_for(controller: :dossiers, action: :show, id: dossier.id)
rescue RestClient::ResourceNotFound rescue RestClient::ResourceNotFound
errors_valid_siret errors_valid_siret
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found') flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(controller: :siret) redirect_to url_for users_dossiers_path
end
def change_siret
Dossier.find(params[:dossier_id]).reset!
@facade = facade params[:dossier_id]
render '/dossiers/new_siret', formats: :js
end end
def update def update
@facade = DossierFacades.new params[:id], current_user.email @facade = facade params[:dossier][:id]
if checked_autorisation_donnees? if checked_autorisation_donnees?
@facade.dossier.update_attributes(update_params) @facade.dossier.update_attributes(update_params)
@ -79,8 +82,8 @@ class Users::DossiersController < UsersController
redirect_to url_for(controller: :description, action: :show, dossier_id: @facade.dossier.id) redirect_to url_for(controller: :description, action: :show, dossier_id: @facade.dossier.id)
end end
else else
flash.now.alert = 'Les conditions sont obligatoires.' flash.alert = 'Les conditions sont obligatoires.'
render 'show' redirect_to users_dossier_path(id: @facade.dossier.id)
end end
end end
@ -132,7 +135,9 @@ class Users::DossiersController < UsersController
def errors_valid_siret def errors_valid_siret
flash.alert = t('errors.messages.invalid_siret') flash.alert = t('errors.messages.invalid_siret')
redirect_to url_for new_users_dossiers_path(procedure_id: create_params[:procedure_id]) @facade = facade params[:dossier_id]
render '/dossiers/new_siret', formats: :js, locals: {invalid_siret: siret}
end end
def update_params def update_params
@ -147,28 +152,21 @@ class Users::DossiersController < UsersController
create_params[:siret] create_params[:siret]
end end
def siren
siret[0..8]
end
def create_params def create_params
params.require(:dossier).permit(:siret, :procedure_id) params.require(:dossier).permit(:siret)
end end
def error_procedure def error_procedure
flash.alert = t('errors.messages.procedure_not_found') flash.alert = t('errors.messages.procedure_not_found')
redirect_to url_for users_dossiers_path redirect_to url_for users_dossiers_path
end end
def mandataire_social? mandataires_list def update_current_user_siret! siret
unless current_user.france_connect_information.nil? current_user.update_attributes(siret: siret)
mandataires_list.each do |mandataire|
return true if mandataire[:nom].upcase == current_user.family_name.upcase &&
mandataire[:prenom].upcase == current_user.given_name.upcase &&
mandataire[:date_naissance_timestamp] == current_user.birthdate.to_time.to_i
end
end end
false def facade id = params[:id]
DossierFacades.new id, current_user.email
end end
end end

View file

@ -15,7 +15,7 @@ class DossierFacades
end end
def entreprise def entreprise
@dossier.entreprise.decorate @dossier.entreprise.decorate unless @dossier.entreprise.nil?
end end
def etablissement def etablissement

View file

@ -193,4 +193,10 @@ class Dossier < ActiveRecord::Base
entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map {|k, v| ["entreprise.#{k}", v] }.to_h entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map {|k, v| ["entreprise.#{k}", v] }.to_h
dossier_attr.merge(etablissement_attr).merge(entreprise_attr) dossier_attr.merge(etablissement_attr).merge(entreprise_attr)
end end
def reset!
entreprise.destroy unless entreprise.nil?
update_attributes(autorisation_donnees: false)
end
end end

View file

@ -1,5 +1,5 @@
class Entreprise < ActiveRecord::Base class Entreprise < ActiveRecord::Base
belongs_to :dossier belongs_to :dossier
has_one :etablissement has_one :etablissement, dependent: :destroy
has_one :rna_information has_one :rna_information, dependent: :destroy
end end

View file

@ -2,7 +2,7 @@ class Etablissement < ActiveRecord::Base
belongs_to :dossier belongs_to :dossier
belongs_to :entreprise belongs_to :entreprise
has_many :exercices has_many :exercices, dependent: :destroy
def geo_adresse def geo_adresse
[numero_voie, type_voie, nom_voie, complement_adresse, code_postal, localite].join(' ') [numero_voie, type_voie, nom_voie, complement_adresse, code_postal, localite].join(' ')

View file

@ -58,4 +58,11 @@ class Procedure < ActiveRecord::Base
published? published?
end end
def clone
procedure = self.deep_clone(include: [ :types_de_piece_justificative, :types_de_champ, :module_api_carto ])
procedure.archived = false
procedure.published = false
return procedure if procedure.save
end
end end

View file

@ -0,0 +1,68 @@
class DossierService
def initialize dossier, siret, france_connect_information
@dossier = dossier
@siret = siret
@france_connect_information = france_connect_information
end
def dossier_informations!
entreprise_thread = Thread.new {
@entreprise_adapter = SIADE::EntrepriseAdapter.new(DossierService.siren @siret)
@dossier.create_entreprise(@entreprise_adapter.to_params)
}
etablissement_thread = Thread.new {
@etablissement_adapter = SIADE::EtablissementAdapter.new(@siret)
@dossier.create_etablissement(@etablissement_adapter.to_params)
}
rna_thread = Thread.new {
@rna_adapter = SIADE::RNAAdapter.new(@siret)
sleep(0.1) while entreprise_thread.alive?
@dossier.entreprise.create_rna_information(@rna_adapter.to_params)
}
exercices_thread = Thread.new {
@exercices_adapter = SIADE::ExercicesAdapter.new(@siret)
sleep(0.1) while etablissement_thread.alive?
@dossier.etablissement.exercices.create(@exercices_adapter.to_params)
}
sleep(0.1) while entreprise_thread.alive? ||
etablissement_thread.alive? ||
rna_thread.alive? ||
exercices_thread.alive?
@dossier.update_attributes(mandataire_social: mandataire_social?(@entreprise_adapter.mandataires_sociaux))
@dossier.etablissement.update_attributes(entreprise: @dossier.entreprise)
@dossier
end
def self.siren siret
siret[0..8]
end
private
def mandataire_social? mandataires_list
unless @france_connect_information.nil?
mandataires_list.each do |mandataire|
return true if mandataire[:nom].upcase == @france_connect_information.family_name.upcase &&
mandataire[:prenom].upcase == @france_connect_information.given_name.upcase &&
mandataire[:date_naissance_timestamp] == @france_connect_information.birthdate.to_time.to_i
end
end
false
end
end

View file

@ -3,6 +3,7 @@
%thead %thead
%th#ID= smart_listing.sortable 'ID', 'id' %th#ID= smart_listing.sortable 'ID', 'id'
%th#libelle= smart_listing.sortable 'Libellé', 'libelle' %th#libelle= smart_listing.sortable 'Libellé', 'libelle'
%th#lien Actions
- @procedures.each do |procedure| - @procedures.each do |procedure|
- procedure = procedure.decorate - procedure = procedure.decorate
@ -10,6 +11,7 @@
%td.col-md-1.col-lg-1= procedure.id %td.col-md-1.col-lg-1= procedure.id
%td.col-md-6.col-lg-6 %td.col-md-6.col-lg-6
= link_to(procedure.libelle, "/admin/procedures/#{procedure.id}") = link_to(procedure.libelle, "/admin/procedures/#{procedure.id}")
%td= link_to('cloner', admin_procedure_clone_path(procedure.id), 'data-method' => :put, class: 'btn-xs btn-primary')
= smart_listing.paginate = smart_listing.paginate
= smart_listing.pagination_per_page_links = smart_listing.pagination_per_page_links

View file

@ -4,6 +4,7 @@
%th#ID= smart_listing.sortable 'ID', 'id' %th#ID= smart_listing.sortable 'ID', 'id'
%th#libelle= smart_listing.sortable 'Libellé', 'libelle' %th#libelle= smart_listing.sortable 'Libellé', 'libelle'
%th#lien Lien %th#lien Lien
%th#lien Actions
- @procedures.each do |procedure| - @procedures.each do |procedure|
- procedure = procedure.decorate - procedure = procedure.decorate
@ -12,6 +13,7 @@
%td.col-md-6.col-lg-6 %td.col-md-6.col-lg-6
= link_to(procedure.libelle, "/admin/procedures/#{procedure.id}") = link_to(procedure.libelle, "/admin/procedures/#{procedure.id}")
%td= link_to procedure.lien, procedure.lien %td= link_to procedure.lien, procedure.lien
%td= link_to('cloner', admin_procedure_clone_path(procedure.id), 'data-method' => :put, class: 'btn-xs btn-primary')
= smart_listing.paginate = smart_listing.paginate
= smart_listing.pagination_per_page_links = smart_listing.pagination_per_page_links

View file

@ -1,13 +1,21 @@
.container#recap_info_entreprise #users_siret_index
%h2 Récapitulatif de vos informations <em id="insee_infogreffe" class='small'>(récupérées auprès de l'INSEE et d'INFOGREFFE)</em>
%br .row.etape.etape_1
= render partial: '/dossiers/etapes/etape1'
.row.etape.etape_2
= render partial: '/dossiers/etapes/etape2'
-#- if @facade.procedure.module_api_carto.use_api_carto?
-# .row.etape.etape_3
-# .etape.etapes_menu.col-md-3.col-lg-3
-# %h3
-# 3 - Ma zone d'intervention
-# .etape.etapes_informations.col-md-9.col-lg-9
-#
-#.row.etape.etape_4
-# .etape.etapes_menu.col-md-3.col-lg-3
-# %h3
-# = "#{@facade.procedure.module_api_carto.use_api_carto? ? '4' : '3'} - Mon dossier"
-# .etape.etapes_informations.col-md-9.col-lg-9
%div.row
= render partial: '/dossiers/infos_entreprise'
%br
= form_for @facade.dossier, url: { controller: '/users/dossiers', action: :update } do |f|
%label{ style:'font-weight:normal' }
= f.check_box :autorisation_donnees
J'autorise les décideurs publics à vérifier les informations de mon organisation auprès des administrations concernées. Ces informations resteront strictement confidentielles.
%br
= f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float:right', id: 'etape_suivante'

View file

@ -0,0 +1,19 @@
.etape.etapes_menu.col-md-3.col-lg-3
%h3
Ma procédure
%br
.center
- if @facade.procedure.euro_flag
#euro_flag.flag
=image_tag('drapeau_europe.png')
#logo_procedure.flag
=image_tag( @facade.procedure.decorate.logo_img )
.etape.etapes_informations.col-md-9.col-lg-9
.row
%h2#titre_procedure.text-info
= @facade.procedure.libelle
%p{style:'width: 95%;'}
= h @facade.procedure.description.html_safe

View file

@ -0,0 +1,39 @@
.etape.etapes_menu.col-md-3.col-lg-3
%h3
Mes informations
%br
- unless @facade.entreprise.nil?
.center{style:'margin-left: -5%'}
Vous êtes authentifié avec le SIRET
%h3.text-success
= @facade.etablissement.siret
= form_for @facade.dossier, url: users_dossier_change_siret_path(dossier_id: @facade.dossier.id), method: :put, remote: true do |f|
= f.submit 'Changer de SIRET', class: %w(btn btn-xs btn-primary)
.etape.etapes_informations.col-md-9.col-lg-9
.row
- if @facade.entreprise.nil?
#new_siret{style:'margin-left: 20%; margin-top: 5%'}
= form_for @facade.dossier, html: {class: 'form-inline'}, url: users_dossier_siret_informations_path(dossier_id: @facade.dossier.id), method: :post, remote: true do |f|
.form-group.form-group-lg
= f.text_field :siret, class: "form-control", placeholder: "Entrez votre Siret", value: @siret
= f.hidden_field :dossier_id, value: @facade.dossier.id
= f.submit 'Valider', class: %w(btn btn-lg btn-success), data: { disable_with: "Recherche en cours ..." }
- else
#recap_info_entreprise
= render partial: '/dossiers/infos_entreprise'
%p#insee_infogreffe{style:'color:grey; float:right'}
%i
Informations récupérées auprès de l'INSEE et d'INFOGREFFE
%br
= form_for @facade.dossier, url: { controller: '/users/dossiers', action: :update } do |f|
= f.hidden_field :id
%label{ style:'font-weight:normal' }
= f.check_box :autorisation_donnees
J'autorise les décideurs publics à vérifier les informations de mon organisation auprès des administrations concernées. Ces informations resteront strictement confidentielles.
%br
= f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float:right', id: 'etape_suivante', disabled: :disabled

View file

@ -0,0 +1,7 @@
$('.row.etape.etape_2').html("<%= escape_javascript(render partial: '/dossiers/etapes/etape2', locals: { facade: @facade } ) %>");
the_terms();
<% unless flash.empty? %>
error_form_siret('<%= invalid_siret %>');
<% end %>
<% flash.clear %>

View file

@ -0,0 +1,31 @@
= devise_error_messages!
#form_login
= image_tag('logo-tps.png')
%br
%h2#gestionnaire_login Changement de mot de passe
%br
%br
#new_user
= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f|
= f.hidden_field :reset_password_token
%h4
= f.label 'Nouveau mot de passe'
.input-group
.input-group-addon
%span.glyphicon.glyphicon-asterisk
= f.password_field :password, autofocus: true, autocomplete: "off", class: 'form-control'
%br
%h4
= f.label 'Retaper le mot de passe'
.input-group
.input-group-addon
%span.glyphicon.glyphicon-asterisk
= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control'
%br
%br
.actions
= f.submit "Changer", class:'btn btn-primary'
%br

View file

@ -0,0 +1,22 @@
= devise_error_messages!
#form_login
= image_tag('logo-tps.png')
%br
%h2#gestionnaire_login Mot de passe oublié
%br
%br
#new_user
= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f|
%h4
= f.label :email
.input-group
.input-group-addon
%span.glyphicon.glyphicon-user
= f.email_field :email, class: 'form-control', placeholder: 'Email'
%br
%br
.actions
= f.submit "Renvoyer", class:'btn btn-primary'
%br

View file

@ -26,3 +26,4 @@
.actions .actions
= f.submit "Se connecter", class:'btn btn-primary' = f.submit "Se connecter", class:'btn btn-primary'
%br %br
= render "gestionnaires/shared/links"

View file

@ -0,0 +1,2 @@
<%= link_to "Mot de passe oublié ?", new_password_path(resource_name) %><br />

View file

@ -1,11 +0,0 @@
- if @dossier.procedure.euro_flag
#euro_flag.flag
=image_tag('drapeau_europe.png')
#logo_procedure.flag
=image_tag( @dossier.procedure.decorate.logo_img )
%h2#titre_procedure.text-info
= @dossier.procedure.libelle
%p
= h @dossier.procedure.description.html_safe

View file

@ -1,11 +0,0 @@
.container.center#users_siret_index
.row
%p.lead{id: 'pro_section', style:'padding-top: 120px'}
= render partial: 'title_procedure'
%br
= form_for @dossier, url: {controller: 'users/dossiers', action: :create}, method: :post do |f|
.form-group.form-group-lg
= f.text_field :siret, class: "form-control", placeholder: "Entrez votre Siret", value: @siret
= f.hidden_field :procedure_id
= f.submit 'Commencer', class: %w(btn btn-lg btn-success), style: 'margin-top:20px;'

View file

@ -2,7 +2,20 @@
%br %br
- if @dossier - if @dossier
= link_to 'X', users_no_procedure_url, class: 'btn btn-xs', style:'float: right' = link_to 'X', users_no_procedure_url, class: 'btn btn-xs', style:'float: right'
= render partial: 'users/dossiers/title_procedure'
- if @dossier.procedure.euro_flag
#euro_flag.flag
=image_tag('drapeau_europe.png')
#logo_procedure.flag
=image_tag( @dossier.procedure.decorate.logo_img )
%h2#titre_procedure.text-info
= @dossier.procedure.libelle
%p
= h @dossier.procedure.description.html_safe
- else - else
= image_tag('logo-tps.png', {id: 'logo_tps'}) = image_tag('logo-tps.png', {id: 'logo_tps'})
%br %br

View file

@ -9,8 +9,9 @@ Rails.application.routes.draw do
}, skip: [:password, :registrations] }, skip: [:password, :registrations]
devise_for :gestionnaires, controllers: { devise_for :gestionnaires, controllers: {
sessions: 'gestionnaires/sessions' sessions: 'gestionnaires/sessions',
}, skip: [:password, :registrations] passwords: 'gestionnaires/passwords'
}, skip: [:registrations]
devise_for :users, controllers: { devise_for :users, controllers: {
sessions: 'users/sessions', sessions: 'users/sessions',
@ -25,6 +26,8 @@ Rails.application.routes.draw do
devise_scope :gestionnaire do devise_scope :gestionnaire do
get '/gestionnaires/sign_in/demo' => 'gestionnaires/sessions#demo' get '/gestionnaires/sign_in/demo' => 'gestionnaires/sessions#demo'
get '/gestionnaires/edit' => 'gestionnaires/registrations#edit', :as => 'edit_gestionnaires_registration'
put '/gestionnaires' => 'gestionnaires/registrations#update', :as => 'gestionnaires_registration'
end end
devise_scope :administrateur do devise_scope :administrateur do
@ -73,6 +76,9 @@ Rails.application.routes.draw do
post '/carte' => 'carte#save' post '/carte' => 'carte#save'
put '/archive' => 'dossiers#archive' put '/archive' => 'dossiers#archive'
post '/siret_informations' => 'dossiers#siret_informations'
put '/change_siret' => 'dossiers#change_siret'
end end
resource :dossiers resource :dossiers
end end
@ -97,6 +103,7 @@ Rails.application.routes.draw do
put 'archive' => 'procedures#archive', as: :archive put 'archive' => 'procedures#archive', as: :archive
put 'publish' => 'procedures#publish', as: :publish put 'publish' => 'procedures#publish', as: :publish
put 'clone' => 'procedures#clone', as: :clone
resource :accompagnateurs, only: [:show, :update] resource :accompagnateurs, only: [:show, :update]

View file

@ -265,4 +265,35 @@ describe Admin::ProceduresController, type: :controller do
it { expect(flash[:alert]).to have_content 'Procédure inéxistante' } it { expect(flash[:alert]).to have_content 'Procédure inéxistante' }
end end
end end
describe 'PUT #clone' do
let!(:procedure) { create(:procedure, administrateur: admin) }
subject { put :clone, procedure_id: procedure.id }
it { expect{ subject }.to change(Procedure, :count).by(1) }
context 'when admin is the owner of the procedure' do
before do
subject
end
it 'creates a new procedure and redirect to it' do
expect(response).to redirect_to edit_admin_procedure_path(id: Procedure.last.id)
expect(flash[:notice]).to have_content 'Procédure clonée'
end
end
context 'when admin is not the owner of the procedure' do
let(:admin_2) { create(:administrateur) }
before do
sign_out admin
sign_in admin_2
subject
end
it { expect(response).to redirect_to :admin_procedures }
it { expect(flash[:alert]).to have_content 'Procédure inéxistante' }
end
end
end end

View file

@ -91,5 +91,17 @@ describe Backoffice::CommentairesController, type: :controller do
end end
end end
end end
describe 'comment cannot be saved' do
before do
allow_any_instance_of(Commentaire).to receive(:save).and_return(false)
end
it 'Notification email is not sent' do
expect(NotificationMailer).not_to receive(:new_answer)
expect(NotificationMailer).not_to receive(:deliver_now!)
post :create, dossier_id: dossier_id, texte_commentaire: texte_commentaire
end
end
end end
end end

View file

@ -5,18 +5,20 @@ describe Users::DossiersController, type: :controller do
let(:procedure) { create(:procedure, :published) } let(:procedure) { create(:procedure, :published) }
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } let(:dossier) { create(:dossier, user: user, procedure: procedure) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:siret_not_found) { 999_999_999_999 } let(:siret_not_found) { 999_999_999_999 }
let(:rna_status) { 404 } let(:rna_status) { 404 }
let(:rna_body) { '' } let(:rna_body) { '' }
let(:user) { create :user }
let(:exercices_status) { 200 } let(:exercices_status) { 200 }
let(:exercices_body) { File.read('spec/support/files/exercices.json') } let(:exercices_body) { File.read('spec/support/files/exercices.json') }
let(:siren) { dossier.siren } let(:siren) { '440117620' }
let(:siret) { dossier.siret } let(:siret) { '44011762001530' }
let(:siret_with_whitespaces) { '440 1176 2001 530' } let(:siret_with_whitespaces) { '440 1176 2001 530' }
let(:bad_siret) { 1 } let(:bad_siret) { 1 }
@ -55,10 +57,66 @@ describe Users::DossiersController, type: :controller do
context 'when procedure_id is valid' do context 'when procedure_id is valid' do
context 'when user is logged in' do context 'when user is logged in' do
before do before do
sign_in create(:user) sign_in user
end end
it { is_expected.to have_http_status(:success) } it { is_expected.to have_http_status(302) }
it { is_expected.to redirect_to users_dossier_path(id: Dossier.last) }
it { expect { subject }.to change(Dossier, :count).by 1 }
describe 'save user siret' do
context 'when user have not a saved siret' do
context 'when siret is present on request' do
subject { get :new, procedure_id: procedure_id, siret: siret }
before do
subject
user.reload
end
it { expect(user.siret).to eq siret }
end
context 'when siret is not present on the request' do
before do
subject
user.reload
end
it { expect(user.siret).to eq nil }
end
end
context 'when user have a saved siret' do
before do
user.siret = '53029478400026'
user.save
user.reload
end
context 'when siret is present on request' do
subject { get :new, procedure_id: procedure_id, siret: siret }
before do
subject
user.reload
end
it { expect(user.siret).to eq siret }
end
context 'when siret is not present on the request' do
before do
subject
user.reload
end
it { expect(user.siret).to eq '53029478400026' }
end
end
end
context 'when procedure is archived' do context 'when procedure is archived' do
let(:procedure) { create(:procedure, archived: 'true') } let(:procedure) { create(:procedure, archived: 'true') }
@ -68,6 +126,7 @@ describe Users::DossiersController, type: :controller do
end end
context 'when user is not logged' do context 'when user is not logged' do
it { is_expected.to have_http_status(302) } it { is_expected.to have_http_status(302) }
it { is_expected.to redirect_to new_user_session_path }
end end
end end
@ -75,7 +134,7 @@ describe Users::DossiersController, type: :controller do
let(:procedure_id) { 0 } let(:procedure_id) { 0 }
before do before do
sign_in create(:user) sign_in user
end end
it { is_expected.to redirect_to users_dossiers_path } it { is_expected.to redirect_to users_dossiers_path }
@ -85,7 +144,7 @@ describe Users::DossiersController, type: :controller do
let(:procedure) { create(:procedure, published: false) } let(:procedure) { create(:procedure, published: false) }
before do before do
sign_in create(:user) sign_in user
end end
it { is_expected.to redirect_to users_dossiers_path } it { is_expected.to redirect_to users_dossiers_path }
@ -93,7 +152,7 @@ describe Users::DossiersController, type: :controller do
end end
end end
describe 'POST #create' do describe 'POST #siret_informations' do
before do before do
stub_request(:get, "https://api-dev.apientreprise.fr/v2/etablissements/#{siret_not_found}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/v2/etablissements/#{siret_not_found}?token=#{SIADETOKEN}")
.to_return(status: 404, body: 'fake body') .to_return(status: 404, body: 'fake body')
@ -109,6 +168,8 @@ describe Users::DossiersController, type: :controller do
stub_request(:get, "https://api-dev.apientreprise.fr/v1/associations/#{siret}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/v1/associations/#{siret}?token=#{SIADETOKEN}")
.to_return(status: rna_status, body: rna_body) .to_return(status: rna_status, body: rna_body)
dossier
end end
describe 'dossier attributs' do describe 'dossier attributs' do
@ -119,10 +180,10 @@ describe Users::DossiersController, type: :controller do
sign_in user sign_in user
end end
subject { post :create, dossier: {siret: example_siret, procedure_id: Procedure.last} } subject { post :siret_informations, dossier_id: dossier.id, dossier: {siret: example_siret} }
it 'create a dossier' do it 'create a dossier' do
expect { subject }.to change { Dossier.count }.by(1) expect { subject }.to change { Dossier.count }.by(0)
end end
it 'creates entreprise' do it 'creates entreprise' do
@ -238,27 +299,32 @@ describe Users::DossiersController, type: :controller do
context 'with non existant siret' do context 'with non existant siret' do
before do before do
sign_in create(:user) sign_in user
subject
end end
let(:siret_not_found) { '11111111111111' } let(:siret_not_found) { '11111111111111' }
subject { post :create, dossier: {siret: siret_not_found, procedure_id: procedure.id} } subject { post :siret_informations, dossier_id: dossier.id, dossier: {siret: siret_not_found} }
it 'does not create new dossier' do it 'does not create new dossier' do
expect { subject }.not_to change { Dossier.count } expect { subject }.not_to change { Dossier.count }
end end
it 'redirects to show' do it { expect(response.status).to eq 200 }
expect(subject).to redirect_to new_users_dossiers_path(procedure_id: procedure_id) it { expect(flash.alert).to eq 'Le siret est incorrect' }
end it { expect(response.to_a[2]).to be_an_instance_of ActionDispatch::Response::RackBody }
end end
end end
end end
describe 'PUT #update' do describe 'PUT #update' do
subject { put :update, id: dossier_id, dossier: {id: dossier_id, autorisation_donnees: autorisation_donnees} }
before do before do
sign_in dossier.user sign_in dossier.user
put :update, id: dossier_id, dossier: {autorisation_donnees: autorisation_donnees} subject
end end
context 'when Checkbox is checked' do context 'when Checkbox is checked' do
let(:autorisation_donnees) { '1' } let(:autorisation_donnees) { '1' }
@ -272,7 +338,7 @@ describe Users::DossiersController, type: :controller do
let(:procedure) { create(:procedure, :with_api_carto) } let(:procedure) { create(:procedure, :with_api_carto) }
before do before do
put :update, id: dossier_id, dossier: {autorisation_donnees: autorisation_donnees} subject
end end
it 'redirects to carte' do it 'redirects to carte' do
expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier.id) expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier.id)
@ -295,6 +361,25 @@ describe Users::DossiersController, type: :controller do
dossier.reload dossier.reload
expect(dossier.autorisation_donnees).to be_falsy expect(dossier.autorisation_donnees).to be_falsy
end end
it { is_expected.to redirect_to users_dossier_path(id: dossier.id) }
end
end
describe 'PUT #change_siret' do
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
subject { put :change_siret, dossier_id: dossier.id }
before do
sign_in user
end
it { expect(subject.status).to eq 200 }
it 'function dossier.reset! is call' do
expect_any_instance_of(Dossier).to receive(:reset!)
subject
end end
end end

View file

@ -0,0 +1,8 @@
FactoryGirl.define do
factory :exercice do
ca '12345678'
dateFinExercice "2014-12-30 23:00:00"
date_fin_exercice_timestamp 1419980400
association :etablissement, factory: [:etablissement]
end
end

View file

@ -0,0 +1,11 @@
FactoryGirl.define do
factory :rna_information do
association_id "W072000535"
titre "ASSOCIATION POUR LA PROMOTION DE SPECTACLES AU CHATEAU DE ROCHEMAURE"
objet "mise en oeuvre et réalisation de spectacles au chateau de rochemaure"
date_creation "1990-04-24"
date_declaration "2014-11-28"
date_publication "1990-05-16"
association :entreprise, factory: [:entreprise]
end
end

View file

@ -6,7 +6,7 @@ feature 'user path for dossier creation' do
let(:siret) { '53272417600013' } let(:siret) { '53272417600013' }
let(:siren) { siret[0...9] } let(:siren) { siret[0...9] }
context 'user arrives on siret page' do context 'user arrives on siret page', js: true do
before do before do
visit new_users_dossiers_path(procedure_id: procedure.id) visit new_users_dossiers_path(procedure_id: procedure.id)
end end
@ -39,11 +39,23 @@ feature 'user path for dossier creation' do
.to_return(status: 404, body: '') .to_return(status: 404, body: '')
page.find_by_id('dossier_siret').set siret page.find_by_id('dossier_siret').set siret
page.click_on 'Commencer' page.click_on 'Valider'
end end
scenario 'user is on page recap info entreprise' do scenario 'user is on page recap info entreprise' do
expect(page).to have_css('#recap_info_entreprise') expect(page).to have_css('#recap_info_entreprise')
end end
context 'when user would like change siret' do
before do
page.click_on('Changer de SIRET')
end
scenario 'redirects to siret page' do
expect(page).to have_css('#dossier_siret')
end
end
context 'when validating info entreprise recap page' do context 'when validating info entreprise recap page' do
before do before do
page.check('dossier_autorisation_donnees') page.check('dossier_autorisation_donnees')

View file

@ -6,7 +6,7 @@ feature 'user arrive on siret page' do
let(:siret) { '42149333900020' } let(:siret) { '42149333900020' }
let(:siren) { siret[0...9] } let(:siren) { siret[0...9] }
context 'when user is not logged in' do context 'when user is not logged in', js: true do
before do before do
visit new_users_dossiers_path(procedure_id: procedure.id) visit new_users_dossiers_path(procedure_id: procedure.id)
end end
@ -22,7 +22,7 @@ feature 'user arrive on siret page' do
end end
end end
scenario 'he is redirected to siret page to enter a siret' do scenario 'he is redirected to siret page to enter a siret' do
expect(page).to have_css('#pro_section') expect(page).to have_css('#new_siret')
end end
context 'when enter a siret' do context 'when enter a siret' do
before do before do
@ -36,7 +36,7 @@ feature 'user arrive on siret page' do
.to_return(status: 404, body: '') .to_return(status: 404, body: '')
page.find_by_id('dossier_siret').set siret page.find_by_id('dossier_siret').set siret
page.click_on 'Commencer' page.click_on 'Valider'
end end
scenario 'he is redirected to recap info entreprise page' do scenario 'he is redirected to recap info entreprise page' do
expect(page).to have_css('#recap_info_entreprise') expect(page).to have_css('#recap_info_entreprise')

View file

@ -563,4 +563,35 @@ describe Dossier do
it { expect(subject['entreprise.prenom']).to be_nil } it { expect(subject['entreprise.prenom']).to be_nil }
end end
describe '#reset!' do
let!(:dossier) { create :dossier, :with_entreprise, autorisation_donnees: true }
let!(:rna_information) { create :rna_information, entreprise: dossier.entreprise }
let!(:exercice) { create :exercice, etablissement: dossier.etablissement }
subject { dossier.reset! }
it { expect(dossier.entreprise).not_to be_nil }
it { expect(dossier.etablissement).not_to be_nil }
it { expect(dossier.etablissement.exercices).not_to be_empty }
it { expect(dossier.etablissement.exercices.size).to eq 1 }
it { expect(dossier.entreprise.rna_information).not_to be_nil }
it { expect(dossier.autorisation_donnees).to be_truthy }
it { expect{subject}.to change(RNAInformation, :count).by(-1) }
it { expect{subject}.to change(Exercice, :count).by(-1) }
it { expect{subject}.to change(Entreprise, :count).by(-1) }
it { expect{subject}.to change(Etablissement, :count).by(-1) }
context 'when method reset! is call' do
before do
subject
dossier.reload
end
it { expect(dossier.entreprise).to be_nil }
it { expect(dossier.etablissement).to be_nil }
it { expect(dossier.autorisation_donnees).to be_falsey }
end
end
end end

View file

@ -122,4 +122,44 @@ describe Procedure do
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end end
end end
describe 'clone' do
let(:archived) { false }
let(:published) { false }
let(:procedure) { create(:procedure, archived: archived, published: published) }
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
let!(:piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) }
let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
subject { procedure.clone }
it 'should duplicate specific objects with different id' do
expect(subject.id).not_to eq(procedure.id)
expect(subject).to have_same_attributes_as(procedure)
expect(subject.module_api_carto).to have_same_attributes_as(procedure.module_api_carto)
subject.types_de_champ.zip(procedure.types_de_champ).each do |stc, ptc|
expect(stc).to have_same_attributes_as(ptc)
end
subject.types_de_piece_justificative.zip(procedure.types_de_piece_justificative).each do |stc, ptc|
expect(stc).to have_same_attributes_as(ptc)
end
end
it 'should not duplicate specific related objects' do
expect(subject.dossiers).to eq([])
expect(subject.gestionnaires).to eq([])
expect(subject.assign_to).to eq([])
end
describe 'procedure status is reset' do
let(:archived) { true }
let(:published) { true }
it 'sets published and archived to false' do
expect(subject.archived).to be_falsey
expect(subject.published).to be_falsey
end
end
end
end end

View file

@ -113,4 +113,11 @@ RSpec.configure do |config|
end end
end end
} }
RSpec::Matchers.define :have_same_attributes_as do |expected|
match do |actual|
ignored = [:id, :procedure_id, :updated_at, :created_at]
actual.attributes.with_indifferent_access.except(*ignored) == expected.attributes.with_indifferent_access.except(*ignored)
end
end
end end

View file

@ -9,6 +9,7 @@ describe 'dossiers/show.html.haml', type: :view do
render render
end end
it 'have autorisation_donnees check box' do it 'have autorisation_donnees check box' do
expect(rendered).to have_css('#dossier_autorisation_donnees') expect(rendered).to have_css('#dossier_autorisation_donnees')
end end

View file

@ -1,49 +0,0 @@
require 'spec_helper'
describe 'users/dossiers/new.html.haml', type: :view, vcr: { cassette_name: 'user_dossier_new_html' } do
let(:user) { create(:user) }
let(:euro_flag) { false }
let(:cerfa_flag) { false }
let(:logo) { '' }
let(:procedure) { create(:procedure, euro_flag: euro_flag, cerfa_flag: cerfa_flag, logo: logo) }
let!(:dossier) { create(:dossier, procedure: procedure, user: user).decorate }
before do
sign_in user
assign(:dossier, dossier.decorate)
render
end
subject { rendered }
it { is_expected.to have_css('#users_siret_index') }
describe 'euro flag' do
context 'euro flag is not present' do
it { is_expected.not_to have_css('#euro_flag.flag') }
end
context 'euro flag is present' do
let(:euro_flag) { true }
it { is_expected.to have_css('#euro_flag.flag') }
end
end
describe 'logo procedure' do
context 'procedure have no logo' do
it 'TPS logo is present' do
is_expected.to match(/src="\/assets\/logo-tps-.*\.png"/)
end
end
context 'procedure have logo' do
# let(:logo) { fixture_file_upload('spec/support/files/logo_test_procedure.png', 'image/png') }
let(:logo) { File.new(File.join(::Rails.root.to_s, "/spec/support/files", "logo_test_procedure.png")) }
it 'Procedure logo is present' do
is_expected.to have_css("img[src='#{procedure.logo}']")
end
end
end
end