Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoirenovel committed Sep 7, 2018
2 parents d9feae4 + 9c9e4b0 commit 98a3ce0
Show file tree
Hide file tree
Showing 43 changed files with 383 additions and 123 deletions.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/new_design/dossier_show.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@
.button.edit-form {
float: right;
}

.messagerie-explanation {
margin-bottom: $default-padding * 2;
}
}
103 changes: 69 additions & 34 deletions app/controllers/new_user/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ class DossiersController < UserController

helper_method :new_demarche_url

before_action :ensure_ownership!, except: [:index, :show, :demande, :messagerie, :modifier, :update, :recherche]
before_action :ensure_ownership_or_invitation!, only: [:show, :demande, :messagerie, :modifier, :update, :create_commentaire]
before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update]
before_action :forbid_invite_submission!, only: [:update]
before_action :ensure_ownership!, except: [:index, :show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :update, :recherche]
before_action :ensure_ownership_or_invitation!, only: [:show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :update, :create_commentaire]
before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update_brouillon, :modifier, :update]
before_action :forbid_invite_submission!, only: [:update_brouillon]
before_action :forbid_closed_submission!, only: [:update_brouillon]

def index
@user_dossiers = current_user.dossiers.includes(:procedure).order_by_updated_at.page(page)
Expand All @@ -25,7 +26,7 @@ def index

def show
if dossier.brouillon?
redirect_to modifier_dossier_path(dossier)
redirect_to brouillon_dossier_path(dossier)

elsif !Flipflop.new_dossier_details?
redirect_to users_dossier_recapitulatif_path(dossier)
Expand Down Expand Up @@ -64,15 +65,15 @@ def update_identite
if @dossier.procedure.module_api_carto.use_api_carto
redirect_to users_dossier_carte_path(@dossier.id)
else
redirect_to modifier_dossier_path(@dossier)
redirect_to brouillon_dossier_path(@dossier)
end
else
flash.now.alert = @dossier.errors.full_messages
render :identite
end
end

def modifier
def brouillon
@dossier = dossier_with_champs

# TODO: remove when the champs are unifed
Expand All @@ -85,41 +86,53 @@ def modifier
end
end

# FIXME: remove PiecesJustificativesService
# delegate draft save logic to champ ?
def update
# FIXME:
# - remove PiecesJustificativesService
# - delegate draft save logic to champ ?
def update_brouillon
@dossier = dossier_with_champs

errors = PiecesJustificativesService.upload!(@dossier, current_user, params)
errors = update_dossier_and_compute_errors

if champs_params[:dossier] && !@dossier.update(champs_params[:dossier])
errors += @dossier.errors.full_messages
if errors.present?
flash.now.alert = errors
render :brouillon
else
if save_draft?
flash.now.notice = 'Votre brouillon a bien été sauvegardé.'
render :brouillon
else
@dossier.en_construction!
NotificationMailer.send_initiated_notification(@dossier).deliver_later
redirect_to merci_dossier_path(@dossier)
end
end
end

if !draft?
errors += @dossier.champs.select(&:mandatory_and_blank?)
.map { |c| "Le champ #{c.libelle.truncate(200)} doit être rempli." }
errors += PiecesJustificativesService.missing_pj_error_messages(@dossier)
end
def modifier
@dossier = dossier_with_champs
end

# FIXME:
# - remove PiecesJustificativesService
def update
@dossier = dossier_with_champs

errors = update_dossier_and_compute_errors

if errors.present?
flash.now.alert = errors
render :modifier
elsif draft?
flash.now.notice = 'Votre brouillon a bien été sauvegardé.'
render :modifier
elsif @dossier.can_transition_to_en_construction?
@dossier.en_construction!
NotificationMailer.send_initiated_notification(@dossier).deliver_later
redirect_to merci_dossier_path(@dossier)
elsif current_user.owns?(dossier)
if Flipflop.new_dossier_details?
redirect_to demande_dossier_path(@dossier)
else
if current_user.owns?(dossier)
if Flipflop.new_dossier_details?
redirect_to demande_dossier_path(@dossier)
else
redirect_to users_dossier_recapitulatif_path(@dossier)
end
else
redirect_to users_dossier_recapitulatif_path(@dossier)
redirect_to users_dossiers_invite_path(@dossier.invite_for_user(current_user))
end
else
redirect_to users_dossiers_invite_path(@dossier.invite_for_user(current_user))
end
end

Expand All @@ -131,7 +144,7 @@ def create_commentaire
@commentaire = CommentaireService.create(current_user, dossier, commentaire_params)

if @commentaire.save
flash.notice = "Message envoyé"
flash.notice = "Votre message a bien été envoyé à l’instructeur en charge de votre dossier."
redirect_to messagerie_dossier_path(dossier)
else
flash.now.alert = @commentaire.errors.full_messages
Expand Down Expand Up @@ -209,6 +222,22 @@ def dossier_with_champs
Dossier.with_champs.find(params[:id])
end

def update_dossier_and_compute_errors
errors = PiecesJustificativesService.upload!(@dossier, current_user, params)

