Merge branch 'dev'

This commit is contained in:
Mathieu Magnin 2017-11-29 11:24:39 +01:00
commit dcbbe9a914
60 changed files with 743 additions and 165 deletions

View file

@ -50,6 +50,7 @@ gem 'rest-client'
gem 'clamav-client', require: 'clamav/client'
gem 'carrierwave'
gem 'carrierwave-i18n'
gem 'copy_carrierwave_file'
gem 'fog'
gem 'fog-openstack'

View file

@ -96,6 +96,7 @@ GEM
json (>= 1.7)
mime-types (>= 1.16)
mimemagic (>= 0.3.0)
carrierwave-i18n (0.2.0)
chartkick (2.2.1)
chunky_png (1.3.8)
clamav-client (3.1.0)
@ -683,6 +684,7 @@ DEPENDENCIES
byebug
capybara
carrierwave
carrierwave-i18n
chartkick
chunky_png
clamav-client

View file

@ -0,0 +1,8 @@
$(document).on("click", "body", function () {
$(".print-menu").removeClass("open fade-in-down");
});
TPS.togglePrintMenu = function(event) {
event.stopPropagation();
$(".print-menu").toggleClass("open fade-in-down");
}

View file

@ -30,3 +30,58 @@
font-size: 14px;
line-height: 20px;
}
.print-menu-opener {
position: relative;
}
.print-menu {
display: none;
position: absolute;
right: 0;
top: 45px;
font-size: 14px;
background: #FFFFFF;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
border: 1px solid $border-grey;
min-width: 270px;
max-width: 340px;
z-index: 20;
&.open {
display: block;
}
li {
border-bottom: 1px solid $border-grey;
&:last-child {
border-bottom: none;
}
.menu-item {
align-items: center;
padding: 14px;
color: $grey;
overflow: hidden;
text-overflow: ellipsis;
img {
margin-right: 14px;
}
}
.menu-link {
display: flex;
color: $black;
&:hover {
background: $light-grey;
}
}
}
}
.print-header {
display: none;
}

View file

@ -44,7 +44,7 @@
}
}
&.success {
&.accepted {
color: #FFFFFF;
border-color: $green;
background-color: $green;
@ -55,6 +55,28 @@
}
}
&.without-continuation {
color: #FFFFFF;
border-color: $black;
background-color: $black;
&:hover {
color: $black;
background-color: #FFFFFF;
}
}
&.refused {
color: #FFFFFF;
border-color: $dark-red;
background-color: $dark-red;
&:hover {
color: $dark-red;
background-color: #FFFFFF;
}
}
&.large {
font-size: 18px;
line-height: 26px;
@ -82,6 +104,13 @@
font-weight: bold;
}
&.icon-only {
&::after {
margin-left: 2px;
color: $blue;
}
}
.dropdown-content {
display: none;
}

View file

