add login for gestionnaire
This commit is contained in:
parent
b3383bec9f
commit
44173a17fb
26 changed files with 313 additions and 142 deletions
|
@ -1,5 +1,5 @@
|
||||||
class Admin::DossierController < ApplicationController
|
class Admin::DossierController < ApplicationController
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_gestionnaire!
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@dossier = Dossier.find(params[:dossier_id])
|
@dossier = Dossier.find(params[:dossier_id])
|
||||||
|
@ -8,7 +8,7 @@ class Admin::DossierController < ApplicationController
|
||||||
@pieces_justificatives = @dossier.pieces_justificatives
|
@pieces_justificatives = @dossier.pieces_justificatives
|
||||||
@commentaires = @dossier.commentaires.order(created_at: :desc)
|
@commentaires = @dossier.commentaires.order(created_at: :desc)
|
||||||
@commentaires = @commentaires.all.decorate
|
@commentaires = @commentaires.all.decorate
|
||||||
@commentaire_email = current_user.email
|
@commentaire_email = current_gestionnaire.email
|
||||||
|
|
||||||
@procedure = @dossier.procedure
|
@procedure = @dossier.procedure
|
||||||
|
|
||||||
|
|
|
@ -3,20 +3,21 @@ class ApplicationController < ActionController::Base
|
||||||
# For APIs, you may want to use :null_session instead.
|
# For APIs, you may want to use :null_session instead.
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
|
|
||||||
before_action :store_location
|
# before_action :store_location
|
||||||
|
|
||||||
def store_location
|
# def store_location
|
||||||
unless params[:controller] == 'devise/sessions'
|
# unless params[:controller] == 'devise/sessions'
|
||||||
url = "/admin/dossiers/#{params[:dossier_id]}"
|
# url = "/admin/dossiers/#{params[:dossier_id]}"
|
||||||
session[:user_return_to] = url
|
# session[:user_return_to] = url
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
def stored_location_for(resource_or_scope)
|
# def stored_location_for(resource_or_scope)
|
||||||
session[:user_return_to] || super
|
# session[:user_return_to] || super
|
||||||
end
|
# end
|
||||||
|
|
||||||
def after_sign_in_path_for(resource)
|
# def after_sign_in_path_for(resource)
|
||||||
stored_location_for(resource) || root_path
|
# puts "========================= coucou #{resource}"
|
||||||
end
|
# stored_location_for(resource) || root_path
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
|
|
7
app/controllers/backoffice_controller.rb
Normal file
7
app/controllers/backoffice_controller.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
class BackofficeController < ApplicationController
|
||||||
|
|
||||||
|
def index
|
||||||
|
redirect_to(controller: '/gestionnaires/sessions', action: :new) unless gestionnaire_signed_in?
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
16
app/controllers/gestionnaires/sessions_controller.rb
Normal file
16
app/controllers/gestionnaires/sessions_controller.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
class Gestionnaires::SessionsController < Devise::SessionsController
|
||||||
|
|
||||||
|
|
||||||
|
def new
|
||||||
|
@gestionnaire = Gestionnaire.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_sign_in_path_for(resource)
|
||||||
|
# stored_location_for(resource) ||
|
||||||
|
backoffice_path
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,25 +0,0 @@
|
||||||
class Pros::SessionsController < Devise::SessionsController
|
|
||||||
# before_filter :configure_sign_in_params, only: [:create]
|
|
||||||
|
|
||||||
# GET /resource/sign_in
|
|
||||||
def new
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
# POST /resource/sign_in
|
|
||||||
def create
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
# DELETE /resource/sign_out
|
|
||||||
# def destroy
|
|
||||||
# super
|
|
||||||
# end
|
|
||||||
|
|
||||||
# protected
|
|
||||||
|
|
||||||
# You can put the params you want to permit in the empty array.
|
|
||||||
# def configure_sign_in_params
|
|
||||||
# devise_parameter_sanitizer.for(:sign_in) << :attribute
|
|
||||||
# end
|
|
||||||
end
|
|
|
@ -1,14 +1,3 @@
|
||||||
class User::CustomFailure < Devise::FailureApp
|
class User::CustomFailure < Devise::FailureApp
|
||||||
def redirect_url
|
|
||||||
url_for(controller: '/start', action: :index)
|
|
||||||
end
|
|
||||||
|
|
||||||
# You need to override respond to eliminate recall
|
|
||||||
def respond
|
|
||||||
if http_auth?
|
|
||||||
http_auth
|
|
||||||
else
|
|
||||||
redirect
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,25 +1,3 @@
|
||||||
class User::SessionsController < Devise::SessionsController
|
class User::SessionsController < Devise::SessionsController
|
||||||
# before_filter :configure_sign_in_params, only: [:create]
|
|
||||||
|
|
||||||
# GET /resource/sign_in
|
|
||||||
def new
|
|
||||||
redirect_to url_for(controller: '/start', action: :error_login)
|
|
||||||
end
|
|
||||||
|
|
||||||
# POST /resource/sign_in
|
|
||||||
def create
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
# DELETE /resource/sign_out
|
|
||||||
def destroy
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
# protected
|
|
||||||
|
|
||||||
# You can put the params you want to permit in the empty array.
|
|
||||||
# def configure_sign_in_params
|
|
||||||
# devise_parameter_sanitizer.for(:sign_in) << :attribute
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
6
app/models/gestionnaire.rb
Normal file
6
app/models/gestionnaire.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
class Gestionnaire < ActiveRecord::Base
|
||||||
|
# Include default devise modules. Others available are:
|
||||||
|
# :confirmable, :lockable, :timeoutable and :omniauthable
|
||||||
|
devise :database_authenticatable, :registerable,
|
||||||
|
:recoverable, :rememberable, :trackable, :validatable
|
||||||
|
end
|
14
app/views/backoffice/index.html.haml
Normal file
14
app/views/backoffice/index.html.haml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#backoffice
|
||||||
|
|
||||||
|
|
||||||
|
%table.table
|
||||||
|
%thead
|
||||||
|
%th Procédure
|
||||||
|
%th Dossier
|
||||||
|
%th etat
|
||||||
|
%th Date de mise à jour
|
||||||
|
%row
|
||||||
|
%td Demande de subventions
|
||||||
|
%td dossier n°34 Demande de subvention
|
||||||
|
%td Mise à jour
|
||||||
|
%td 24/12/2015
|
10
app/views/gestionnaires/sessions/new.html.haml
Normal file
10
app/views/gestionnaires/sessions/new.html.haml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
%h1 Bienvenue sur TPS
|
||||||
|
%br
|
||||||
|
#gestionnaire_login
|
||||||
|
= form_for @gestionnaire, url: {controller: 'gestionnaires/sessions', action: :create } do |f|
|
||||||
|
.form-group-lg
|
||||||
|
.form-group
|
||||||
|
= f.text_field :email, class: 'form-control', placeholder: 'Email'
|
||||||
|
.form-group
|
||||||
|
= f.password_field :password, class: 'form-control', placeholder: 'Mot de passe'
|
||||||
|
= f.submit 'Se connecter', class: %w(btn btn-lg btn-success), data: { disable_with: 'Connexion', submit: true }
|
|
@ -13,10 +13,10 @@
|
||||||
%a{href: '/', class:'btn btn-lg'}
|
%a{href: '/', class:'btn btn-lg'}
|
||||||
='TPS'
|
='TPS'
|
||||||
|
|
||||||
-if user_signed_in?
|
-if gestionnaire_signed_in?
|
||||||
%div{style: 'decorate:none; box-shadow:none; float:right; margin-top:8px'}
|
%div{style: 'decorate:none; box-shadow:none; float:right; margin-top:8px'}
|
||||||
= current_user.email
|
= current_gestionnaire.email
|
||||||
= link_to "Déconnexion", '/logout', method: :delete, :class => 'btn btn-md'
|
= link_to "Déconnexion", '/gestionnaires/sign_out', method: :delete, :class => 'btn btn-md'
|
||||||
|
|
||||||
#flash_message.center
|
#flash_message.center
|
||||||
- if flash.notice
|
- if flash.notice
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
%p.lead{id: 'admin_section'}
|
/ %p.lead{id: 'admin_section'}
|
||||||
%span{class:'text-info', style:'font-weight:bold'}
|
/ %span{class:'text-info', style:'font-weight:bold'}
|
||||||
-if user_signed_in?
|
/ -if user_signed_in?
|
||||||
='Vous êtes identifié comme une administration'
|
/ ='Vous êtes identifié comme une administration'
|
||||||
-else
|
/ -else
|
||||||
='Si vous êtes une administration, '
|
/ ='Si vous êtes une administration, '
|
||||||
|
|
||||||
%p.lead
|
/ %p.lead
|
||||||
-if user_signed_in?
|
/ -if user_signed_in?
|
||||||
= form_tag(url_for({controller: 'admin/dossier', action: :index}), class: 'form-inline', method: 'GET') do
|
/ = form_tag(url_for({controller: 'admin/dossier', action: :index}), class: 'form-inline', method: 'GET') do
|
||||||
.form-group.form-group-lg
|
/ .form-group.form-group-lg
|
||||||
= text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "N° de dossier", :id => "dossier_id", :name => "dossier_id"
|
/ = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "N° de dossier", :id => "dossier_id", :name => "dossier_id"
|
||||||
%br
|
/ %br
|
||||||
= submit_tag "Accéder", class: %w(btn btn-lg btn-success), style: 'margin-top:20px;', data: { disable_with: "Accéder", submit: true}
|
/ = submit_tag "Accéder", class: %w(btn btn-lg btn-success), style: 'margin-top:20px;', data: { disable_with: "Accéder", submit: true}
|
||||||
-else
|
/ -else
|
||||||
= form_tag(url_for({controller: 'user/sessions', action: :create}), class: 'form-inline', method: 'POST') do
|
/ = form_tag(url_for({controller: 'user/sessions', action: :create}), class: 'form-inline', method: 'POST') do
|
||||||
.form-group.form-group-lg
|
/ .form-group.form-group-lg
|
||||||
= text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "Identifiant", :id => "user_email", :name => "user[email]"
|
/ = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "Identifiant", :id => "user_email", :name => "user[email]"
|
||||||
%br
|
/ %br
|
||||||
= password_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "Mot de passe", :id => "user_password", :name => "user[password]"
|
/ = password_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "Mot de passe", :id => "user_password", :name => "user[password]"
|
||||||
%br
|
/ %br
|
||||||
= text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "N° de dossier", :id => "dossier_id", :name => "dossier_id"
|
/ = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "N° de dossier", :id => "dossier_id", :name => "dossier_id"
|
||||||
%br
|
/ %br
|
||||||
= submit_tag "Accéder", class: %w(btn btn-lg btn-success), style: 'margin-top:20px;', data: { disable_with: "Accéder", submit: true}
|
/ = submit_tag "Accéder", class: %w(btn btn-lg btn-success), style: 'margin-top:20px;', data: { disable_with: "Accéder", submit: true}
|
||||||
|
|
|
@ -3,5 +3,7 @@
|
||||||
%br
|
%br
|
||||||
%p{style: 'width:67%; margin-left:auto; margin-right:auto'}
|
%p{style: 'width:67%; margin-left:auto; margin-right:auto'}
|
||||||
Site de démonstration d’un service public de saisie d’un projet ou de dépôt d’une démarche administrative, auprès d’un ou plusieurs organismes publics, simplifié des informations déjà connues des administrations, grâce à la fourniture du numéro SIRET.
|
Site de démonstration d’un service public de saisie d’un projet ou de dépôt d’une démarche administrative, auprès d’un ou plusieurs organismes publics, simplifié des informations déjà connues des administrations, grâce à la fourniture du numéro SIRET.
|
||||||
|
|
||||||
.row
|
.row
|
||||||
= render partial: '/start/pro'
|
= render partial: '/start/pro'
|
||||||
|
|
||||||
|
|
|
@ -20,4 +20,61 @@
|
||||||
# available at http://guides.rubyonrails.org/i18n.html.
|
# available at http://guides.rubyonrails.org/i18n.html.
|
||||||
|
|
||||||
fr:
|
fr:
|
||||||
hello: "Bonjour le monde"
|
devise:
|
||||||
|
confirmations:
|
||||||
|
confirmed: 'Votre compte a été confirmé avec succès.'
|
||||||
|
send_instructions: 'Vous allez recevoir un e-mail avec les instructions nécessaires à la confirmation de votre compte dans quelques minutes.'
|
||||||
|
send_paranoid_instructions: 'Si votre e-mail existe dans notre base de données, vous allez bientôt recevoir un e-mail contenant les instructions de confirmation de votre compte.'
|
||||||
|
failure:
|
||||||
|
already_authenticated: "Vous êtes déjà connecté"
|
||||||
|
inactive: "Votre compte n'est pas encore activé."
|
||||||
|
invalid: "%{authentication_keys} ou mot de passe incorrect."
|
||||||
|
locked: "Votre compte est verrouillé."
|
||||||
|
last_attempt: "Vous avez droit à une tentative avant que votre compte ne soit verrouillé."
|
||||||
|
locked: "Votre compte est verrouillé."
|
||||||
|
not_found_in_database: "%{authentication_keys} ou mot de passe incorrect."
|
||||||
|
timeout: "Votre session est expirée. Veuillez vous reconnecter pour continuer."
|
||||||
|
unauthenticated: "Vous devez vous connecter ou vous inscrire pour continuer."
|
||||||
|
unconfirmed: "Vous devez confirmer votre compte pour continuer."
|
||||||
|
mailer:
|
||||||
|
confirmation_instructions:
|
||||||
|
subject: "Instructions de confirmation"
|
||||||
|
reset_password_instructions:
|
||||||
|
subject: "Instructions pour changer le mot de passe"
|
||||||
|
unlock_instructions:
|
||||||
|
subject: "Instructions pour déverrouiller le compte"
|
||||||
|
omniauth_callbacks:
|
||||||
|
failure: "Nous n'avons pas pu vous authentifier via %{kind} : '%{reason}'."
|
||||||
|
success: 'Authentifié avec succès via %{kind}.'
|
||||||
|
passwords:
|
||||||
|
no_token: "Vous ne pouvez accéder à cette page sans passer par un e-mail de réinitialisation de mot de passe. Si vous êtes passé par un e-mail de ce type, assurez-vous d'utiliser l'URL complète."
|
||||||
|
send_instructions: 'Vous allez recevoir les instructions de réinitialisation du mot de passe dans quelques instants'
|
||||||
|
send_paranoid_instructions: "Si votre e-mail existe dans notre base de données, vous allez recevoir un lien de réinitialisation par e-mail"
|
||||||
|
updated: 'Votre mot de passe a été édité avec succès, vous êtes maintenant connecté'
|
||||||
|
updated_not_active: 'Votre mot de passe a été changé avec succès.'
|
||||||
|
registrations:
|
||||||
|
destroyed: 'Votre compte a été supprimé avec succès. Nous espérons vous revoir bientôt.'
|
||||||
|
signed_up: 'Bienvenue, vous êtes connecté.'
|
||||||
|
signed_up_but_inactive: "Vous êtes bien enregistré. Vous ne pouvez cependant pas vous connecter car votre compte n'est pas encore activé."
|
||||||
|
signed_up_but_locked: "Vous êtes bien enregistré. Vous ne pouvez cependant pas vous connecter car votre compte est verrouillé."
|
||||||
|
signed_up_but_unconfirmed: 'Un message contenant un lien de confirmation a été envoyé à votre adresse email. Ouvrez ce lien pour confirmer votre compte.'
|
||||||
|
update_needs_confirmation: "Votre compte a bien été mis à jour mais nous devons vérifier votre nouvelle adresse email. Merci de vérifier vos emails et de cliquer sur le lien de confirmation pour finaliser la validation de votre nouvelle adresse."
|
||||||
|
updated: 'Votre compte a été modifié avec succès.'
|
||||||
|
sessions:
|
||||||
|
signed_in: "Connecté avec succès."
|
||||||
|
signed_out: "Déconnecté avec succès."
|
||||||
|
already_signed_out: "Déconnecté avec succès."
|
||||||
|
unlocks:
|
||||||
|
send_instructions: 'Vous allez recevoir les instructions nécessaires au déverrouillage de votre compte dans quelques instants'
|
||||||
|
send_paranoid_instructions: 'Si votre compte existe, vous allez bientôt recevoir un email contenant les instructions pour le déverrouiller.'
|
||||||
|
unlocked: 'Votre compte a été déverrouillé avec succès, veuillez vous connecter pour continuer.'
|
||||||
|
errors:
|
||||||
|
messages:
|
||||||
|
already_confirmed: "a déjà été validé(e), veuillez essayer de vous connecter"
|
||||||
|
confirmation_period_expired: "à confirmer dans les %{period}, merci de faire une nouvelle demande"
|
||||||
|
expired: "a expiré, merci d'en faire une nouvelle demande"
|
||||||
|
not_found: "n'a pas été trouvé(e)"
|
||||||
|
not_locked: "n'était pas verrouillé(e)"
|
||||||
|
not_saved:
|
||||||
|
one: "1 erreur a empêché ce(tte) %{resource} d'être sauvegardé(e) :"
|
||||||
|
other: "%{count} erreurs ont empêché ce(tte) %{resource} d'être sauvegardé(e) :"
|
|
@ -1,21 +1,9 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
devise_for :pros, controllers: {
|
devise_for :gestionnaires, controllers: {
|
||||||
sessions: 'sessions'
|
sessions: 'gestionnaires/sessions'
|
||||||
}, skip: [:password] #:registrations,
|
|
||||||
|
|
||||||
devise_for :users, controllers: {
|
}, skip: [:password, :registrations]
|
||||||
sessions: 'sessions'
|
|
||||||
}, skip: [:registrations, :password]
|
|
||||||
|
|
||||||
devise_scope :user do
|
|
||||||
post 'login', to: 'user/sessions#create'
|
|
||||||
delete 'logout', to: 'user/sessions#destroy'
|
|
||||||
end
|
|
||||||
|
|
||||||
devise_scope :pro do
|
|
||||||
post 'login_pro', to: 'pros/sessions#create'
|
|
||||||
delete 'logout_pro', to: 'pros/sessions#destroy'
|
|
||||||
end
|
|
||||||
|
|
||||||
root 'start#index'
|
root 'start#index'
|
||||||
|
|
||||||
|
@ -47,6 +35,13 @@ Rails.application.routes.draw do
|
||||||
post '/commentaire' => 'commentaires#create'
|
post '/commentaire' => 'commentaires#create'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
get 'backoffice' => 'backoffice#index'
|
||||||
|
|
||||||
|
namespace :backoffice do
|
||||||
|
get 'sign_in' => '/gestionnaires/sessions#new'
|
||||||
|
end
|
||||||
# The priority is based upon order of creation: first created -> highest priority.
|
# The priority is based upon order of creation: first created -> highest priority.
|
||||||
# See how all your routes lay out with "rake routes".
|
# See how all your routes lay out with "rake routes".
|
||||||
|
|
||||||
|
|
42
db/migrate/20150918163159_devise_create_gestionnaires.rb
Normal file
42
db/migrate/20150918163159_devise_create_gestionnaires.rb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
class DeviseCreateGestionnaires < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table(:gestionnaires) do |t|
|
||||||
|
## Database authenticatable
|
||||||
|
t.string :email, null: false, default: ""
|
||||||
|
t.string :encrypted_password, null: false, default: ""
|
||||||
|
|
||||||
|
## Recoverable
|
||||||
|
t.string :reset_password_token
|
||||||
|
t.datetime :reset_password_sent_at
|
||||||
|
|
||||||
|
## Rememberable
|
||||||
|
t.datetime :remember_created_at
|
||||||
|
|
||||||
|
## Trackable
|
||||||
|
t.integer :sign_in_count, default: 0, null: false
|
||||||
|
t.datetime :current_sign_in_at
|
||||||
|
t.datetime :last_sign_in_at
|
||||||
|
t.inet :current_sign_in_ip
|
||||||
|
t.inet :last_sign_in_ip
|
||||||
|
|
||||||
|
## Confirmable
|
||||||
|
# t.string :confirmation_token
|
||||||
|
# t.datetime :confirmed_at
|
||||||
|
# t.datetime :confirmation_sent_at
|
||||||
|
# t.string :unconfirmed_email # Only if using reconfirmable
|
||||||
|
|
||||||
|
## Lockable
|
||||||
|
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
||||||
|
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
||||||
|
# t.datetime :locked_at
|
||||||
|
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :gestionnaires, :email, unique: true
|
||||||
|
add_index :gestionnaires, :reset_password_token, unique: true
|
||||||
|
# add_index :gestionnaires, :confirmation_token, unique: true
|
||||||
|
# add_index :gestionnaires, :unlock_token, unique: true
|
||||||
|
end
|
||||||
|
end
|
22
db/schema.rb
22
db/schema.rb
|
@ -84,13 +84,31 @@ ActiveRecord::Schema.define(version: 20150921101240) do
|
||||||
t.integer "entreprise_id"
|
t.integer "entreprise_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "gestionnaires", force: :cascade do |t|
|
||||||
|
t.string "email", default: "", null: false
|
||||||
|
t.string "encrypted_password", default: "", null: false
|
||||||
|
t.string "reset_password_token"
|
||||||
|
t.datetime "reset_password_sent_at"
|
||||||
|
t.datetime "remember_created_at"
|
||||||
|
t.integer "sign_in_count", default: 0, null: false
|
||||||
|
t.datetime "current_sign_in_at"
|
||||||
|
t.datetime "last_sign_in_at"
|
||||||
|
t.inet "current_sign_in_ip"
|
||||||
|
t.inet "last_sign_in_ip"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "gestionnaires", ["email"], name: "index_gestionnaires_on_email", unique: true, using: :btree
|
||||||
|
add_index "gestionnaires", ["reset_password_token"], name: "index_gestionnaires_on_reset_password_token", unique: true, using: :btree
|
||||||
|
|
||||||
create_table "pieces_justificatives", force: :cascade do |t|
|
create_table "pieces_justificatives", force: :cascade do |t|
|
||||||
t.string "content"
|
t.string "content"
|
||||||
t.integer "dossier_id"
|
t.integer "dossier_id"
|
||||||
t.integer "type_piece_jointe_id"
|
t.integer "type_de_piece_justificative_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "pieces_justificatives", ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_piece_jointe_id", using: :btree
|
add_index "pieces_justificatives", ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_de_piece_justificative_id", using: :btree
|
||||||
|
|
||||||
create_table "procedures", force: :cascade do |t|
|
create_table "procedures", force: :cascade do |t|
|
||||||
t.string "libelle"
|
t.string "libelle"
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Admin::DossierController, type: :controller do
|
describe Admin::DossierController, type: :controller do
|
||||||
let(:dossier) { create(:dossier, :with_entreprise) }
|
let(:dossier) { create(:dossier, :with_entreprise) }
|
||||||
let(:dossier_id) { dossier.id }
|
let(:dossier_id) { dossier.id }
|
||||||
let(:bad_dossier_id) { Dossier.count + 10 }
|
let(:bad_dossier_id) { Dossier.count + 10 }
|
||||||
|
let(:gestionnaire) { create(:gestionnaire) }
|
||||||
|
|
||||||
describe 'GET #show' do
|
describe 'GET #show' do
|
||||||
context 'l\'utilisateur est connecté' do
|
context "l'utilisateur est connecté" do
|
||||||
before do
|
before do
|
||||||
sign_in
|
sign_in gestionnaire
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns http success' do
|
it 'returns http success' do
|
||||||
|
@ -16,24 +17,22 @@ RSpec.describe Admin::DossierController, type: :controller do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'le numéro de dossier n\'existe pas' do
|
it "le numéro de dossier n'existe pas" do
|
||||||
get :show, dossier_id: bad_dossier_id
|
get :show, dossier_id: bad_dossier_id
|
||||||
expect(response).to redirect_to('/start/error_dossier')
|
expect(response).to redirect_to('/start/error_dossier')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'L\'utilisateur n\'est pas connecté avec un dossier_id correct' do
|
context "L'utilisateur n'est pas connecté mais le numéro de dossier est correct" do
|
||||||
it do
|
subject { get :show, dossier_id: dossier_id }
|
||||||
get :show, dossier_id: dossier_id
|
it { is_expected.to redirect_to('/gestionnaires/sign_in') }
|
||||||
expect(response).to redirect_to('/')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #index' do
|
describe 'GET #index' do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
before do
|
before do
|
||||||
sign_in
|
sign_in gestionnaire
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'le numéro de dossier est correct' do
|
it 'le numéro de dossier est correct' do
|
||||||
|
|
7
spec/factories/gestionnaire.rb
Normal file
7
spec/factories/gestionnaire.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
FactoryGirl.define do
|
||||||
|
sequence(:gestionnaire_email) { |n| "plop#{n}@plop.com" }
|
||||||
|
factory :gestionnaire do
|
||||||
|
email { generate(:gestionnaire_email) }
|
||||||
|
password 'password'
|
||||||
|
end
|
||||||
|
end
|
|
@ -5,11 +5,12 @@ feature '_Commentaires_Flux Admin/Dossier#Show Page' do
|
||||||
let(:dossier_id) { dossier.id }
|
let(:dossier_id) { dossier.id }
|
||||||
let!(:commentaire) { create(:commentaire, dossier: dossier, email: 'toto@toto.com') }
|
let!(:commentaire) { create(:commentaire, dossier: dossier, email: 'toto@toto.com') }
|
||||||
let(:email_commentaire) { 'test@test.com' }
|
let(:email_commentaire) { 'test@test.com' }
|
||||||
|
let(:gestionnaire) { create(:gestionnaire) }
|
||||||
let(:email_pre_rempli) { 'toto@sgmap.fr' }
|
let(:email_pre_rempli) { 'toto@sgmap.fr' }
|
||||||
let(:body) { 'Commentaire de test' }
|
let(:body) { 'Commentaire de test' }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
login_admin
|
login_as gestionnaire, scope: :gestionnaire
|
||||||
visit "/admin/dossiers/#{dossier_id}"
|
visit "/admin/dossiers/#{dossier_id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ feature '_Commentaires_Flux Admin/Dossier#Show Page' do
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Champs email est prérempli' do
|
scenario 'Champs email est prérempli' do
|
||||||
expect(page).to have_selector("input[id=email_commentaire][value='#{email_pre_rempli}']")
|
expect(page).to have_selector("input[id=email_commentaire][value='#{gestionnaire.email}']")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ feature 'Admin/Dossier#Show Page' do
|
||||||
let(:dossier_id) { dossier.id }
|
let(:dossier_id) { dossier.id }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
login_admin
|
login_gestionnaire
|
||||||
visit "/admin/dossiers/#{dossier_id}"
|
visit "/admin/dossiers/#{dossier_id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
31
spec/features/backoffice/connection_spec.rb
Normal file
31
spec/features/backoffice/connection_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
feature 'when gestionnaire come to /backoffice and is not authenticated' do
|
||||||
|
before do
|
||||||
|
visit backoffice_path
|
||||||
|
end
|
||||||
|
scenario 'he is redirected to /gestionnaires/sign_id' do
|
||||||
|
expect(page).to have_css('#gestionnaire_login')
|
||||||
|
end
|
||||||
|
context 'when user enter bad credentials' do
|
||||||
|
before do
|
||||||
|
page.find_by_id(:gestionnaire_email).set 'unknown@plop.com'
|
||||||
|
page.find_by_id(:gestionnaire_password).set 'password'
|
||||||
|
page.click_on 'Se connecter'
|
||||||
|
end
|
||||||
|
scenario 'he stay on the same page with an error' do
|
||||||
|
expect(page).to have_content('email ou mot de passe incorrect.')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
context 'when user enter good credentials' do
|
||||||
|
let(:gestionnaire) { create(:gestionnaire) }
|
||||||
|
before do
|
||||||
|
page.find_by_id(:gestionnaire_email).set gestionnaire.email
|
||||||
|
page.find_by_id(:gestionnaire_password).set gestionnaire.password
|
||||||
|
page.click_on 'Se connecter'
|
||||||
|
end
|
||||||
|
scenario 'he is redirected to /backoffice' do
|
||||||
|
expect(page).to have_css('#backoffice')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
19
spec/models/gestionnaire_spec.rb
Normal file
19
spec/models/gestionnaire_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe Gestionnaire, type: :model do
|
||||||
|
|
||||||
|
describe 'database column' do
|
||||||
|
it { is_expected.to have_db_column(:email) }
|
||||||
|
it { is_expected.to have_db_column(:encrypted_password) }
|
||||||
|
it { is_expected.to have_db_column(:reset_password_token) }
|
||||||
|
it { is_expected.to have_db_column(:reset_password_sent_at) }
|
||||||
|
it { is_expected.to have_db_column(:remember_created_at) }
|
||||||
|
it { is_expected.to have_db_column(:sign_in_count) }
|
||||||
|
it { is_expected.to have_db_column(:current_sign_in_at) }
|
||||||
|
it { is_expected.to have_db_column(:last_sign_in_at) }
|
||||||
|
it { is_expected.to have_db_column(:current_sign_in_ip) }
|
||||||
|
it { is_expected.to have_db_column(:last_sign_in_ip) }
|
||||||
|
it { is_expected.to have_db_column(:created_at) }
|
||||||
|
it { is_expected.to have_db_column(:updated_at) }
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,16 +1,6 @@
|
||||||
module ControllerHelpers
|
|
||||||
def sign_in(user = double('test@localhost.com'))
|
|
||||||
if user.nil?
|
|
||||||
allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, scope: :user)
|
|
||||||
allow(controller).to receive(:current_user).and_return(nil)
|
|
||||||
else
|
|
||||||
allow(request.env['warden']).to receive(:authenticate!).and_return(user)
|
|
||||||
allow(controller).to receive(:current_user).and_return(create(:user))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.include Devise::TestHelpers, type: :controller
|
config.include Devise::TestHelpers, type: :controller
|
||||||
config.include ControllerHelpers, type: :controller
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,11 @@ module FeatureHelpers
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def login_gestionnaire
|
||||||
|
gestionnaire = create(:gestionnaire)
|
||||||
|
login_as gestionnaire, scope: :gestionnaire
|
||||||
|
end
|
||||||
|
|
||||||
def create_dossier
|
def create_dossier
|
||||||
dossier = FactoryGirl.create(:dossier)
|
dossier = FactoryGirl.create(:dossier)
|
||||||
dossier
|
dossier
|
||||||
|
|
9
spec/views/backoffice/index.html.haml_spec.rb
Normal file
9
spec/views/backoffice/index.html.haml_spec.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'backoffice/index.html.haml', type: :view do
|
||||||
|
before do
|
||||||
|
render
|
||||||
|
end
|
||||||
|
it { expect(rendered).to have_css('#backoffice') }
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in a new issue