if champs_params[:dossier] && !@dossier.update(champs_params[:dossier])
errors += @dossier.errors.full_messages
end

if !save_draft?
errors += @dossier.champs.select(&:mandatory_and_blank?)
.map { |c| "Le champ #{c.libelle.truncate(200)} doit être rempli." }
errors += PiecesJustificativesService.missing_pj_error_messages(@dossier)
end

errors
end

def ensure_ownership!
if !current_user.owns?(dossier)
forbidden!
Expand All @@ -227,6 +256,12 @@ def forbid_invite_submission!
end
end

def forbid_closed_submission!
if passage_en_construction? && !dossier.can_transition_to_en_construction?
forbidden!
end
end

def forbidden!
flash[:alert] = "Vous n'avez pas accès à ce dossier"
redirect_to root_path
Expand All @@ -245,10 +280,10 @@ def commentaire_params
end

def passage_en_construction?
dossier.brouillon? && !draft?
dossier.brouillon? && !save_draft?
end

def draft?
def save_draft?
params[:save_draft]
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/carte_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def save

dossier.update(json_latlngs: safe_json_latlngs)

redirect_to modifier_dossier_path(dossier)
redirect_to brouillon_dossier_path(dossier)
end

def get_position
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/dossiers/invites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def show
@facade = InviteDossierFacades.new params[:id].to_i, current_user.email

if @facade.dossier.brouillon?
redirect_to modifier_dossier_path(@facade.dossier)
redirect_to brouillon_dossier_path(@facade.dossier)
else
render 'users/recapitulatif/show'
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def update
if @facade.dossier.procedure.module_api_carto.use_api_carto
redirect_to url_for(controller: :carte, action: :show, dossier_id: @facade.dossier.id)
else
redirect_to modifier_dossier_path(@facade.dossier)
redirect_to brouillon_dossier_path(@facade.dossier)
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions app/helpers/commentaire_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,14 @@ def commentaire_is_from_me_class(commentaire, email)
"from-me"
end
end

def commentaire_is_from_guest(commentaire)
commentaire.dossier.invites.map(&:email).include?(commentaire.email)
end

def commentaire_date(commentaire)
is_current_year = (commentaire.created_at.year == Date.current.year)
template = is_current_year ? :message_date : :message_date_with_year
I18n.l(commentaire.created_at.localtime, format: template)
end
end
2 changes: 1 addition & 1 deletion app/helpers/dossier_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def highlight_if_unseen_class(seen_at, updated_at)

def url_for_dossier(dossier)
if dossier.brouillon?
modifier_dossier_path(dossier)
brouillon_dossier_path(dossier)
else
users_dossier_recapitulatif_path(dossier)
end
Expand Down
8 changes: 6 additions & 2 deletions app/helpers/tabs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ def tab_item(label, url, active: false, badge: nil, notification: false)
}
end

def active_tab_item(label, url, badge: nil, notification: false)
tab_item(label, url, active: current_page?(url), badge: badge, notification: notification)
def dynamic_tab_item(label, url_or_urls, badge: nil, notification: false)
urls = [url_or_urls].flatten
url = urls.first
active = urls.any? { |u| current_page?(u) }

tab_item(label, url, active: active, badge: badge, notification: notification)
end
end
6 changes: 5 additions & 1 deletion app/models/gestionnaire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class Gestionnaire < ApplicationRecord
has_many :dossiers_from_avis, through: :avis, source: :dossier

def visible_procedures
procedures.publiees_ou_archivees
if Flipflop.publish_draft?
procedures.avec_lien
else
procedures.publiees_ou_archivees
end
end

def can_view_dossier?(dossier_id)
Expand Down
1 change: 1 addition & 0 deletions app/models/procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Procedure < ApplicationRecord
scope :by_libelle, -> { order(libelle: :asc) }
scope :created_during, -> (range) { where(created_at: range) }
scope :cloned_from_library, -> { where(cloned_from_library: true) }
scope :avec_lien, -> { joins(:procedure_path) }

validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :description, presence: true, allow_blank: false, allow_nil: false
Expand Down
21 changes: 17 additions & 4 deletions app/views/admin/procedures/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,27 @@

%div
%h3 Lien démarche
%div{ style: 'margin-left: 3%;' }
%div{ style: 'margin-top: 30px;' }
- if @procedure.archivee?
%b
.alert.alert-info
Cette démarche est archivée et n’est donc pas accessible par le public.
- elsif @procedure.brouillon_avec_lien? || @procedure.publiee?
- elsif @procedure.publiee?
= link_to procedure_lien(@procedure), sanitize_url(procedure_lien(@procedure)), target: :blank
- elsif @procedure.brouillon_avec_lien?
- if @procedure.gestionnaires.present? && @procedure.service.present?
= link_to procedure_lien(@procedure), sanitize_url(procedure_lien(@procedure)), target: :blank
- else
.alert.alert-info
Pour pouvoir tester cette démarche, vous devez d’abord lui affecter
- if @procedure.gestionnaires.empty?
= link_to("des instructeurs", admin_procedure_instructeurs_path(@procedure))
- if @procedure.gestionnaires.empty? && @procedure.service.nil?
et
- if @procedure.service.nil?
= link_to("un service", services_path(procedure_id: @procedure))
\.
- else
%b
.alert.alert-info
Cette démarche n’a pas encore de lien, et n’est donc pas accessible par le public.