@ -23,7 +23,7 @@
border: 1px solid $black;
}
&.success {
&.accepted {
background-color: $green;
}

View file

@ -7,4 +7,4 @@
// = require select2
// = require typeahead
// = require_tree .
// = stub "print"
// = stub ./print.scss

View file

@ -1,6 +1,20 @@
@import "colors";
@import "fonts";
.new-header,
.backoffice-header,
footer {
display: none;
}
.print-header {
display: block;
margin-top: 30px;
font-size: 30px;
line-height: 50px;
font-weight: bold;
}
body {
font-family: "Muli";
}

View file

@ -26,21 +26,13 @@ class CommentairesController < ApplicationController
@commentaire.dossier.next_step! 'user', 'comment' if current_user.email == @commentaire.dossier.user.email
end
unless params[:piece_justificative].nil?
pj = PiecesJustificativesService.upload_one! @commentaire.dossier, current_user, params
if pj.errors.empty?
@commentaire.piece_justificative = pj
else
flash.alert = pj.errors.full_messages
end
end
@commentaire.file = params["file"]
@commentaire.body = params['texte_commentaire']
unless @commentaire.body.blank? && @commentaire.piece_justificative.nil?
@commentaire.save unless flash.alert
if @commentaire.save
flash.notice = "Votre message a été envoyé"
else
flash.alert = "Veuillez rédiger un message ou ajouter une pièce jointe."
flash.alert = "Veuillez rédiger un message ou ajouter une pièce jointe (maximum 20 Mo)"
end
if is_gestionnaire?

View file

@ -2,6 +2,8 @@ module NewGestionnaire
class AvisController < ApplicationController
layout 'new_application'
before_action :set_avis_and_dossier, only: [:show, :instruction, :messagerie, :create_commentaire]
A_DONNER_STATUS = 'a-donner'
DONNES_STATUS = 'donnes'
@ -23,13 +25,9 @@ module NewGestionnaire
end
def show
@avis = avis
@dossier = avis.dossier
end
def instruction
@avis = avis
@dossier = avis.dossier
end
def update
@ -39,13 +37,19 @@ module NewGestionnaire
end
def messagerie
@avis = avis
@dossier = avis.dossier
@commentaire = Commentaire.new
end
def create_commentaire
Commentaire.create(commentaire_params.merge(email: current_gestionnaire.email, dossier: avis.dossier))
redirect_to messagerie_avis_path(avis)
@commentaire = Commentaire.new(commentaire_params.merge(email: current_gestionnaire.email, dossier: avis.dossier))
if @commentaire.save
flash.notice = "Message envoyé"
redirect_to messagerie_avis_path(avis)
else
flash.alert = @commentaire.errors.full_messages
render :messagerie
end
end
def create_avis
@ -56,6 +60,11 @@ module NewGestionnaire
private
def set_avis_and_dossier
@avis = avis
@dossier = avis.dossier
end
def avis
current_gestionnaire.avis.includes(dossier: [:avis, :commentaires]).find(params[:id])
end
@ -65,7 +74,7 @@ module NewGestionnaire
end
def commentaire_params
params.require(:commentaire).permit(:body)
params.require(:commentaire).permit(:body, :file)
end
def create_avis_params

View file

@ -5,25 +5,22 @@ module NewGestionnaire
end
def show
@dossier = dossier
dossier.notifications.demande.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :demande)
end
def messagerie
@dossier = dossier
dossier.notifications.messagerie.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :messagerie)
@commentaire = Commentaire.new
end
def annotations_privees
@dossier = dossier
dossier.notifications.annotations_privees.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :annotations_privees)
end
def avis
@dossier = dossier
dossier.notifications.avis.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :avis)
end
@ -54,10 +51,16 @@ module NewGestionnaire
end
def create_commentaire
Commentaire.create(commentaire_params.merge(email: current_gestionnaire.email, dossier: dossier))
current_gestionnaire.follow(dossier)
flash.notice = "Message envoyé"
redirect_to messagerie_dossier_path(dossier.procedure, dossier)
@commentaire = Commentaire.new(commentaire_params.merge(email: current_gestionnaire.email, dossier: dossier))
if @commentaire.save
current_gestionnaire.follow(dossier)
flash.notice = "Message envoyé"
redirect_to messagerie_dossier_path(dossier.procedure, dossier)
else
flash.alert = @commentaire.errors.full_messages
render :messagerie
end
end
def position
@ -95,11 +98,11 @@ module NewGestionnaire
private
def dossier
current_gestionnaire.dossiers.find(params[:dossier_id])
@dossier ||= current_gestionnaire.dossiers.find(params[:dossier_id])
end
def commentaire_params
params.require(:commentaire).permit(:body)
params.require(:commentaire).permit(:body, :file)
end
def avis_params

View file

@ -0,0 +1,11 @@
module DossierHelper
def button_or_label_class(dossier)
if dossier.closed?
'accepted'
elsif dossier.without_continuation?
'without-continuation'
elsif dossier.refused?
'refused'
end
end
end

View file

@ -1,9 +1,13 @@
class Commentaire < ActiveRecord::Base
belongs_to :dossier, touch: true
belongs_to :champ
belongs_to :piece_justificative
mount_uploader :file, CommentaireFileUploader
validates :file, file_size: { maximum: 20.megabytes, message: "La taille du fichier doit être inférieure à 20 Mo" }
validate :is_virus_free?
validates_presence_of :body, message: "Votre message ne peut être vide"
default_scope { order(created_at: :asc) }
scope :updated_since?, -> (date) { where('commentaires.updated_at > ?', date) }
@ -13,6 +17,14 @@ class Commentaire < ActiveRecord::Base
"#{email}, " + I18n.l(created_at.localtime, format: '%d %b %Y %H:%M')
end
def file_url
if Features.remote_storage
RemoteDownloader.new(file.path).url
else
file.url
end
end
private
def notify
@ -43,4 +55,10 @@ class Commentaire < ActiveRecord::Base
def notify_user
NotificationMailer.new_answer(dossier).deliver_now!
end
def is_virus_free?
if file.present? && file_changed? && !ClamavService.safe_file?(file.path)
errors.add(:file, "Virus détecté dans le fichier joint, merci de changer de fichier")
end
end
end

View file

@ -373,6 +373,12 @@ class Dossier < ActiveRecord::Base
end
end
def user_geometry
if json_latlngs.present?
UserGeometry.new(json_latlngs)
end
end
private
def build_attestation

View file

@ -40,6 +40,7 @@ class Procedure < ActiveRecord::Base
validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :description, presence: true, allow_blank: false, allow_nil: false
validates :organisation, presence: true, allow_blank: false, allow_nil: false
def hide!
now = DateTime.now

View file

@ -0,0 +1,40 @@
class UserGeometry
alias :read_attribute_for_serialization :send
def initialize(json_latlngs)
@json_latlngs = json_latlngs
end
def value
to_geo_json(@json_latlngs)
end
def type_de_champ
{
id: -1,
libelle: 'user_geometry',
type_champ: 'user_geometry',
order_place: -1,
descripton: ''
}
end
private
def to_geo_json(json_latlngs)
json = JSON.parse(json_latlngs)
coordinates = json.map do |lat_longs|
outbounds = lat_longs.map do |lat_long|
[lat_long['lng'], lat_long['lat']]
end
[outbounds]
end
{
type: 'MultiPolygon',
coordinates: coordinates
}
end
end

