Merge pull request #3 from sgmap/open-unified-login

Unified login (more) + OpenSimplif
This commit is contained in:
XjulI1 2016-10-19 10:35:19 +02:00 committed by GitHub
commit 408728856f
18 changed files with 132 additions and 44 deletions

View file

@ -21,8 +21,11 @@ class Admin::GestionnairesController < AdminController
assign_gestionnaire!
end
return redirect_to admin_procedure_accompagnateurs_path(procedure_id: procedure_id) unless procedure_id.nil?
redirect_to admin_gestionnaires_path
if procedure_id
redirect_to admin_procedure_accompagnateurs_path(procedure_id: procedure_id)
else
redirect_to admin_gestionnaires_path
end
end
def destroy
@ -30,19 +33,18 @@ class Admin::GestionnairesController < AdminController
redirect_to admin_gestionnaires_path
end
def create_gestionnaire_params
params.require(:gestionnaire).permit(:email)
.merge(password: SecureRandom.hex(5))
.merge(administrateurs: [current_administrateur])
end
private
def new_gestionnaire!
@gestionnaire = Gestionnaire.create(create_gestionnaire_params)
attributes = params.require(:gestionnaire).permit(:email)
.merge(password: SecureRandom.hex(5))
@gestionnaire = Gestionnaire.create(attributes.merge(
administrateurs: [current_administrateur]
))
if @gestionnaire.errors.messages.empty?
User.create(attributes) if Features.unified_login
flash.notice = 'Accompagnateur ajouté'
GestionnaireMailer.new_gestionnaire(@gestionnaire.email, @gestionnaire.password).deliver_now!
GestionnaireMailer.new_assignement(@gestionnaire.email, current_administrateur.email).deliver_now!
@ -61,4 +63,4 @@ class Admin::GestionnairesController < AdminController
#TODO Mailer no assign_to
end
end
end
end

View file

@ -14,7 +14,7 @@ class Gestionnaire < ActiveRecord::Base
after_create :build_default_preferences_list_dossier
after_create :build_default_preferences_smart_listing_page
after_save :sync_credentials
after_update :sync_credentials, if: -> { Features.unified_login }
def dossiers_follow
dossiers.joins(:follows).where("follows.gestionnaire_id = #{id}")

View file

@ -15,8 +15,7 @@ class User < ActiveRecord::Base
delegate :given_name, :family_name, :email_france_connect, :gender, :birthdate, :birthplace, :france_connect_particulier_id, to: :france_connect_information
accepts_nested_attributes_for :france_connect_information
after_update :sync_credentials
after_update :sync_credentials, if: -> { Features.unified_login }
def self.find_for_france_connect email, siret
user = User.find_by_email(email)

View file

@ -1,6 +1,3 @@
=link_to 'Tous mes dossiers en CSV', backoffice_download_dossiers_tps_path, {class: 'btn btn-success btn-sm', style: 'float: right; margin-right: 4%; margin-top: 7px'}
%h1 Gestion des dossiers
#filter_by_procedure{style:'margin-left: 5%'}
%select{onchange: 'location = this.value', style:'margin-top: 10px; margin-bottom: 10px', id: 'filter_by_procedure_select'}
%option{value: backoffice_dossiers_path}
@ -67,4 +64,4 @@
%a.btn#pref_list_dossier_open_action{href: '#'}
%i.fa.fa-columns
%br
%br

View file

@ -1,7 +1,12 @@
#backoffice_index
#pref_list_menu
= render partial: 'backoffice/dossiers/pref_list'
= render partial: 'backoffice/dossiers/onglets'
=link_to 'Tous mes dossiers en CSV', backoffice_download_dossiers_tps_path, {class: 'btn btn-success btn-sm', style: 'float: right; margin-right: 4%; margin-top: 7px'}
%h1 Gestion des dossiers
-unless Features.opensimplif
= render partial: 'backoffice/dossiers/onglets'
= smart_listing_render :dossiers

View file

@ -31,7 +31,8 @@
= render partial: 'administrateurs/login_banner'
-else
= link_to "Utilisateur", '/users/sign_in', method: :get, :class => 'btn btn-md'
= link_to "Accompagnateur", '/gestionnaires/sign_in', method: :get, :class => 'btn btn-md'
-unless Features.unified_login
= link_to "Accompagnateur", '/gestionnaires/sign_in', method: :get, :class => 'btn btn-md'
= link_to "Administrateur", '/administrateurs/sign_in', method: :get, :class => 'btn btn-md'
- if Rails.env != 'production'

View file

@ -1,5 +1,3 @@
%h1 Mes dossiers
%br
#onglets
%ul.nav.nav-tabs

View file

@ -1,5 +1,8 @@
#users_index
= render partial: 'onglets'
%h1 Mes dossiers
-unless Features.opensimplif
= render partial: 'onglets'
= smart_listing_render :dossiers

View file