%br
Expand Down
2 changes: 1 addition & 1 deletion app/views/dossiers/_edit_dossier.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- if [email protected]_only?
- if user_signed_in? && (current_user.owns_or_invite?(@facade.dossier))
= link_to modifier_dossier_path(@facade.dossier), class: 'action', id: 'maj_infos' do
= link_to brouillon_dossier_path(@facade.dossier), class: 'action', id: 'maj_infos' do
#edit-dossier.col-lg-2.col-md-2.col-sm-2.col-xs-2.action
= "MODIFIER"
2 changes: 1 addition & 1 deletion app/views/dossiers/_infos_dossier.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
- if champ.type_champ == TypeDeChamp.type_champs.fetch(:dossier_link)
- dossier = Dossier.includes(:procedure).find_by(id: champ.decorate.value)
- if dossier
= link_to("Dossier #{dossier.id}", modifier_dossier_path(dossier), target: '_blank')
= link_to("Dossier #{dossier.id}", brouillon_dossier_path(dossier), target: '_blank')
%br
= sanitize(dossier.text_summary)
- else
Expand Down
6 changes: 3 additions & 3 deletions app/views/new_gestionnaire/avis/_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
%li= "#{dossier.procedure.libelle}, dossier nº #{dossier.id}"

%ul.tabs
= active_tab_item('Demande', gestionnaire_avis_path(avis))
= active_tab_item('Avis', instruction_gestionnaire_avis_path(avis), notification: avis.answer.blank?)
= active_tab_item('Messagerie', messagerie_gestionnaire_avis_path(avis))
= dynamic_tab_item('Demande', gestionnaire_avis_path(avis))
= dynamic_tab_item('Avis', instruction_gestionnaire_avis_path(avis), notification: avis.answer.blank?)
= dynamic_tab_item('Messagerie', messagerie_gestionnaire_avis_path(avis))
10 changes: 5 additions & 5 deletions app/views/new_gestionnaire/dossiers/_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
%ul.tabs
- notifications_summary = current_gestionnaire.notifications_for_dossier(dossier)

= active_tab_item('Demande',
= dynamic_tab_item('Demande',
gestionnaire_dossier_path(dossier.procedure, dossier),
notification: notifications_summary[:demande])

= active_tab_item('Annotations privées',
= dynamic_tab_item('Annotations privées',
annotations_privees_gestionnaire_dossier_path(dossier.procedure, dossier),
notification: notifications_summary[:annotations_privees])

= active_tab_item('Avis externes',
= dynamic_tab_item('Avis externes',
avis_gestionnaire_dossier_path(dossier.procedure, dossier),
notification: notifications_summary[:avis])

= active_tab_item('Messagerie',
= dynamic_tab_item('Messagerie',
messagerie_gestionnaire_dossier_path(dossier.procedure, dossier),
notification: notifications_summary[:messagerie])

= active_tab_item('Personnes impliquées',
= dynamic_tab_item('Personnes impliquées',
personnes_impliquees_gestionnaire_dossier_path(dossier.procedure, dossier))

.container
Expand Down
11 changes: 11 additions & 0 deletions app/views/new_user/dossiers/brouillon.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- content_for(:title, "Modification du brouillon nº #{@dossier.id} (#{@dossier.procedure.libelle})")

- content_for :footer do
= render partial: "new_user/dossiers/footer", locals: { dossier: @dossier }

.dossier-edit
.dossier-header.sub-header
.container
= render partial: "shared/dossiers/header", locals: { dossier: @dossier, apercu: false }

= render partial: "shared/dossiers/edit", locals: { dossier: @dossier, apercu: false }
2 changes: 1 addition & 1 deletion app/views/new_user/dossiers/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
= dossier.id
%td
= link_to(url_for_dossier(dossier), class: 'cell-link') do
= dossier.procedure.libelle
= procedure_libelle(dossier.procedure)
%td.status-col
= link_to(url_for_dossier(dossier), class: 'cell-link') do
= render partial: 'shared/dossiers/status_badge', locals: { dossier: dossier }
Expand Down
4 changes: 4 additions & 0 deletions app/views/new_user/dossiers/messagerie.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
#dossier-show
= render partial: 'new_user/dossiers/show/header', locals: { dossier: @dossier }

.container
%p.messagerie-explanation
La messagerie vous permet de contacter l’instructeur en charge de votre dossier.

= render partial: "shared/dossiers/messagerie", locals: { dossier: @dossier, user_email: current_user.email, messagerie_seen_at: nil, new_commentaire: @commentaire, form_url: commentaire_dossier_path(@dossier) }
Loading

0 comments on commit 98a3ce0

Please sign in to comment.