View file

@ -0,0 +1,17 @@
class CadastreSerializer < ActiveModel::Serializer
attributes :value, :type_de_champ
def value
object.geometry
end
def type_de_champ
{
id: -1,
libelle: 'cadastre',
type_champ: 'cadastre',
order_place: -1,
descripton: ''
}
end
end

View file

@ -18,11 +18,18 @@ class DossierSerializer < ActiveModel::Serializer
has_one :etablissement
has_many :cerfa
has_many :commentaires
has_many :champs
has_many :champs_private
has_many :pieces_justificatives
has_many :types_de_piece_justificative
has_many :champs do
champs = object.champs + object.quartier_prioritaires + object.cadastres
if object.user_geometry.present?
champs << object.user_geometry
end
champs
end
def email
object.user.try(:email)
end
@ -38,4 +45,19 @@ class DossierSerializer < ActiveModel::Serializer
def invites
object.invites_gestionnaires.pluck(:email)
end
private
def user_geometry(dossier)
{
value: dossier.geometry,
type_de_champ: {
id: -1,
libelle: 'user_geometry',
type_champ: 'user_geometry',
order_place: -1,
descripton: ''
}
}
end
end

View file

@ -0,0 +1,17 @@
class QuartierPrioritaireSerializer < ActiveModel::Serializer
attributes :value, :type_de_champ
def value
object.geometry
end
def type_de_champ
{
id: -1,
libelle: 'quartier prioritaire',
type_champ: 'quartier_prioritaire',
order_place: -1,
descripton: ''
}
end
end

View file

@ -0,0 +1,3 @@
class UserGeometrySerializer < ActiveModel::Serializer
attributes :value, :type_de_champ
end

View file

@ -0,0 +1,23 @@
class CommentaireFileUploader < BaseUploader
def root
File.join(Rails.root, 'public')
end
if Features.remote_storage
storage :fog
else
storage :file
end
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(pdf doc docx xls xlsx ppt pptx odt ods odp jpg jpeg png zip txt)
end
def accept_extension_list
extension_white_list.map{ |e| ".#{e}" }.join(",")
end
end

View file

@ -2,7 +2,7 @@
.alert.alert-info
Cette procédure est publiée, certains éléments de la description ne sont plus modifiables
- { libelle: 'Libellé*', description: 'Description*', organisation: 'Organisme', direction: 'Direction', lien_site_web: 'Lien site internet', lien_notice: 'Lien notice' }.each do |key, value|
- { libelle: 'Libellé*', description: 'Description*', organisation: 'Organisme*', direction: 'Direction', lien_site_web: 'Lien site internet', lien_notice: 'Lien notice' }.each do |key, value|
.form-group
%h4
= value

View file

@ -3,7 +3,13 @@
= commentaire.header
.content
= sanitize(commentaire.body)
- if file = commentaire.piece_justificative
- if commentaire.file.present?
.file
= link_to commentaire.file_url, class: 'link', target: '_blank' do
%span.fa.fa-file
%div
= commentaire.file_identifier
- elsif file = commentaire.piece_justificative
.file
= link_to file.content_url, class: 'link', target: '_blank' do
%span.fa.fa-file

View file

@ -5,6 +5,6 @@
.row
.col-md-6
%h4.text-primary{ style: 'margin-top: 0px;' } Ajouter un fichier
= file_field_tag "piece_justificative[content]", accept: PieceJustificative.accept_format, style: 'float: left; margin-left: 20px;'
= file_field_tag "file", accept: Commentaire.new.file.accept_extension_list, style: 'float: left; margin-left: 20px;'
.col-md-6.text-right
= submit_tag 'Envoyer', id: 'save-message', class: 'form-control btn btn-danger', data: { disable_with: 'Envoi...' }

View file

@ -20,8 +20,6 @@
= link_to "Nouveautés", "https://github.com/sgmap/tps/releases", :class => "footer-link"
%li.footer-link
= link_to "Statistiques", stats_path, :class => "footer-link"
%li.footer-link
= link_to "Accès ancienne plateforme de test", "https://tps-dev.apientreprise.fr/", :class => "footer-link"
%li.footer-column
%ul.footer-links

View file

@ -14,7 +14,7 @@
= favicon_link_tag(image_url("favicons/96x96.png"), type: "image/png", sizes: "96x96")
= stylesheet_link_tag "new_design/new_application", media: "all", "data-turbolinks-track": "reload"
= stylesheet_link_tag "print", media: "print", "data-turbolinks-track": true
= stylesheet_link_tag "new_design/print", media: "print", "data-turbolinks-track": true
%body
.page-wrapper

View file

