From 0ac23f6d96f44f7c9adea80e14beebfb182b866b Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 13 Sep 2016 12:17:56 +0200 Subject: [PATCH] User can invite other User --- app/controllers/invites_controller.rb | 17 ++++++++++++++--- app/controllers/users/dossiers_controller.rb | 6 ++++-- app/models/dossier.rb | 8 ++++++++ app/views/dossiers/_infos_dossier.html.haml | 6 +++--- app/views/dossiers/_invites.html.haml | 2 +- .../dossiers/_tab_objects_dossier.html.haml | 7 +++++-- config/routes.rb | 6 ++++-- 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb index ee82d2bf3..e729a84cd 100644 --- a/app/controllers/invites_controller.rb +++ b/app/controllers/invites_controller.rb @@ -1,6 +1,8 @@ class InvitesController < ApplicationController + before_action :gestionnaire_or_user? + def create - email_sender = current_gestionnaire.email + email_sender = @current_devise_profil.email user = User.find_by_email(params[:email]) invite = Invite.create(dossier_id: params[:dossier_id], user: user, email: params[:email].downcase, email_sender: email_sender) @@ -16,8 +18,17 @@ class InvitesController < ApplicationController if gestionnaire_signed_in? redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id']) - # else - # redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: params['dossier_id']) + else + redirect_to url_for(controller: 'users/recapitulatif', action: :show, dossier_id: params['dossier_id']) end end + + private + + def gestionnaire_or_user? + return redirect_to root_path unless user_signed_in? || gestionnaire_signed_in? + + @current_devise_profil = current_user if user_signed_in? + @current_devise_profil = current_gestionnaire if gestionnaire_signed_in? + end end diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 891bf600b..bf81eae8c 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -10,8 +10,10 @@ class Users::DossiersController < UsersController end def index - cookies[:liste] = params[:liste] || cookies[:liste] || 'a_traiter' - @dossiers_list_facade = DossiersListFacades.new current_user, cookies[:liste] + liste = params[:liste] || cookies[:liste] || 'a_traiter' + cookies[:liste] = liste + + @dossiers_list_facade = DossiersListFacades.new current_user, liste @dossiers = smart_listing_create :dossiers, @dossiers_list_facade.dossiers_to_display, diff --git a/app/models/dossier.rb b/app/models/dossier.rb index e94ffa375..e00ca94c2 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -307,4 +307,12 @@ class Dossier < ActiveRecord::Base next_step! 'user', 'submit' NotificationMailer.dossier_submitted(self).deliver_now! end + + def read_only? + validated? || received? || submitted? || closed? || refused? || without_continuation? + end + + def owner? email + user.email == email + end end diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index 3947d592e..8f97562e6 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -41,8 +41,8 @@ %br .row{style: 'text-align:right'} - - if !@facade.dossier.validated? && !@facade.dossier.received? && !@facade.dossier.submitted? && !@facade.dossier.closed? && !@facade.dossier.refused? && !@facade.dossier.without_continuation? - - if user_signed_in? && (current_user.email == @facade.dossier.user.email) + - unless @facade.dossier.read_only? + - if user_signed_in? && @facade.dossier.owner?(current_user.email) - if @facade.procedure.cerfa_flag? || @facade.dossier.types_de_piece_justificative.size > 0 %a.btn.btn-success{"data-target" => "#UploadPJmodal", "data-toggle" => "modal", @@ -60,7 +60,7 @@ = 'Modifier mon dossier' -if gestionnaire_signed_in? - -if !@facade.dossier.validated? && !@facade.dossier.received? && !@facade.dossier.submitted? && !@facade.dossier.closed? && !@facade.dossier.refused? && !@facade.dossier.without_continuation? + -if !@facade.dossier.read_only? = form_tag(url_for({controller: 'backoffice/dossiers', action: :valid, dossier_id: @facade.dossier.id}), class: 'form-inline', method: 'POST') do %button#action_button.btn.btn-success = 'Valider le dossier' diff --git a/app/views/dossiers/_invites.html.haml b/app/views/dossiers/_invites.html.haml index 788619476..8328ef5c4 100644 --- a/app/views/dossiers/_invites.html.haml +++ b/app/views/dossiers/_invites.html.haml @@ -12,7 +12,7 @@ Aucune personne invité .col-md-3.col-lg-3 - =form_tag backoffice_dossier_invites_path(dossier_id: @facade.dossier.id), method: :post, class: 'form-inline' do + =form_tag invites_dossier_path(dossier_id: @facade.dossier.id), method: :post, class: 'form-inline' do =text_field_tag :email, '', class: 'form-control', placeholder: 'Envoyer une invitation' =submit_tag 'Ajouter', class: 'btn btn-success' diff --git a/app/views/dossiers/_tab_objects_dossier.html.haml b/app/views/dossiers/_tab_objects_dossier.html.haml index a478f0dbe..b95c33a60 100644 --- a/app/views/dossiers/_tab_objects_dossier.html.haml +++ b/app/views/dossiers/_tab_objects_dossier.html.haml @@ -6,10 +6,12 @@ %a{href: "#commentaires_files", 'aria-controls' => "commentaires_files", role: "tab", 'data-toggle' => "tab"} Fichiers - - if gestionnaire_signed_in? + - if gestionnaire_signed_in? || @facade.dossier.owner?(current_user.email) %li{role: "presentation"} %a{href: "#invites", 'aria-controls' => "invites", role: "tab", 'data-toggle' => "tab"} Invités + + - if gestionnaire_signed_in? %li{role: "presentation"} %a{href: "#followers", 'aria-controls' => "followers", role: "tab", 'data-toggle' => "tab"} Abonnés @@ -25,9 +27,10 @@ %div{role: "tabpanel", class: "tab-pane fade", id:"commentaires_files"} = render partial: '/dossiers/commentaires_files' - - if gestionnaire_signed_in? + - if gestionnaire_signed_in? || @facade.dossier.owner?(current_user.email) %div{role: "tabpanel", class: "tab-pane fade", id:"invites"} = render partial: '/dossiers/invites' + - if gestionnaire_signed_in? %div{role: "tabpanel", class: "tab-pane fade", id:"followers"} = render partial: 'followers' %div{role: "tabpanel", class: "tab-pane fade", id:"champs_private"} diff --git a/config/routes.rb b/config/routes.rb index f679c5057..9f3d48777 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -141,6 +141,10 @@ Rails.application.routes.draw do get 'address_point' => 'search#get_address_point' end + namespace :invites do + post 'dossier/:dossier_id' => '/invites#create', as: 'dossier' + end + namespace :backoffice do get 'sign_in' => '/gestionnaires/sessions#new' get 'dossiers/search' => 'dossiers#search' @@ -155,8 +159,6 @@ Rails.application.routes.draw do post 'without_continuation' => 'dossiers#without_continuation' post 'close' => 'dossiers#close' - post 'invites' => '/invites#create' - put 'follow' => 'dossiers#follow' end