@ -147,6 +147,27 @@ describe Admin::GestionnairesController, type: :controller do
}
end
end
context 'unified login' do
before do
allow(Features).to receive(:unified_login).and_return(true)
subject
end
it "creates associated user with same credentials" do
gestionnaire = controller.instance_variable_get(:@gestionnaire)
user = User.find_by(email: gestionnaire.email)
expect(user.valid_password?(gestionnaire.password)).to be(true)
end
context 'invalid email' do
let(:email) { 'fail' }
it "won't create associated user" do
expect(User.where(email: email).exists?).to be(false)
end
end
end
end
describe 'DELETE #destroy' do
@ -171,4 +192,4 @@ describe Admin::GestionnairesController, type: :controller do
it { expect { subject }.not_to change(Gestionnaire, :count) }
end
end
end

View file

@ -6,11 +6,12 @@ describe Gestionnaires::PasswordsController, type: :controller do
end
describe "update" do
context "when associated gestionnaire" do
context "unified login" do
let(:gestionnaire) { create(:gestionnaire, email: 'unique@plop.com', password: 'password') }
let(:user) { create(:user, email: 'unique@plop.com', password: 'password') }
before do
allow(Features).to receive(:unified_login).and_return(true)
@token = gestionnaire.send(:set_reset_password_token)
user # make sure it's created
end

View file

@ -40,4 +40,18 @@ describe RootController, type: :controller do
it { expect(response.body).to have_css('#landing') }
end
end
context "unified login" do
render_views
before do
allow(Features).to receive(:unified_login).and_return(true)
subject
end
it "won't have gestionnaire login link" do
expect(response.body).to have_css("a[href='#{new_user_session_path}']")
expect(response.body).to_not have_css("a[href='#{new_gestionnaire_session_path}']")
end
end
end

View file

@ -6,11 +6,12 @@ describe Users::PasswordsController, type: :controller do
end
describe "update" do
context "when associated gestionnaire" do
context "unified login" do
let(:user) { create(:user, email: 'unique@plop.com', password: 'password') }
let(:gestionnaire) { create(:gestionnaire, email: 'unique@plop.com', password: 'password') }
before do
allow(Features).to receive(:unified_login).and_return(true)
@token = user.send(:set_reset_password_token)
gestionnaire # make sure it's created
end

View file

@ -34,9 +34,10 @@ describe Users::SessionsController, type: :controller do
it { is_expected.to be_falsey }
end
context "when associated gestionnaire" do
context "unified login" do
let(:user) { create(:user, email: 'unique@plop.com', password: 'password') }
let(:gestionnaire) { create(:gestionnaire, email: 'unique@plop.com', password: 'password') }
before { allow(Features).to receive(:unified_login).and_return(true) }
it 'signs user in' do
post :create, user: { email: user.email, password: user.password }

View file

@ -89,4 +89,16 @@ feature 'on click on tabs button' do
end
end
end
end
context "OpenSimplif" do
before do
allow(Features).to receive(:opensimplif).and_return(true)
visit backoffice_dossiers_url
end
scenario "it hides the tabs" do
expect(page).to_not have_css('#filter_by_procedure')
expect(page).to_not have_css('#onglets')
end
end
end

View file

@ -99,4 +99,15 @@ feature 'on click on tabs button' do
end
end
end
end
context "OpenSimplif" do
before do
allow(Features).to receive(:opensimplif).and_return(true)
visit users_dossiers_url
end
scenario "it hides the tabs" do
expect(page).to_not have_css('#onglets')
end
end
end

View file

@ -185,14 +185,18 @@ describe Gestionnaire, type: :model do
end
end
it 'syncs credentials to associated user' do
gestionnaire = create(:gestionnaire)
user = create(:user, email: gestionnaire.email)
context 'unified login' do
before { allow(Features).to receive(:unified_login).and_return(true) }
gestionnaire.update_attributes(email: 'whoami@plop.com', password: 'super secret')
it 'syncs credentials to associated user' do
gestionnaire = create(:gestionnaire)
user = create(:user, email: gestionnaire.email)
user.reload
expect(user.email).to eq('whoami@plop.com')
expect(user.valid_password?('super secret')).to be(true)
gestionnaire.update_attributes(email: 'whoami@plop.com', password: 'super secret')
user.reload
expect(user.email).to eq('whoami@plop.com')
expect(user.valid_password?('super secret')).to be(true)
end
end
end

View file

@ -73,14 +73,18 @@ describe User, type: :model do
end
end
it 'syncs credentials to associated gestionnaire' do
user = create(:user)
gestionnaire = create(:gestionnaire, email: user.email)
context 'unified login' do
before { allow(Features).to receive(:unified_login).and_return(true) }
user.update_attributes(email: 'whoami@plop.com', password: 'super secret')
it 'syncs credentials to associated gestionnaire' do
user = create(:user)
gestionnaire = create(:gestionnaire, email: user.email)
gestionnaire.reload
expect(gestionnaire.email).to eq('whoami@plop.com')
expect(gestionnaire.valid_password?('super secret')).to be(true)
user.update_attributes(email: 'whoami@plop.com', password: 'super secret')
gestionnaire.reload
expect(gestionnaire.email).to eq('whoami@plop.com')
expect(gestionnaire.valid_password?('super secret')).to be(true)
end
end
end

View file

@ -75,6 +75,20 @@ module SmartListing
end
end
class Features
#def self.remote_storage
# true
#end
def self.unified_login
false
end
def self.opensimplif
false
end
end
WebMock.disable_net_connect!(allow_localhost: true)
RSpec.configure do |config|