@ -3,21 +3,9 @@
= render partial: 'header', locals: { avis: @avis, dossier: @dossier }
.messagerie.container
%ul
%ul.messages-list
- @dossier.commentaires.each do |commentaire|
%li
= render partial: 'new_gestionnaire/dossiers/commentaire_icon', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire }
= render partial: "new_gestionnaire/shared/commentaires/commentaire", locals: { commentaire: commentaire }
.width-100
%h2
%span.mail
= render partial: 'new_gestionnaire/dossiers/commentaire_issuer', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire }
- if ![current_gestionnaire.email, @dossier.user.email, 'contact@tps.apientreprise.fr'].include?(commentaire.email)
%span.guest Invité
%span.date= I18n.l(commentaire.created_at.localtime, format: '%H:%M le %d/%m/%Y')
%p= sanitize(commentaire.body)
= form_for(Commentaire.new, url: commentaire_avis_path(@avis), html: { class: 'form' }) do |f|
= f.text_area :body, rows: 5, placeholder: 'Répondre ici', required: true
.send-wrapper
= f.submit 'Envoyer', class: 'button send'
= render partial: "new_gestionnaire/shared/commentaires/form", locals: { commentaire: @commentaire, form_url: commentaire_avis_path(@avis) }

View file

@ -7,8 +7,14 @@
%li
= "Dossier nº #{dossier.id}"
.mixed-buttons-bar
= link_to print_dossier_path(dossier.procedure, dossier), target: "_blank", class: "button icon-only" do
.icon.printer>
.button.dropdown.icon-only.print-menu-opener{ onclick: "javascript:TPS.togglePrintMenu(event);" }
.icon.printer
%ul.print-menu
%li
= link_to "Tout le dossier", print_dossier_path(dossier.procedure, dossier), target: "_blank", class: "menu-item menu-link"
%li
= link_to "Uniquement cet onglet", "#", onclick: "TPS.togglePrintMenu; window.print()", class: "menu-item menu-link"
= render partial: "new_gestionnaire/procedures/dossier_actions", locals: { procedure: dossier.procedure, dossier: dossier, dossier_is_followed: current_gestionnaire&.follow?(dossier) }
= render partial: "state_button", locals: { dossier: dossier }
%ul.tabs
@ -29,3 +35,9 @@
- if notifications_summary[:messagerie]
%span.notifications{ 'aria-label': 'notifications' }
= link_to "Messagerie", messagerie_dossier_path(dossier.procedure, dossier)
.container
.print-header
= dossier.procedure.libelle.truncate_words(10)
>
= "Dossier nº #{dossier.id} (#{dossier.statut})"

View file

@ -61,7 +61,7 @@
- else
- if dossier.motivation.present? || dossier.attestation.present?
%span.button.dropdown{ class: dossier.closed? ? 'success' : nil }
%span.button.dropdown{ class: button_or_label_class(dossier) }
= dossier.statut
.dropdown-content.fade-in-down.terminated
- if dossier.motivation.present?
@ -73,5 +73,5 @@
%p.attestation L'acceptation du dossier a envoyé automatiquement une attestation au demandeur
= link_to "Voir l'attestation", attestation_dossier_path(dossier.procedure, dossier), target: '_blank', class: 'button'
- else
%span.label{ class: dossier.closed? ? 'success' : nil }
%span.label{ class: button_or_label_class(dossier) }
= dossier.statut

View file

@ -6,24 +6,6 @@
%ul.messages-list
- @dossier.commentaires.each do |commentaire|
%li
= render partial: 'commentaire_icon', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire }
= render partial: "new_gestionnaire/shared/commentaires/commentaire", locals: { commentaire: commentaire }
.width-100
%h2
%span.mail
= render partial: 'commentaire_issuer', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire }
- if ![current_gestionnaire.email, @dossier.user.email, 'contact@tps.apientreprise.fr'].include?(commentaire.email)
%span.guest Invité
%span.date= I18n.l(commentaire.created_at.localtime, format: '%H:%M le %d/%m/%Y')
.rich-text
= sanitize(commentaire.body)
- if file = commentaire.piece_justificative
.attachment-link
= link_to file.content_url, class: "button", target: "_blank", title: "Télécharger" do
.icon.attachment
= file.original_filename
= form_for(Commentaire.new, url: commentaire_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' }) do |f|
= f.text_area :body, rows: 5, placeholder: 'Répondre ici', required: true
.send-wrapper
= f.submit 'Envoyer', class: 'button send', data: { disable_with: "Envoi..." }
= render partial: "new_gestionnaire/shared/commentaires/form", locals: { commentaire: @commentaire, form_url: commentaire_dossier_path(@dossier.procedure, @dossier) }

View file

@ -0,0 +1,11 @@
- if procedure.dossiers.state_not_brouillon.any?
%span.button.dropdown
Télécharger tous les dossiers
.dropdown-content.fade-in-down
%ul.dropdown-items
%li
= link_to "Au format .csv", download_dossiers_procedure_path(format: :csv, procedure_id: procedure.id), target: "_blank"
%li
= link_to "Au format .xlsx", download_dossiers_procedure_path(format: :xlsx, procedure_id: procedure.id), target: "_blank"
%li
= link_to "Au format .ods", download_dossiers_procedure_path(format: :ods, procedure_id: procedure.id), target: "_blank"

View file

@ -3,7 +3,7 @@
- elsif dossier.en_construction?
%span.label.construction en construction
- elsif dossier.closed?
%span.label.success accepté
%span.label.accepted accepté
- elsif dossier.refused?
%span.label.refused refusé
- elsif dossier.without_continuation?

View file

@ -41,16 +41,7 @@
%span.badge= @archived_dossiers.count
.procedure-actions
%span.button.dropdown
Télécharger tous les dossiers
.dropdown-content.fade-in-down
%ul.dropdown-items
%li
= link_to "Au format .csv", download_dossiers_procedure_path(format: :csv, procedure_id: @procedure.id), target: "_blank"
%li
= link_to "Au format .xlsx", download_dossiers_procedure_path(format: :xlsx, procedure_id: @procedure.id), target: "_blank"
%li
= link_to "Au format .ods", download_dossiers_procedure_path(format: :ods, procedure_id: @procedure.id), target: "_blank"
= render partial: "download_dossiers", locals: { procedure: @procedure }
.container
- if @dossiers.present? || @current_filters.count > 0

View file

@ -0,0 +1,21 @@
= render partial: 'new_gestionnaire/shared/commentaires/commentaire_icon', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire }
.width-100
%h2
%span.mail
= render partial: 'new_gestionnaire/shared/commentaires/commentaire_issuer', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire }
- if ![current_gestionnaire.email, @dossier.user.email, 'contact@tps.apientreprise.fr'].include?(commentaire.email)
%span.guest Invité
%span.date= I18n.l(commentaire.created_at.localtime, format: '%H:%M le %d/%m/%Y')
%p.rich-text= sanitize(commentaire.body)
- if commentaire.file.present?
.attachment-link
= link_to commentaire.file_url, class: "button", target: "_blank", title: "Télécharger" do
.icon.attachment
= commentaire.file_identifier
- elsif commentaire.piece_justificative
.attachment-link
= link_to commentaire.piece_justificative.content_url, class: "button", target: "_blank", title: "Télécharger" do
.icon.attachment
= commentaire.piece_justificative.original_filename

