User can invite other User

This commit is contained in:
Xavier J 2016-09-13 12:17:56 +02:00
parent e9d4685aef
commit 0ac23f6d96
7 changed files with 39 additions and 13 deletions

View file

@ -1,6 +1,8 @@
class InvitesController < ApplicationController class InvitesController < ApplicationController
before_action :gestionnaire_or_user?
def create def create
email_sender = current_gestionnaire.email email_sender = @current_devise_profil.email
user = User.find_by_email(params[: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) 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? if gestionnaire_signed_in?
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'])
# else else
# redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: params['dossier_id']) redirect_to url_for(controller: 'users/recapitulatif', action: :show, dossier_id: params['dossier_id'])
end end
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 end

View file

@ -10,8 +10,10 @@ class Users::DossiersController < UsersController
end end
def index def index
cookies[:liste] = params[:liste] || cookies[:liste] || 'a_traiter' liste = params[:liste] || cookies[:liste] || 'a_traiter'
@dossiers_list_facade = DossiersListFacades.new current_user, cookies[:liste] cookies[:liste] = liste
@dossiers_list_facade = DossiersListFacades.new current_user, liste
@dossiers = smart_listing_create :dossiers, @dossiers = smart_listing_create :dossiers,
@dossiers_list_facade.dossiers_to_display, @dossiers_list_facade.dossiers_to_display,

View file

@ -307,4 +307,12 @@ class Dossier < ActiveRecord::Base
next_step! 'user', 'submit' next_step! 'user', 'submit'
NotificationMailer.dossier_submitted(self).deliver_now! NotificationMailer.dossier_submitted(self).deliver_now!
end end
def read_only?
validated? || received? || submitted? || closed? || refused? || without_continuation?
end
def owner? email
user.email == email
end
end end

View file

@ -41,8 +41,8 @@
%br %br
.row{style: 'text-align:right'} .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? - unless @facade.dossier.read_only?
- if user_signed_in? && (current_user.email == @facade.dossier.user.email) - if user_signed_in? && @facade.dossier.owner?(current_user.email)
- if @facade.procedure.cerfa_flag? || @facade.dossier.types_de_piece_justificative.size > 0 - if @facade.procedure.cerfa_flag? || @facade.dossier.types_de_piece_justificative.size > 0
%a.btn.btn-success{"data-target" => "#UploadPJmodal", %a.btn.btn-success{"data-target" => "#UploadPJmodal",
"data-toggle" => "modal", "data-toggle" => "modal",
@ -60,7 +60,7 @@
= 'Modifier mon dossier' = 'Modifier mon dossier'
-if gestionnaire_signed_in? -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 = 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 %button#action_button.btn.btn-success
= 'Valider le dossier' = 'Valider le dossier'

View file

@ -12,7 +12,7 @@
Aucune personne invité Aucune personne invité
.col-md-3.col-lg-3 .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' =text_field_tag :email, '', class: 'form-control', placeholder: 'Envoyer une invitation'
=submit_tag 'Ajouter', class: 'btn btn-success' =submit_tag 'Ajouter', class: 'btn btn-success'

View file

@ -6,10 +6,12 @@
%a{href: "#commentaires_files", 'aria-controls' => "commentaires_files", role: "tab", 'data-toggle' => "tab"} %a{href: "#commentaires_files", 'aria-controls' => "commentaires_files", role: "tab", 'data-toggle' => "tab"}
Fichiers Fichiers
- if gestionnaire_signed_in? - if gestionnaire_signed_in? || @facade.dossier.owner?(current_user.email)
%li{role: "presentation"} %li{role: "presentation"}
%a{href: "#invites", 'aria-controls' => "invites", role: "tab", 'data-toggle' => "tab"} %a{href: "#invites", 'aria-controls' => "invites", role: "tab", 'data-toggle' => "tab"}
Invités Invités
- if gestionnaire_signed_in?
%li{role: "presentation"} %li{role: "presentation"}
%a{href: "#followers", 'aria-controls' => "followers", role: "tab", 'data-toggle' => "tab"} %a{href: "#followers", 'aria-controls' => "followers", role: "tab", 'data-toggle' => "tab"}
Abonnés Abonnés
@ -25,9 +27,10 @@
%div{role: "tabpanel", class: "tab-pane fade", id:"commentaires_files"} %div{role: "tabpanel", class: "tab-pane fade", id:"commentaires_files"}
= render partial: '/dossiers/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"} %div{role: "tabpanel", class: "tab-pane fade", id:"invites"}
= render partial: '/dossiers/invites' = render partial: '/dossiers/invites'
- if gestionnaire_signed_in?
%div{role: "tabpanel", class: "tab-pane fade", id:"followers"} %div{role: "tabpanel", class: "tab-pane fade", id:"followers"}
= render partial: 'followers' = render partial: 'followers'
%div{role: "tabpanel", class: "tab-pane fade", id:"champs_private"} %div{role: "tabpanel", class: "tab-pane fade", id:"champs_private"}

View file

@ -141,6 +141,10 @@ Rails.application.routes.draw do
get 'address_point' => 'search#get_address_point' get 'address_point' => 'search#get_address_point'
end end
namespace :invites do
post 'dossier/:dossier_id' => '/invites#create', as: 'dossier'
end
namespace :backoffice do namespace :backoffice do
get 'sign_in' => '/gestionnaires/sessions#new' get 'sign_in' => '/gestionnaires/sessions#new'
get 'dossiers/search' => 'dossiers#search' get 'dossiers/search' => 'dossiers#search'
@ -155,8 +159,6 @@ Rails.application.routes.draw do
post 'without_continuation' => 'dossiers#without_continuation' post 'without_continuation' => 'dossiers#without_continuation'
post 'close' => 'dossiers#close' post 'close' => 'dossiers#close'
post 'invites' => '/invites#create'
put 'follow' => 'dossiers#follow' put 'follow' => 'dossiers#follow'
end end