Connexion page is contextualized with procedure title and description when is access with link.

This commit is contained in:
Xavier J 2016-05-26 15:59:50 +02:00
parent 95bb773275
commit 4d1cb9ecfe
9 changed files with 115 additions and 21 deletions

View file

@ -11,7 +11,13 @@ class Users::SessionsController < Sessions::SessionsController
# GET /resource/sign_in # GET /resource/sign_in
def new def new
unless user_return_to_procedure_id.nil?
@dossier = Dossier.new(procedure: Procedure.not_archived(user_return_to_procedure_id))
end
@user = User.new @user = User.new
rescue ActiveRecord::RecordNotFound
error_procedure
end end
#POST /resource/sign_in #POST /resource/sign_in
@ -39,10 +45,21 @@ class Users::SessionsController < Sessions::SessionsController
end end
end end
# protected def no_procedure
session['user_return_to'] = nil
# You can put the params you want to permit in the empty array. redirect_to new_user_session_path
# def configure_sign_in_params end
# devise_parameter_sanitizer.for(:sign_in) << :attribute
# end private
def error_procedure
flash.alert = t('errors.messages.procedure_not_found')
redirect_to url_for root_path
end
def user_return_to_procedure_id
return nil if session["user_return_to"].nil?
NumberService.to_number session["user_return_to"].split("?procedure_id=").second
end
end end

View file

@ -25,6 +25,10 @@ class Procedure < ActiveRecord::Base
types_de_champ.order(:order_place) types_de_champ.order(:order_place)
end end
def self.not_archived id
Procedure.where(archived: false).find(id)
end
def switch_types_de_champ index_of_first_element def switch_types_de_champ index_of_first_element
return false if index_of_first_element < 0 return false if index_of_first_element < 0
types_de_champ_tmp = types_de_champ_ordered types_de_champ_tmp = types_de_champ_ordered

View file

@ -0,0 +1,5 @@
class NumberService
def self.to_number string
string.to_s if Float(string) rescue nil
end
end

View file

@ -0,0 +1,11 @@
- if @dossier.procedure.euro_flag
#euro_flag.flag
=image_tag('drapeau_europe.png')
#logo_procedure.flag
=image_tag( @dossier.procedure.decorate.logo_img )
%h2#titre_procedure.text-info
= @dossier.procedure.libelle
%p
= h @dossier.procedure.description.html_safe

View file

@ -1,20 +1,7 @@
.container.center#users_siret_index .container.center#users_siret_index
.row .row
%p.lead{id: 'pro_section'} %p.lead{id: 'pro_section', style:'padding-top: 120px'}
%br = render partial: 'title_procedure'
%br
- if @dossier.procedure.euro_flag
#euro_flag.flag
=image_tag('drapeau_europe.png')
#logo_procedure.flag
=image_tag( @dossier.procedure.decorate.logo_img )
%h2#titre_procedure.text-info
= @dossier.procedure.libelle
%p
= h @dossier.procedure.description.html_safe
%br %br
= form_for @dossier, url: {controller: 'users/dossiers', action: :create}, method: :post do |f| = form_for @dossier, url: {controller: 'users/dossiers', action: :create}, method: :post do |f|

View file

@ -1,6 +1,12 @@
#form_login #form_login
= image_tag('logo-tps.png')
%br %br
- if @dossier
= link_to 'X', users_no_procedure_url, class: 'btn btn-xs', style:'float: right'
= render partial: 'users/dossiers/title_procedure'
- else
= image_tag('logo-tps.png', {id: 'logo_tps'})
%br
%h2#login_user Connexion %h2#login_user Connexion
%a.btn_fc#btn_fcp{href: '/france_connect/particulier'} %a.btn_fc#btn_fcp{href: '/france_connect/particulier'}

View file

@ -18,6 +18,7 @@ Rails.application.routes.draw do
devise_scope :user do devise_scope :user do
get '/users/sign_in/demo' => 'users/sessions#demo' get '/users/sign_in/demo' => 'users/sessions#demo'
get '/users/no_procedure' => 'users/sessions#no_procedure'
end end
devise_scope :gestionnaire do devise_scope :gestionnaire do

View file

@ -67,4 +67,33 @@ describe Users::SessionsController, type: :controller do
end end
end end
end end
describe '.new' do
subject { get :new }
context 'when procedure_id is not present in user_return_to session params' do
it { expect(subject.status).to eq 200}
end
context 'when procedure_id is present in user_return_to session params' do
context 'when procedure_id does not exist' do
before do
session["user_return_to"] = '?procedure_id=0'
end
it { expect(subject.status).to eq 302}
it { expect(subject).to redirect_to root_path }
end
context 'when procedure_id exist' do
let(:procedure) { create :procedure }
before do
session["user_return_to"] = "?procedure_id=#{procedure.id}"
end
it { expect(subject.status).to eq 200}
end
end
end
end end

View file

@ -0,0 +1,34 @@
require 'spec_helper'
describe 'users/sessions/new.html.haml', type: :view do
let(:dossier) { create :dossier }
before(:each) do
allow(view).to receive(:devise_mapping).and_return(Devise.mappings[:user])
allow(view).to receive(:resource_name).and_return(:user)
end
before do
assign(:user, User.new)
end
context 'when user_return_to session params contains a procedure_id' do
before do
assign(:dossier, dossier)
render
end
it { expect(rendered).to have_selector('#form_login #logo_procedure') }
it { expect(rendered).to have_selector('#form_login #titre_procedure') }
it { expect(rendered).to have_content(dossier.procedure.libelle) }
it { expect(rendered).to have_content(dossier.procedure.description) }
end
context 'when user_return_to session params not contains a procedure_id' do
before do
render
end
it { expect(rendered).to have_selector('#form_login #logo_tps') }
end
end