View file

@ -0,0 +1,11 @@
= form_for(commentaire, url: form_url, html: { class: 'form' }) do |f|
= f.text_area :body, rows: 5, placeholder: 'Répondre ici', required: true
.flex.justify-between
%div
= f.file_field :file, id: :file, accept: commentaire.file.accept_extension_list
%label{ for: :file }
.notice
(taille max : 20 Mo)
.send-wrapper
= f.submit 'Envoyer', class: 'button send', data: { disable_with: "Envoi…" }

View file

@ -40,7 +40,7 @@
= link_to ".button.secondary", "#", class: "button secondary"
= link_to ".button.success", "#", class: "button success"
= link_to ".button.accepted", "#", class: "button accepted"
= link_to ".button.large", "#", class: "button large"
@ -67,7 +67,7 @@
%span.label .label
%span.label.instruction .label.instruction
%span.label.construction .label.construction
%span.label.success .label.success
%span.label.accepted .label.accepted
%span.label.refused .label.refused
%span.label.without-continuation .label.without-continuation

View file

@ -4,4 +4,4 @@
selected: champ.drop_down_list.selected_options(champ),
disabled: champ.drop_down_list.disabled_options),
multiple: champ.drop_down_list.multiple,
class: champ.drop_down_list.multiple ? 'select2' : nil)
class: 'select2')

View file

@ -34,8 +34,6 @@ module TPS
URL = "http://localhost:3000/"
end
config.skylight.environments += ["staging"]
config.active_job.queue_adapter = :delayed_job
config.action_view.sanitized_allowed_tags = ActionView::Base.sanitized_allowed_tags + ['u']

View file

@ -0,0 +1,5 @@
fr:
activerecord:
attributes:
commentaire:
file: fichier

View file

@ -1,5 +1,8 @@
fr:
activerecord:
attributes:
procedure:
organisation: Organisme
errors:
models:
procedure:
@ -10,3 +13,5 @@ fr:
blank: Attribut manquant
lien_demarche:
blank: Attribut manquant
organisation:
blank: Attribut manquant

View file

@ -0,0 +1,5 @@
class AddFileToCommentaires < ActiveRecord::Migration[5.0]
def change
add_column :commentaires, :file, :string
end
end

View file

@ -0,0 +1,5 @@
class MakeProceduresOrganisationNotNull < ActiveRecord::Migration[5.0]
def change
change_column_null :procedures, :organisation, false
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20171117165748) do
ActiveRecord::Schema.define(version: 20171123125346) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -78,8 +78,8 @@ ActiveRecord::Schema.define(version: 20171117165748) do
t.string "logo"
t.string "signature"
t.boolean "activated"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "procedure_id"
t.string "logo_secure_token"
t.string "signature_secure_token"
@ -163,6 +163,7 @@ ActiveRecord::Schema.define(version: 20171117165748) do
t.datetime "updated_at", null: false
t.integer "piece_justificative_id"
t.integer "champ_id"
t.string "file"
t.index ["champ_id"], name: "index_commentaires_on_champ_id", using: :btree
t.index ["dossier_id"], name: "index_commentaires_on_dossier_id", using: :btree
end
@ -403,7 +404,7 @@ ActiveRecord::Schema.define(version: 20171117165748) do
create_table "procedures", force: :cascade do |t|
t.string "libelle"
t.string "description"
t.string "organisation"
t.string "organisation", null: false
t.string "direction"
t.string "lien_demarche"
t.datetime "created_at", null: false

