diff --git a/app/controllers/admin/gestionnaires_controller.rb b/app/controllers/admin/gestionnaires_controller.rb index e3ddc27a6..421eaa240 100644 --- a/app/controllers/admin/gestionnaires_controller.rb +++ b/app/controllers/admin/gestionnaires_controller.rb @@ -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 \ No newline at end of file +end diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index c053d3f16..70c4d7ba7 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -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}") diff --git a/app/models/user.rb b/app/models/user.rb index 31bc7779e..23794964c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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) diff --git a/app/views/backoffice/dossiers/_onglets.html.haml b/app/views/backoffice/dossiers/_onglets.html.haml index 6b366d70e..9018c1144 100644 --- a/app/views/backoffice/dossiers/_onglets.html.haml +++ b/app/views/backoffice/dossiers/_onglets.html.haml @@ -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 \ No newline at end of file +%br diff --git a/app/views/backoffice/dossiers/index.html.haml b/app/views/backoffice/dossiers/index.html.haml index b6473abf4..c37cde902 100644 --- a/app/views/backoffice/dossiers/index.html.haml +++ b/app/views/backoffice/dossiers/index.html.haml @@ -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 diff --git a/app/views/layouts/_navbar.html.haml b/app/views/layouts/_navbar.html.haml index 5d99553f4..47dd43354 100644 --- a/app/views/layouts/_navbar.html.haml +++ b/app/views/layouts/_navbar.html.haml @@ -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' diff --git a/app/views/users/dossiers/_onglets.html.haml b/app/views/users/dossiers/_onglets.html.haml index de6a40156..de53b9039 100644 --- a/app/views/users/dossiers/_onglets.html.haml +++ b/app/views/users/dossiers/_onglets.html.haml @@ -1,5 +1,3 @@ -%h1 Mes dossiers - %br #onglets %ul.nav.nav-tabs diff --git a/app/views/users/dossiers/index.html.haml b/app/views/users/dossiers/index.html.haml index f7931ed8f..a692b6ea2 100644 --- a/app/views/users/dossiers/index.html.haml +++ b/app/views/users/dossiers/index.html.haml @@ -1,5 +1,8 @@ #users_index - = render partial: 'onglets' + %h1 Mes dossiers + + -unless Features.opensimplif + = render partial: 'onglets' = smart_listing_render :dossiers diff --git a/spec/controllers/admin/gestionnaires_controller_spec.rb b/spec/controllers/admin/gestionnaires_controller_spec.rb index 61ce9e98d..f00c5970c 100644 --- a/spec/controllers/admin/gestionnaires_controller_spec.rb +++ b/spec/controllers/admin/gestionnaires_controller_spec.rb @@ -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 \ No newline at end of file +end diff --git a/spec/controllers/gestionnaires/passwords_controller_spec.rb b/spec/controllers/gestionnaires/passwords_controller_spec.rb index 004beabb7..c094f606e 100644 --- a/spec/controllers/gestionnaires/passwords_controller_spec.rb +++ b/spec/controllers/gestionnaires/passwords_controller_spec.rb @@ -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 diff --git a/spec/controllers/root_controller_spec.rb b/spec/controllers/root_controller_spec.rb index 9dae45c6b..a96f202cf 100644 --- a/spec/controllers/root_controller_spec.rb +++ b/spec/controllers/root_controller_spec.rb @@ -40,4 +40,18 @@ describe RootController, type: :controller do it { expect(response.body).to have_css('#landing') } end -end \ No newline at end of file + + 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 diff --git a/spec/controllers/users/passwords_controller_spec.rb b/spec/controllers/users/passwords_controller_spec.rb index 72e38aa73..83d877b4e 100644 --- a/spec/controllers/users/passwords_controller_spec.rb +++ b/spec/controllers/users/passwords_controller_spec.rb @@ -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 diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb index 418f4fbbd..1f51dc107 100644 --- a/spec/controllers/users/sessions_controller_spec.rb +++ b/spec/controllers/users/sessions_controller_spec.rb @@ -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 } diff --git a/spec/features/backoffice/onglets_link_spec.rb b/spec/features/backoffice/onglets_link_spec.rb index b88c9347c..e0d61d38c 100644 --- a/spec/features/backoffice/onglets_link_spec.rb +++ b/spec/features/backoffice/onglets_link_spec.rb @@ -89,4 +89,16 @@ feature 'on click on tabs button' do end end end -end \ No newline at end of file + + 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 diff --git a/spec/features/users/onglets_link_spec.rb b/spec/features/users/onglets_link_spec.rb index f2cb8c7b3..3685869c1 100644 --- a/spec/features/users/onglets_link_spec.rb +++ b/spec/features/users/onglets_link_spec.rb @@ -99,4 +99,15 @@ feature 'on click on tabs button' do end end end -end \ No newline at end of file + + 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 diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index 21cacaf59..61f71acec 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 41243be83..3cbb0283c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bbbac8b2e..38f9934da 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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|