commit
b51186d063
11 changed files with 6 additions and 287 deletions
|
@ -1,59 +1,4 @@
|
||||||
class Administrateurs::PasswordsController < Devise::PasswordsController
|
class Administrateurs::PasswordsController < ApplicationController
|
||||||
after_action :try_to_authenticate_user, only: [:update]
|
|
||||||
after_action :try_to_authenticate_instructeur, only: [:update]
|
|
||||||
|
|
||||||
# GET /resource/password/new
|
|
||||||
# def new
|
|
||||||
# super
|
|
||||||
# end
|
|
||||||
|
|
||||||
# POST /resource/password
|
|
||||||
# def create
|
|
||||||
# super
|
|
||||||
# end
|
|
||||||
|
|
||||||
# GET /resource/password/edit?reset_password_token=abcdef
|
|
||||||
# def edit
|
|
||||||
# super
|
|
||||||
# end
|
|
||||||
|
|
||||||
# PUT /resource/password
|
|
||||||
# def update
|
|
||||||
# # params[:user][:password_confirmation] = params[:user][:password]
|
|
||||||
# super
|
|
||||||
# end
|
|
||||||
|
|
||||||
# protected
|
|
||||||
|
|
||||||
# def after_resetting_password_path_for(resource)
|
|
||||||
# super(resource)
|
|
||||||
# end
|
|
||||||
|
|
||||||
# The path used after sending reset password instructions
|
|
||||||
# def after_sending_reset_password_instructions_path_for(resource_name)
|
|
||||||
# super(resource_name)
|
|
||||||
# end
|
|
||||||
|
|
||||||
def try_to_authenticate_user
|
|
||||||
if administrateur_signed_in?
|
|
||||||
user = User.find_by(email: current_administrateur.email)
|
|
||||||
|
|
||||||
if user
|
|
||||||
sign_in user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def try_to_authenticate_instructeur
|
|
||||||
if administrateur_signed_in?
|
|
||||||
instructeur = Instructeur.find_by(email: current_administrateur.email)
|
|
||||||
|
|
||||||
if instructeur
|
|
||||||
sign_in instructeur
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_strength
|
def test_strength
|
||||||
@score, @words, @length = ZxcvbnService.new(password_params[:password]).complexity
|
@score, @words, @length = ZxcvbnService.new(password_params[:password]).complexity
|
||||||
@min_length = PASSWORD_MIN_LENGTH
|
@min_length = PASSWORD_MIN_LENGTH
|
||||||
|
@ -64,6 +9,6 @@ class Administrateurs::PasswordsController < Devise::PasswordsController
|
||||||
private
|
private
|
||||||
|
|
||||||
def password_params
|
def password_params
|
||||||
params.require(:administrateur).permit(:reset_password_token, :password)
|
params.require(:administrateur).permit(:password)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
class Administrateurs::SessionsController < Sessions::SessionsController
|
|
||||||
def new
|
|
||||||
redirect_to new_user_session_path
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_sign_in_path_for(resource)
|
|
||||||
admin_procedures_path
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -119,7 +119,7 @@ module Instructeurs
|
||||||
elsif avis.instructeur&.email == params[:email]
|
elsif avis.instructeur&.email == params[:email]
|
||||||
# the avis instructeur has already signed up and it sould sign in
|
# the avis instructeur has already signed up and it sould sign in
|
||||||
|
|
||||||
redirect_to new_instructeur_session_url
|
redirect_to new_user_session_url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
class Instructeurs::PasswordsController < Devise::PasswordsController
|
|
||||||
after_action :try_to_authenticate_user, only: [:update]
|
|
||||||
after_action :try_to_authenticate_administrateur, only: [:update]
|
|
||||||
|
|
||||||
# GET /resource/password/new
|
|
||||||
# def new
|
|
||||||
# super
|
|
||||||
# end
|
|
||||||
|
|
||||||
# POST /resource/password
|
|
||||||
# def create
|
|
||||||
# super
|
|
||||||
# end
|
|
||||||
|
|
||||||
# GET /resource/password/edit?reset_password_token=abcdef
|
|
||||||
# def edit
|
|
||||||
# super
|
|
||||||
# end
|
|
||||||
|
|
||||||
# PUT /resource/password
|
|
||||||
# def update
|
|
||||||
# super
|
|
||||||
# end
|
|
||||||
|
|
||||||
# protected
|
|
||||||
|
|
||||||
# def after_resetting_password_path_for(resource)
|
|
||||||
# super(resource)
|
|
||||||
# end
|
|
||||||
|
|
||||||
# The path used after sending reset password instructions
|
|
||||||
# def after_sending_reset_password_instructions_path_for(resource_name)
|
|
||||||
# super(resource_name)
|
|
||||||
# end
|
|
||||||
|
|
||||||
def try_to_authenticate_user
|
|
||||||
if instructeur_signed_in?
|
|
||||||
user = User.find_by(email: current_instructeur.email)
|
|
||||||
|
|
||||||
if user
|
|
||||||
sign_in user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def try_to_authenticate_administrateur
|
|
||||||
if instructeur_signed_in?
|
|
||||||
administrateur = Administrateur.find_by(email: current_instructeur.email)
|
|
||||||
|
|
||||||
if administrateur
|
|
||||||
sign_in administrateur
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,9 +0,0 @@
|
||||||
class Instructeurs::SessionsController < Sessions::SessionsController
|
|
||||||
def new
|
|
||||||
redirect_to new_user_session_path
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -77,15 +77,9 @@ Rails.application.routes.draw do
|
||||||
omniauth_callbacks: 'administrations/omniauth_callbacks'
|
omniauth_callbacks: 'administrations/omniauth_callbacks'
|
||||||
}
|
}
|
||||||
|
|
||||||
devise_for :administrateurs, controllers: {
|
devise_for :administrateurs, skip: :all
|
||||||
sessions: 'administrateurs/sessions',
|
|
||||||
passwords: 'administrateurs/passwords'
|
|
||||||
}, skip: [:registrations]
|
|
||||||
|
|
||||||
devise_for :instructeurs, controllers: {
|
devise_for :instructeurs, skip: :all
|
||||||
sessions: 'instructeurs/sessions',
|
|
||||||
passwords: 'instructeurs/passwords'
|
|
||||||
}, skip: [:registrations]
|
|
||||||
|
|
||||||
devise_for :users, controllers: {
|
devise_for :users, controllers: {
|
||||||
sessions: 'users/sessions',
|
sessions: 'users/sessions',
|
||||||
|
@ -95,20 +89,12 @@ Rails.application.routes.draw do
|
||||||
}
|
}
|
||||||
|
|
||||||
devise_scope :user do
|
devise_scope :user do
|
||||||
get '/users/sign_in/demo' => redirect("/users/sign_in")
|
|
||||||
get '/users/no_procedure' => 'users/sessions#no_procedure'
|
get '/users/no_procedure' => 'users/sessions#no_procedure'
|
||||||
get 'connexion-par-jeton/:id' => 'users/sessions#sign_in_by_link', as: 'sign_in_by_link'
|
get 'connexion-par-jeton/:id' => 'users/sessions#sign_in_by_link', as: 'sign_in_by_link'
|
||||||
get 'lien-envoye/:email' => 'users/sessions#link_sent', constraints: { email: /.*/ }, as: 'link_sent'
|
get 'lien-envoye/:email' => 'users/sessions#link_sent', constraints: { email: /.*/ }, as: 'link_sent'
|
||||||
end
|
end
|
||||||
|
|
||||||
devise_scope :instructeur do
|
|
||||||
get '/instructeurs/sign_in/demo' => redirect("/users/sign_in")
|
|
||||||
get '/instructeurs/edit' => 'instructeurs/registrations#edit', :as => 'edit_instructeurs_registration'
|
|
||||||
put '/instructeurs' => 'instructeurs/registrations#update', :as => 'instructeurs_registration'
|
|
||||||
end
|
|
||||||
|
|
||||||
devise_scope :administrateur do
|
devise_scope :administrateur do
|
||||||
get '/administrateurs/sign_in/demo' => redirect("/users/sign_in")
|
|
||||||
get '/administrateurs/password/test_strength' => 'administrateurs/passwords#test_strength'
|
get '/administrateurs/password/test_strength' => 'administrateurs/passwords#test_strength'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -178,7 +164,6 @@ Rails.application.routes.draw do
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
get 'activate' => '/administrateurs/activate#new'
|
get 'activate' => '/administrateurs/activate#new'
|
||||||
patch 'activate' => '/administrateurs/activate#create'
|
patch 'activate' => '/administrateurs/activate#create'
|
||||||
get 'sign_in' => '/administrateurs/sessions#new'
|
|
||||||
get 'procedures/archived' => 'procedures#archived'
|
get 'procedures/archived' => 'procedures#archived'
|
||||||
get 'procedures/draft' => 'procedures#draft'
|
get 'procedures/draft' => 'procedures#draft'
|
||||||
get 'procedures/path_list' => 'procedures#path_list'
|
get 'procedures/path_list' => 'procedures#path_list'
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe Administrateurs::SessionsController, type: :controller do
|
|
||||||
before do
|
|
||||||
@request.env["devise.mapping"] = Devise.mappings[:administrateur]
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#create' do
|
|
||||||
it { expect(described_class).to be < Sessions::SessionsController }
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -229,7 +229,7 @@ describe Instructeurs::AvisController, type: :controller do
|
||||||
get :sign_up, params: { id: avis.id, email: invited_email }
|
get :sign_up, params: { id: avis.id, email: invited_email }
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to redirect_to new_instructeur_session_url }
|
it { is_expected.to redirect_to new_user_session_url }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
require "spec_helper"
|
|
||||||
|
|
||||||
describe Instructeurs::PasswordsController, type: :controller do
|
|
||||||
before do
|
|
||||||
@request.env["devise.mapping"] = Devise.mappings[:instructeur]
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "update" do
|
|
||||||
context "unified login" do
|
|
||||||
let(:user) { create(:user, email: 'unique@plop.com', password: 'démarches-simplifiées-pwd') }
|
|
||||||
let(:administrateur) { create(:administrateur, email: 'unique@plop.com', password: 'démarches-simplifiées-pwd') }
|
|
||||||
let(:instructeur) { administrateur.instructeur }
|
|
||||||
|
|
||||||
before do
|
|
||||||
@token = instructeur.send(:set_reset_password_token)
|
|
||||||
user # make sure it's created
|
|
||||||
administrateur # make sure it's created
|
|
||||||
end
|
|
||||||
|
|
||||||
it "also signs user in" do
|
|
||||||
put :update, params: {
|
|
||||||
instructeur: {
|
|
||||||
reset_password_token: @token,
|
|
||||||
password: "démarches-simplifiées-pwd",
|
|
||||||
password_confirmation: "démarches-simplifiées-pwd"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect(subject.current_instructeur).to eq(instructeur)
|
|
||||||
expect(subject.current_user).to eq(user)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "also signs administrateur in" do
|
|
||||||
put :update, params: {
|
|
||||||
instructeur: {
|
|
||||||
reset_password_token: @token,
|
|
||||||
password: "démarches-simplifiées-pwd",
|
|
||||||
password_confirmation: "démarches-simplifiées-pwd"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect(subject.current_administrateur).to eq(administrateur)
|
|
||||||
expect(subject.current_user).to eq(user)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,11 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe Instructeurs::SessionsController, type: :controller do
|
|
||||||
before do
|
|
||||||
@request.env["devise.mapping"] = Devise.mappings[:instructeur]
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#create' do
|
|
||||||
it { expect(described_class).to be < Sessions::SessionsController }
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,67 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
feature 'Administrator connection' do
|
|
||||||
include ActiveJob::TestHelper
|
|
||||||
|
|
||||||
let(:email) { 'admin1@admin.com' }
|
|
||||||
let(:password) { 'mon chien aime les bananes' }
|
|
||||||
let!(:admin) { create(:administrateur, :with_procedure, email: email, password: password) }
|
|
||||||
let!(:user) { create(:user, email: email, password: password) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
Flipflop::FeatureSet.current.test!.switch!(:enable_email_login_token, true)
|
|
||||||
visit new_administrateur_session_path
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'administrator is on sign in page' do
|
|
||||||
expect(page).to have_css('#new_user')
|
|
||||||
end
|
|
||||||
|
|
||||||
context "admin fills form and log in" do
|
|
||||||
before do
|
|
||||||
sign_in_with(email, password, true)
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'a menu button is available' do
|
|
||||||
expect(page).to have_css('#admin_menu')
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when he click on the menu' do
|
|
||||||
before do
|
|
||||||
page.find_by_id('admin_menu').click
|
|
||||||
end
|
|
||||||
scenario 'it displays the menu' do
|
|
||||||
expect(page).to have_css('a#profile')
|
|
||||||
expect(page).to have_css('#sign-out')
|
|
||||||
end
|
|
||||||
context 'when clicking on sign-out' do
|
|
||||||
before do
|
|
||||||
stub_request(:get, "https://api.github.com/repos/betagouv/tps/releases/latest")
|
|
||||||
.to_return(:status => 200, :body => '{"tag_name": "plip", "body": "blabla", "published_at": "2016-02-09T16:46:47Z"}', :headers => {})
|
|
||||||
|
|
||||||
page.find_by_id('sign-out').find('a').click
|
|
||||||
end
|
|
||||||
scenario 'admin is redireted to home page' do
|
|
||||||
expect(page).to have_css('.landing')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
context 'when clicking on profile' do
|
|
||||||
before do
|
|
||||||
page.find_by_id('profile').click
|
|
||||||
end
|
|
||||||
scenario 'it redirects to profile page' do
|
|
||||||
expect(page).to have_css('#profil-page')
|
|
||||||
end
|
|
||||||
context 'when clicking on procedure' do
|
|
||||||
before do
|
|
||||||
page.click_on('Tableau de bord').click
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'it redirects to procedure page' do
|
|
||||||
expect(page).to have_content('Démarches')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in a new issue