View file

@ -97,6 +97,108 @@
"order_place": 1,
"description": "description de votre projet"
}
},
{
"value": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
2.3050735,
48.8401501
],
[
2.3052329,
48.8402106
],
[
2.3053759,
48.8400422
],
[
2.3050735,
48.8401501
]
]
]
]
},
"type_de_champ": {
"id": -1,
"libelle": "cadastre",
"type_champ": "cadastre",
"order_place": -1,
"descripton": ""
}
},
{
"value": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
2.3050735,
48.8401501
],
[
2.3052329,
48.8402106
],
[
2.3053759,
48.8400422
],
[
2.3050735,
48.8401501
]
]
]
]
},
"type_de_champ": {
"id": -1,
"libelle": "quartier prioritaire",
"type_champ": "quartier_prioritaire",
"order_place": -1,
"descripton": ""
}
},
{
"value": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
2.3049509525299072,
48.84028511554904
],
[
2.305165529251098,
48.84014035882062
],
[
2.3049670457839966,
48.84005562298059
],
[
2.3049509525299072,
48.84028511554904
]
]
]
]
},
"type_de_champ": {
"id": -1,
"libelle": "user_geometry",
"type_champ": "user_geometry",
"order_place": -1,
"descripton": ""
}
}
],
"champs_private": [
@ -155,9 +257,9 @@
"direction": "direction SGMAP",
"archived_at": null,
"geographic_information": {
"use_api_carto": false,
"quartiers_prioritaires": false,
"cadastre": false
"use_api_carto": true,
"quartiers_prioritaires": true,
"cadastre": true
},
"types_de_champ": [
{

View file

@ -0,0 +1,32 @@
namespace :'2017_10_30_copy_commentaire_piece_justificative_to_file' do
task set: :environment do
commentaires_to_process = Commentaire.where(file:nil).where.not(piece_justificative_id: nil).reorder(id: :desc)
puts "#{commentaires_to_process.count} commentaires to process..."
commentaires_to_process.each do |c|
process_commentaire(c)
end
end
def process_commentaire commentaire
puts "Processing commentaire #{commentaire.id}"
if commentaire.piece_justificative.present?
# https://github.com/carrierwaveuploader/carrierwave#uploading-files-from-a-remote-location
commentaire.remote_file_url = commentaire.piece_justificative.content_url
if commentaire.piece_justificative.original_filename.present?
commentaire.file.define_singleton_method(:filename) { commentaire.piece_justificative.original_filename }
end
if commentaire.body.blank?
commentaire.body = commentaire.piece_justificative.original_filename || "."
end
commentaire.save
if !commentaire.file.present?
puts "Failed to save file for commentaire #{commentaire.id}"
end
end
end
end

View file

@ -234,6 +234,46 @@ describe API::V1::DossiersController do
it { expect(subject[:type_champ]).to eq('text') }
end
end
context 'when the dossier includes a quartier prioritaire' do
before do
dossier.quartier_prioritaires << create(:quartier_prioritaire)
end
subject do
super().find { |champ| champ[:type_de_champ][:type_champ] == 'quartier_prioritaire' }
end
it { expect(subject[:type_de_champ]).to match({ id: -1, libelle: 'quartier prioritaire', type_champ: 'quartier_prioritaire', order_place: -1, descripton: ''}) }
it { expect(subject[:value]).to match(dossier.quartier_prioritaires.first.geometry.symbolize_keys) }
end
context 'when the dossier includes a cadastre' do
before do
dossier.cadastres << create(:cadastre)
end
subject do
super().find { |champ| champ[:type_de_champ][:type_champ] == 'cadastre' }
end
it { expect(subject[:type_de_champ]).to match({ id: -1, libelle: 'cadastre', type_champ: 'cadastre', order_place: -1, descripton: ''}) }
it { expect(subject[:value]).to match(dossier.cadastres.first.geometry.symbolize_keys) }
end
context 'when the dossier includes some user geometry' do
before do
dossier.json_latlngs = '[[{"lat": 2.0, "lng": 102.0}, {"lat": 3.0, "lng": 103.0}, {"lat": 2.0, "lng": 102.0}]]'
dossier.save
end
subject do
super().find { |champ| champ[:type_de_champ][:type_champ] == 'user_geometry' }
end
it { expect(subject[:type_de_champ]).to match({ id: -1, libelle: 'user_geometry', type_champ: 'user_geometry', order_place: -1, descripton: ''}) }
it { expect(subject[:value]).to match(UserGeometry.new(dossier.json_latlngs).value) }
end
end
describe 'champs_private' do

View file

@ -65,11 +65,7 @@ describe Backoffice::CommentairesController, type: :controller do
let(:document_upload) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
subject do
post :create, params: {dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire, piece_justificative: {content: document_upload}}
end
it 'create a new piece justificative' do
expect { subject }.to change(PieceJustificative, :count).by(1)
post :create, params: { dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire, file: document_upload }
end
it 'clamav check the pj' do
@ -77,26 +73,6 @@ describe Backoffice::CommentairesController, type: :controller do
subject
end
it 'Internal notification is created' do
expect { subject }.to change(Notification, :count).by (1)
end
describe 'piece justificative created' do
let(:pj) { PieceJustificative.last }
before do
subject
end
it 'not have a type de pj' do
expect(pj.type_de_piece_justificative).to be_nil
end
it 'content not be nil' do
expect(pj.content).not_to be_nil
end
end
describe 'commentaire created' do
let(:commentaire) { Commentaire.last }
@ -105,8 +81,8 @@ describe Backoffice::CommentairesController, type: :controller do
end
it 'have a piece justificative reference' do
expect(commentaire.piece_justificative).not_to be_nil
expect(commentaire.piece_justificative).to eq PieceJustificative.last
expect(commentaire.file.present?).to eq true
expect(commentaire.file.class).to eq(CommentaireFileUploader)
end
end
end

View file

@ -63,12 +63,38 @@ describe NewGestionnaire::AvisController, type: :controller do
end
describe '#create_commentaire' do
let(:file) { nil }
let(:scan_result) { true }
subject { post :create_commentaire, { id: avis_without_answer.id, commentaire: { body: 'commentaire body', file: file } } }
before do
post :create_commentaire, { id: avis_without_answer.id, commentaire: { body: 'commentaire body' } }
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
end
it { expect(response).to redirect_to(messagerie_avis_path(avis_without_answer)) }
it { expect(dossier.commentaires.map(&:body)).to match(['commentaire body']) }
it do
subject
expect(response).to redirect_to(messagerie_avis_path(avis_without_answer))
expect(dossier.commentaires.map(&:body)).to match(['commentaire body'])
end
context "with a file" do
let(:file) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
it do
subject
expect(Commentaire.last.file.path).to include("piece_justificative_0.pdf")
end
it { expect { subject }.to change(Commentaire, :count).by(1) }
context "and a virus" do
let(:scan_result) { false }
it { expect { subject }.not_to change(Commentaire, :count) }
end
end
end
describe '#create_avis' do

View file

@ -111,20 +111,56 @@ describe NewGestionnaire::DossiersController, type: :controller do
describe "#create_commentaire" do
let(:saved_commentaire) { dossier.commentaires.first }
let(:body) { "body" }
let(:file) { nil }
let(:scan_result) { true }
before do
subject {
post :create_commentaire, params: {
procedure_id: procedure.id,
dossier_id: dossier.id,
commentaire: { body: 'body' }
commentaire: {
body: body,
file: file
}
}
}
before do
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
end
it { expect(saved_commentaire.body).to eq('body') }
it { expect(saved_commentaire.email).to eq(gestionnaire.email) }
it { expect(saved_commentaire.dossier).to eq(dossier) }
it { expect(response).to redirect_to(messagerie_dossier_path(dossier.procedure, dossier)) }
it { expect(gestionnaire.followed_dossiers).to include(dossier) }
it do
subject
expect(saved_commentaire.body).to eq('body')
expect(saved_commentaire.email).to eq(gestionnaire.email)
expect(saved_commentaire.dossier).to eq(dossier)
expect(response).to redirect_to(messagerie_dossier_path(dossier.procedure, dossier))
expect(gestionnaire.followed_dossiers).to include(dossier)
expect(saved_commentaire.file.present?).to eq(false)
end
it { expect { subject }.to change(Commentaire, :count).by(1) }
context "without a body" do
let(:body) { nil }
it { expect { subject }.not_to change(Commentaire, :count) }
end
context "with a file" do
let(:file) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
it { subject; expect(saved_commentaire.file.present?).to eq(true) }
it { expect { subject }.to change(Commentaire, :count).by(1) }
context "and a virus" do
let(:scan_result) { false }
it { expect { subject }.not_to change(Commentaire, :count) }
end
end
end
describe "#create_avis" do

View file

@ -61,11 +61,7 @@ describe Users::CommentairesController, type: :controller do
subject do
sign_in dossier.user
post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire, piece_justificative: { content: document_upload } }
end
it 'create a new piece justificative' do
expect { subject }.to change(PieceJustificative, :count).by(1)
post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire, file: document_upload }
end
it 'clamav check the pj' do
@ -73,22 +69,6 @@ describe Users::CommentairesController, type: :controller do
subject
end
describe 'piece justificative created' do
let(:pj) { PieceJustificative.last }
before do
subject
end
it 'not have a type de pj' do
expect(pj.type_de_piece_justificative).to be_nil
end
it 'content not be nil' do
expect(pj.content).not_to be_nil
end
end
describe 'commentaire created' do
let(:commentaire) { Commentaire.last }
@ -97,8 +77,8 @@ describe Users::CommentairesController, type: :controller do
end
it 'have a piece justificative reference' do
expect(commentaire.piece_justificative).not_to be_nil
expect(commentaire.piece_justificative).to eq PieceJustificative.last
expect(commentaire.file.present?).to be true
expect(commentaire.file.class).to eq CommentaireFileUploader
end
end
end

View file

@ -3,5 +3,6 @@ FactoryGirl.define do
numero '001'
feuille 1
section 'OM'
geometry '{"type": "MultiPolygon", "coordinates": [[[[2.37112834276229, 48.8773116214902], [2.37163254350824, 48.8775780792784], [2.37112834276229, 48.8773116214902]]]]}'
end
end

View file

@ -3,5 +3,6 @@ FactoryGirl.define do
code 'QPcode'
commune 'Paris'
nom 'Test des QP'
geometry '{"type": "MultiPolygon", "coordinates": [[[[2.37112834276229, 48.8773116214902], [2.37163254350824, 48.8775780792784], [2.37112834276229, 48.8773116214902]]]]}'
end
end

View file

@ -13,6 +13,7 @@ feature 'As an administrateur I wanna clone a procedure', js: true do
page.find_by_id('new-procedure').click
fill_in 'procedure_libelle', with: 'libelle de la procedure'
page.execute_script("$('#procedure_description').data('wysihtml5').editor.setValue('description de la procedure')")
fill_in 'procedure_organisation', with: 'organisme de la procedure'
page.find_by_id('save-procedure').click
end

View file

@ -37,6 +37,7 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
page.find_by_id('flash_message').visible?
fill_in 'procedure_libelle', with: 'libelle de la procedure'
page.execute_script("$('#procedure_description').data('wysihtml5').editor.setValue('description de la procedure')")
fill_in 'procedure_organisation', with: 'organisme de la procedure'
page.find_by_id('save-procedure').click
expect(page).to have_current_path(admin_procedure_types_de_champ_path(Procedure.first.id.to_s))
end
@ -47,6 +48,7 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
page.find_by_id('new-procedure').click
fill_in 'procedure_libelle', with: 'libelle de la procedure'
page.execute_script("$('#procedure_description').data('wysihtml5').editor.setValue('description de la procedure')")
fill_in 'procedure_organisation', with: 'organisme de la procedure'
page.find_by_id('save-procedure').click
end

View file

@ -15,7 +15,7 @@ describe Commentaire do
let(:assign_to) { create(:assign_to, gestionnaire: gestionnaire, procedure: procedure) }
let(:user) { create(:user) }
let(:dossier) { create(:dossier, procedure: procedure, user: user) }
let(:commentaire) { Commentaire.new(dossier: dossier) }
let(:commentaire) { Commentaire.new(dossier: dossier, body: "Mon commentaire") }
context "with a commentaire created by a user" do
it "calls notify_gestionnaires" do

View file

@ -967,4 +967,49 @@ describe Dossier do
it { is_expected.to eq("#{dossier.individual.nom} #{dossier.individual.prenom}") }
end
end
describe 'geometry' do
let(:dossier) { create(:dossier, json_latlngs: json_latlngs) }
let(:json_latlngs) { nil }
subject{ dossier.user_geometry }
context 'when there are no map' do
it { is_expected.to eq(nil) }
end
context 'when there are 2 polygones' do
let(:json_latlngs) do
'[[{"lat": 2.0, "lng": 102.0}, {"lat": 3.0, "lng": 103.0}, {"lat": 2.0, "lng": 102.0}],
[{"lat": 2.0, "lng": 102.0}, {"lat": 3.0, "lng": 103.0}, {"lat": 2.0, "lng": 102.0}]]'
end
let(:expected) do
{
"type": "MultiPolygon",
"coordinates":
[
[
[
[102.0, 2.0],
[103.0, 3.0],
[102.0, 2.0]
]
],
[
[
[102.0, 2.0],
[103.0, 3.0],
[102.0, 2.0]
]
]
]
}
end
subject{ dossier.user_geometry.value }
it { is_expected.to eq(expected) }
end
end
end

View file

@ -57,6 +57,12 @@ describe Procedure do
it { is_expected.to allow_value('').for(:lien_demarche) }
it { is_expected.to allow_value('http://localhost').for(:lien_demarche) }
end
context 'organisation' do
it { is_expected.not_to allow_value(nil).for(:organisation) }
it { is_expected.not_to allow_value('').for(:organisation) }
it { is_expected.to allow_value('URRSAF').for(:organisation) }
end
end
describe '#types_de_champ_ordered' do

View file

@ -0,0 +1,20 @@
describe 'new_gestionnaire/procedures/_download_dossiers.html.haml', type: :view do
let(:current_gestionnaire) { create(:gestionnaire) }
let(:procedure) { create(:procedure) }
subject { render 'new_gestionnaire/procedures/download_dossiers.html.haml', procedure: procedure }
context "when procedure has 0 dossier" do
it { is_expected.not_to include("Télécharger tous les dossiers") }
end
context "when procedure has 1 dossier brouillon" do
let!(:dossier) { create(:dossier, procedure: procedure) }
it { is_expected.not_to include("Télécharger tous les dossiers") }
end
context "when procedure has at least 1 dossier en construction" do
let!(:dossier) { create(:dossier, :initiated, procedure: procedure) }
it { is_expected.to include("Télécharger tous les dossiers") }
end
end