refacto: rename administration to super_admin

This commit is contained in:
Christophe Robillard 2020-11-05 15:09:11 +01:00
parent a88172eb01
commit 5562e65bf3
39 changed files with 180 additions and 175 deletions

View file

@ -1,28 +0,0 @@
class AdministrationsController < ApplicationController
before_action :authenticate_administration!
def edit_otp
end
def enable_otp
current_administration.enable_otp!
@qrcode = generate_qr_code
sign_out :administration
end
protected
def authenticate_administration!
if !administration_signed_in?
redirect_to root_path
end
end
private
def generate_qr_code
issuer = 'DSManager'
label = "#{issuer}:#{current_administration.email}"
RQRCode::QRCode.new(current_administration.otp_provisioning_uri(label, issuer: issuer))
end
end

View file

@ -142,7 +142,7 @@ class ApplicationController < ActionController::Base
current_user,
current_instructeur,
current_administrateur,
current_administration
current_super_admin
].compact.map { |role| role.class.name }
roles.any? ? roles.join(', ') : 'Guest'
@ -180,11 +180,11 @@ class ApplicationController < ActionController::Base
authorized_request =
request.path_info == '/' ||
request.path_info.start_with?('/manager') ||
request.path_info.start_with?('/administrations')
request.path_info.start_with?('/super_admins')
api_request = request.path_info.start_with?('/api/')
if administration_signed_in? || authorized_request
if super_admin_signed_in? || authorized_request
flash.now.alert = MAINTENANCE_MESSAGE
elsif api_request
render json: { error: MAINTENANCE_MESSAGE }.to_json, status: :service_unavailable

View file

@ -1,7 +1,7 @@
module Manager
class AdministrateursController < Manager::ApplicationController
def create
administrateur = current_administration.invite_admin(create_administrateur_params[:email])
administrateur = current_super_admin.invite_admin(create_administrateur_params[:email])
if administrateur.errors.empty?
flash.notice = "Administrateur créé"
@ -14,7 +14,7 @@ module Manager
end
def reinvite
Administrateur.find_inactive_by_id(params[:id]).user.invite_administrateur!(current_administration.id)
Administrateur.find_inactive_by_id(params[:id]).user.invite_administrateur!(current_super_admin.id)
flash.notice = "Invitation renvoyée"
redirect_to manager_administrateur_path(params[:id])
end
@ -24,7 +24,7 @@ module Manager
administrateur.delete_and_transfer_services
logger.info("L'administrateur #{administrateur.id} est supprimé par #{current_administration.id}")
logger.info("L'administrateur #{administrateur.id} est supprimé par #{current_super_admin.id}")
flash[:notice] = "L'administrateur #{administrateur.id} est supprimé"
redirect_to manager_administrateurs_path

View file

@ -1,6 +1,6 @@
module Manager
class ApplicationController < Administrate::ApplicationController
before_action :authenticate_administration!
before_action :authenticate_super_admin!
before_action :default_params
def default_params
@ -12,13 +12,13 @@ module Manager
protected
def authenticate_administration!
if administration_signed_in? && current_administration.otp_required_for_login?
def authenticate_super_admin!
if super_admin_signed_in? && current_super_admin.otp_required_for_login?
super
elsif administration_signed_in?
redirect_to edit_administration_otp_path
elsif super_admin_signed_in?
redirect_to edit_super_admin_otp_path
else
redirect_to new_administration_session_path
redirect_to new_super_admin_session_path
end
end

View file

@ -5,12 +5,12 @@ module Manager
end
def create_administrateur
administrateur = current_administration.invite_admin(create_administrateur_params[:email])
administrateur = current_super_admin.invite_admin(create_administrateur_params[:email])
if administrateur.errors.empty?
PipedriveAcceptsDealsJob.perform_later(
create_administrateur_params[:person_id],
current_administration.id,
current_super_admin.id,
create_administrateur_params[:stage_id]
)
@ -26,7 +26,7 @@ module Manager
def refuse_administrateur
PipedriveRefusesDealsJob.perform_later(
refuse_administrateur_params[:person_id],
current_administration.id
current_super_admin.id
)
AdministrationMailer

View file

@ -22,9 +22,9 @@ module Manager
def discard
dossier = Dossier.find(params[:id])
dossier.discard_and_keep_track!(current_administration, :manager_request)
dossier.discard_and_keep_track!(current_super_admin, :manager_request)
logger.info("Le dossier #{dossier.id} est supprimé par #{current_administration.email}")
logger.info("Le dossier #{dossier.id} est supprimé par #{current_super_admin.email}")
flash[:notice] = "Le dossier #{dossier.id} a été supprimé."
redirect_to manager_dossier_path(dossier)
@ -32,7 +32,7 @@ module Manager
def restore
dossier = Dossier.with_discarded.find(params[:id])
dossier.restore(current_administration)
dossier.restore(current_super_admin)
flash[:notice] = "Le dossier #{dossier.id} a été restauré."
@ -41,9 +41,9 @@ module Manager
def repasser_en_instruction
dossier = Dossier.find(params[:id])
dossier.repasser_en_instruction(current_administration)
dossier.repasser_en_instruction(current_super_admin)
logger.info("Le dossier #{dossier.id} est repassé en instruction par #{current_administration.email}")
logger.info("Le dossier #{dossier.id} est repassé en instruction par #{current_super_admin.email}")
flash[:notice] = "Le dossier #{dossier.id} est repassé en instruction."
redirect_to manager_dossier_path(dossier)

View file

@ -15,7 +15,7 @@ module Manager
end
instructeur.destroy!
logger.info("L'instructeur #{instructeur.id} est supprimé par #{current_administration.id}")
logger.info("L'instructeur #{instructeur.id} est supprimé par #{current_super_admin.id}")
flash[:notice] = "L'instructeur #{instructeur.id} est supprimé"
redirect_to manager_instructeurs_path

View file

@ -23,16 +23,16 @@ module Manager
end
def discard
procedure.discard_and_keep_track!(current_administration)
procedure.discard_and_keep_track!(current_super_admin)
logger.info("La démarche #{procedure.id} est supprimée par #{current_administration.email}")
logger.info("La démarche #{procedure.id} est supprimée par #{current_super_admin.email}")
flash[:notice] = "La démarche #{procedure.id} a été supprimée."
redirect_to manager_procedure_path(procedure)
end
def restore
procedure.restore(current_administration)
procedure.restore(current_super_admin)
flash[:notice] = "La démarche #{procedure.id} a été restauré."

View file

@ -39,9 +39,9 @@ module Manager
if !user.can_be_deleted?
fail "Impossible de supprimer cet utilisateur. Il a des dossiers en instruction ou il est administrateur."
end
user.delete_and_keep_track_dossiers(current_administration)
user.delete_and_keep_track_dossiers(current_super_admin)
logger.info("L'utilisateur #{user.id} est supprimé par #{current_administration.id}")
logger.info("L'utilisateur #{user.id} est supprimé par #{current_super_admin.id}")
flash[:notice] = "L'utilisateur #{user.id} est supprimé"
redirect_to manager_users_path

View file

@ -8,7 +8,7 @@ class RootController < ApplicationController
return redirect_to instructeur_procedures_path
elsif user_signed_in?
return redirect_to dossiers_path
elsif administration_signed_in?
elsif super_admin_signed_in?
return redirect_to manager_root_path
end

View file

@ -1,5 +1,5 @@
class StatsController < ApplicationController
before_action :authenticate_administration!, only: [:download]
before_action :authenticate_super_admin!, only: [:download]
MEAN_NUMBER_OF_CHAMPS_IN_A_FORM = 24.0
@ -34,7 +34,7 @@ class StatsController < ApplicationController
@dossiers_cumulative = stat.dossiers_cumulative
@dossiers_in_the_last_4_months = stat.dossiers_in_the_last_4_months
if administration_signed_in?
if super_admin_signed_in?
@dossier_instruction_mean_time = Rails.cache.fetch("dossier_instruction_mean_time", expires_in: 1.day) do
dossier_instruction_mean_time(dossiers)
end
@ -201,7 +201,7 @@ class StatsController < ApplicationController
end
def max_date
if administration_signed_in?
if super_admin_signed_in?
Time.zone.now
else
Time.zone.now.beginning_of_month - 1.second

View file

@ -0,0 +1,28 @@
class SuperAdminsController < ApplicationController
before_action :authenticate_super_admin!
def edit_otp
end
def enable_otp
current_super_admin.enable_otp!
@qrcode = generate_qr_code
sign_out :super_admin
end
protected
def authenticate_super_admin!
if !super_admin_signed_in?
redirect_to root_path
end
end
private
def generate_qr_code
issuer = 'DSManager'
label = "#{issuer}:#{current_super_admin.email}"
RQRCode::QRCode.new(current_super_admin.otp_provisioning_uri(label, issuer: issuer))
end
end

View file

@ -1,6 +1,6 @@
# == Schema Information
#
# Table name: administrations
# Table name: super_admins
#
# id :integer not null, primary key
# consumed_timestep :integer
@ -24,12 +24,12 @@
# created_at :datetime
# updated_at :datetime
#
class Administration < ApplicationRecord
class SuperAdmin < ApplicationRecord
devise :rememberable, :trackable, :validatable, :lockable, :async, :recoverable,
:two_factor_authenticatable, :otp_secret_encryption_key => Rails.application.secrets.otp_secret_key
def enable_otp!
self.otp_secret = Administration.generate_otp_secret
self.otp_secret = SuperAdmin.generate_otp_secret
self.otp_required_for_login = true
save!
end

View file

@ -9,7 +9,7 @@ class OperationAuthorSerializer < ActiveModel::Serializer
"Instructeur##{object.id}"
when Administrateur
"Administrateur##{object.id}"
when Administration
when SuperAdmin
"Manager##{object.id}"
else
nil

View file

@ -6,7 +6,7 @@
%li
.menu-item{ title: current_email }
= current_email
- if administration_signed_in?
- if super_admin_signed_in?
%li
= link_to manager_root_path, class: "menu-item menu-link" do
= image_tag "icons/super-admin.svg", alt: ''

View file

@ -8,7 +8,7 @@ as defined by the routes in the `admin/` namespace
%>
<nav class="navigation" role="navigation">
<%= link_to "Se déconnecter", destroy_administration_session_path, method: :delete, class: "navigation__link" %>
<%= link_to "Se déconnecter", destroy_super_admin_session_path, method: :delete, class: "navigation__link" %>
<hr />

View file

@ -88,7 +88,7 @@
.chart.cumulative-dossiers-chart.hidden
= area_chart @dossiers_cumulative
- if administration_signed_in?
- if super_admin_signed_in?
.stat-card.stat-card-half.pull-left
%span.stat-card-title Temps de traitement moyen d'un dossier
@ -107,7 +107,7 @@
.clearfix
- if administration_signed_in?
- if super_admin_signed_in?
%h2.new-h2 Téléchargement
= link_to "Télécharger les statistiques (CSV)", stats_download_path(format: :csv), class: 'button secondary'

View file

@ -75,13 +75,13 @@ Rails.application.routes.draw do
# Authentication
#
devise_for :administrations, skip: [:registrations], controllers: {
sessions: 'administrations/sessions',
passwords: 'administrations/passwords'
devise_for :super_admins, skip: [:registrations], controllers: {
sessions: 'super_admins/sessions',
passwords: 'super_admins/passwords'
}
get 'administrations/edit_otp', to: 'administrations#edit_otp', as: 'edit_administration_otp'
put 'administrations/enable_otp', to: 'administrations#enable_otp', as: 'enable_administration_otp'
get 'super_admins/edit_otp', to: 'super_admins#edit_otp', as: 'edit_super_admin_otp'
put 'super_admins/enable_otp', to: 'super_admins#enable_otp', as: 'enable_super_admin_otp'
devise_for :users, controllers: {
sessions: 'users/sessions',

View file

@ -0,0 +1,5 @@
class RenameAdministrationsToSuperAdmins < ActiveRecord::Migration[6.0]
def change
rename_table :administrations, :super_admins
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_11_03_165913) do
ActiveRecord::Schema.define(version: 2020_11_05_131443) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -74,32 +74,6 @@ ActiveRecord::Schema.define(version: 2020_11_03_165913) do
t.index ["procedure_id"], name: "index_administrateurs_procedures_on_procedure_id"
end
create_table "administrations", id: :serial, 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.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "failed_attempts", default: 0, null: false
t.string "unlock_token"
t.datetime "locked_at"
t.string "encrypted_otp_secret"
t.string "encrypted_otp_secret_iv"
t.string "encrypted_otp_secret_salt"
t.integer "consumed_timestep"
t.boolean "otp_required_for_login"
t.index ["email"], name: "index_administrations_on_email", unique: true
t.index ["reset_password_token"], name: "index_administrations_on_reset_password_token", unique: true
t.index ["unlock_token"], name: "index_administrations_on_unlock_token", unique: true
end
create_table "assign_tos", id: :serial, force: :cascade do |t|
t.integer "instructeur_id"
t.integer "procedure_id"
@ -606,6 +580,32 @@ ActiveRecord::Schema.define(version: 2020_11_03_165913) do
t.datetime "updated_at", precision: 6, null: false
end
create_table "super_admins", id: :serial, 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.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "failed_attempts", default: 0, null: false
t.string "unlock_token"
t.datetime "locked_at"
t.string "encrypted_otp_secret"
t.string "encrypted_otp_secret_iv"
t.string "encrypted_otp_secret_salt"
t.integer "consumed_timestep"
t.boolean "otp_required_for_login"
t.index ["email"], name: "index_super_admins_on_email", unique: true
t.index ["reset_password_token"], name: "index_super_admins_on_reset_password_token", unique: true
t.index ["unlock_token"], name: "index_super_admins_on_unlock_token", unique: true
end
create_table "task_records", id: false, force: :cascade do |t|
t.string "version", null: false
end

View file

@ -15,7 +15,7 @@ describe ApplicationController, type: :controller do
let(:current_user) { nil }
let(:current_instructeur) { nil }
let(:current_administrateur) { nil }
let(:current_administration) { nil }
let(:current_super_admin) { nil }
let(:payload) { {} }
before do
@ -23,7 +23,7 @@ describe ApplicationController, type: :controller do
allow(@controller).to receive(:current_user).and_return(current_user)
expect(@controller).to receive(:current_instructeur).and_return(current_instructeur)
expect(@controller).to receive(:current_administrateur).and_return(current_administrateur)
expect(@controller).to receive(:current_administration).and_return(current_administration)
expect(@controller).to receive(:current_super_admin).and_return(current_super_admin)
allow(Raven).to receive(:user_context)
@controller.send(:set_raven_context)
@ -72,11 +72,11 @@ describe ApplicationController, type: :controller do
end
end
context 'when someone is logged as a user, instructeur, administrateur and administration' do
context 'when someone is logged as a user, instructeur, administrateur and super_admin' do
let(:current_user) { create(:user) }
let(:current_instructeur) { create(:instructeur) }
let(:current_administrateur) { create(:administrateur) }
let(:current_administration) { create(:administration) }
let(:current_super_admin) { create(:super_admin) }
it do
expect(Raven).to have_received(:user_context)
@ -93,7 +93,7 @@ describe ApplicationController, type: :controller do
user_agent: 'Rails Testing',
user_id: current_user.id,
user_email: current_user.email,
user_roles: 'User, Instructeur, Administrateur, Administration'
user_roles: 'User, Instructeur, Administrateur, SuperAdmin'
})
end
end
@ -109,7 +109,7 @@ describe ApplicationController, type: :controller do
@request.path_info = path_info
end
context 'when no administration is logged in' do
context 'when no super_admin is logged in' do
before { @controller.send(:reject) }
it { expect(@controller).to have_received(:sign_out).with(:user) }
@ -119,7 +119,7 @@ describe ApplicationController, type: :controller do
it { expect(@controller).to have_received(:redirect_to).with(root_path) }
context 'when the path is safe' do
['/', '/manager', '/administrations'].each do |path|
['/', '/manager', '/super_admins'].each do |path|
let(:path_info) { path }
it { expect(@controller).not_to have_received(:sign_out) }
@ -138,11 +138,11 @@ describe ApplicationController, type: :controller do
end
end
context 'when a administration is logged in' do
let(:current_administration) { create(:administration) }
context 'when a super_admin is logged in' do
let(:current_super_admin) { create(:super_admin) }
before do
sign_in(current_administration)
sign_in(current_super_admin)
@controller.send(:reject)
end

View file

@ -1,22 +1,22 @@
describe Manager::AdministrateursController, type: :controller do
let(:administration) { create(:administration) }
let(:super_admin) { create(:super_admin) }
let(:administrateur) { create(:administrateur) }
before do
sign_in administration
sign_in super_admin
end
describe '#show' do
let(:subject) { get :show, params: { id: administrateur.id } }
context 'with 2FA not enabled' do
let(:administration) { create(:administration, otp_required_for_login: false) }
it { expect(subject).to redirect_to(edit_administration_otp_path) }
let(:super_admin) { create(:super_admin, otp_required_for_login: false) }
it { expect(subject).to redirect_to(edit_super_admin_otp_path) }
end
context 'with 2FA enabled' do
render_views
let(:administration) { create(:administration, otp_required_for_login: true) }
let(:super_admin) { create(:super_admin, otp_required_for_login: true) }
before do
subject

View file

@ -1,6 +1,6 @@
describe Manager::ApplicationController, type: :controller do
describe 'append_info_to_payload' do
let(:current_user) { create(:administration) }
let(:current_user) { create(:super_admin) }
let(:payload) { {} }
before do

View file

@ -1,9 +1,9 @@
describe Manager::DemandesController, type: :controller do
let(:administration) { create(:administration) }
let(:super_admin) { create(:super_admin) }
describe 'GET #index' do
before do
sign_in administration
sign_in super_admin
end
it "display pending demandes" do

View file

@ -1,9 +1,9 @@
describe Manager::DossiersController, type: :controller do
let(:administration) { create :administration }
let(:super_admin) { create :super_admin }
let(:deleted_dossier) { DeletedDossier.find_by(dossier_id: dossier) }
let(:operations) { dossier.dossier_operation_logs.map(&:operation).map(&:to_sym) }
before { sign_in administration }
before { sign_in super_admin }
describe '#discard' do
let(:dossier) { create(:dossier, :en_construction) }
@ -23,7 +23,7 @@ describe Manager::DossiersController, type: :controller do
let(:dossier) { create(:dossier, :en_construction) }
before do
dossier.discard_and_keep_track!(administration, :manager_request)
dossier.discard_and_keep_track!(super_admin, :manager_request)
post :restore, params: { id: dossier.id }
dossier.reload

View file

@ -1,12 +1,12 @@
describe Manager::InstructeursController, type: :controller do
let(:administration) { create(:administration) }
let(:super_admin) { create(:super_admin) }
let(:instructeur) { create(:instructeur) }
describe '#show' do
render_views
before do
sign_in(administration)
sign_in(super_admin)
get :show, params: { id: instructeur.id }
end
@ -14,7 +14,7 @@ describe Manager::InstructeursController, type: :controller do
end
describe '#delete' do
before { sign_in administration }
before { sign_in super_admin }
subject { delete :delete, params: { id: instructeur.id } }

View file

@ -1,7 +1,7 @@
describe Manager::ProceduresController, type: :controller do
let(:administration) { create :administration }
let(:super_admin) { create :super_admin }
before { sign_in administration }
before { sign_in super_admin }
describe '#whitelist' do
let(:procedure) { create(:procedure) }
@ -52,7 +52,7 @@ describe Manager::ProceduresController, type: :controller do
let(:operations) { dossier.dossier_operation_logs.map(&:operation).map(&:to_sym) }
before do
procedure.discard_and_keep_track!(administration)
procedure.discard_and_keep_track!(super_admin)
post :restore, params: { id: procedure.id }
procedure.reload

View file

@ -1,14 +1,14 @@
describe Manager::UsersController, type: :controller do
let(:administration) { create(:administration) }
let(:super_admin) { create(:super_admin) }
describe '#show' do
render_views
let(:administration) { create(:administration) }
let(:super_admin) { create(:super_admin) }
let(:user) { create(:user) }
before do
sign_in(administration)
sign_in(super_admin)
get :show, params: { id: user.id }
end
@ -19,7 +19,7 @@ describe Manager::UsersController, type: :controller do
let!(:user) { create(:user, email: 'ancien.email@domaine.fr') }
before {
sign_in administration
sign_in super_admin
}
subject { patch :update, params: { id: user.id, user: { email: nouvel_email } } }
@ -48,7 +48,7 @@ describe Manager::UsersController, type: :controller do
describe '#delete' do
let!(:user) { create(:user) }
before { sign_in administration }
before { sign_in super_admin }
subject { delete :delete, params: { id: user.id } }

View file

@ -32,7 +32,7 @@ describe RootController, type: :controller do
context 'when Administration is connected' do
before do
sign_in create(:administration)
sign_in create(:super_admin)
end
it { expect(subject).to redirect_to(manager_root_path) }

View file

@ -9,7 +9,7 @@ describe StatsController, type: :controller do
create(:procedure, created_at: 2.months.ago, updated_at: Time.zone.now)
@controller = StatsController.new
allow(@controller).to receive(:administration_signed_in?).and_return(false)
allow(@controller).to receive(:super_admin_signed_in?).and_return(false)
end
let(:association) { Procedure.all }
@ -33,7 +33,7 @@ describe StatsController, type: :controller do
@controller = StatsController.new
allow(@controller).to receive(:administration_signed_in?).and_return(true)
allow(@controller).to receive(:super_admin_signed_in?).and_return(true)
end
let (:association) { Procedure.all }
@ -64,7 +64,7 @@ describe StatsController, type: :controller do
let (:association) { Procedure.all }
context "while a super admin is logged in" do
before { allow(@controller).to receive(:administration_signed_in?).and_return(true) }
before { allow(@controller).to receive(:super_admin_signed_in?).and_return(true) }
subject { @controller.send(:cumulative_hash, association, :updated_at) }
@ -78,7 +78,7 @@ describe StatsController, type: :controller do
end
context "while a super admin is not logged in" do
before { allow(@controller).to receive(:administration_signed_in?).and_return(false) }
before { allow(@controller).to receive(:super_admin_signed_in?).and_return(false) }
subject { @controller.send(:cumulative_hash, association, :updated_at) }

View file

@ -1,8 +0,0 @@
FactoryBot.define do
sequence(:administration_email) { |n| "plop#{n}@plop.com" }
factory :administration do
email { generate(:administration_email) }
password { 'my-s3cure-p4ssword' }
otp_required_for_login { true }
end
end

View file

@ -0,0 +1,8 @@
FactoryBot.define do
sequence(:super_admin_email) { |n| "plop#{n}@plop.com" }
factory :super_admin do
email { generate(:super_admin_email) }
password { 'my-s3cure-p4ssword' }
otp_required_for_login { true }
end
end

View file

@ -1,11 +1,11 @@
feature 'As an administrateur', js: true do
let(:administration) { create(:administration) }
let(:super_admin) { create(:super_admin) }
let(:admin_email) { 'new_admin@gouv.fr' }
let(:new_admin) { Administrateur.by_email(admin_email) }
before do
perform_enqueued_jobs do
administration.invite_admin(admin_email)
super_admin.invite_admin(admin_email)
end
end

View file

@ -1247,7 +1247,7 @@ describe Dossier do
end
describe 'discarded_brouillon_expired and discarded_en_construction_expired' do
let(:administration) { create(:administration) }
let(:super_admin) { create(:super_admin) }
before do
create(:dossier)
@ -1259,8 +1259,8 @@ describe Dossier do
create(:dossier).discard!
create(:dossier, :en_construction).discard!
create(:dossier).procedure.discard_and_keep_track!(administration)
create(:dossier, :en_construction).procedure.discard_and_keep_track!(administration)
create(:dossier).procedure.discard_and_keep_track!(super_admin)
create(:dossier, :en_construction).procedure.discard_and_keep_track!(super_admin)
end
Timecop.travel(1.week.ago) do
create(:dossier).discard!

View file

@ -845,7 +845,7 @@ describe Procedure do
end
describe "#discard_and_keep_track!" do
let(:administration) { create(:administration) }
let(:super_admin) { create(:super_admin) }
let(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, procedure: procedure) }
let!(:dossier2) { create(:dossier, procedure: procedure) }
@ -857,7 +857,7 @@ describe Procedure do
context "when discarding procedure" do
before do
instructeur.followed_dossiers << dossier
procedure.discard_and_keep_track!(administration)
procedure.discard_and_keep_track!(super_admin)
instructeur.reload
end

View file

@ -1,9 +1,9 @@
describe Administration, type: :model do
describe SuperAdmin, type: :model do
describe '#invite_admin' do
let(:administration) { create :administration }
let(:super_admin) { create :super_admin }
let(:valid_email) { 'paul@tps.fr' }
subject { administration.invite_admin(valid_email) }
subject { super_admin.invite_admin(valid_email) }
it {
user = subject
@ -11,8 +11,8 @@ describe Administration, type: :model do
expect(user).to be_persisted
}
it { expect(administration.invite_admin(nil).errors).not_to be_empty }
it { expect(administration.invite_admin('toto').errors).not_to be_empty }
it { expect(super_admin.invite_admin(nil).errors).not_to be_empty }
it { expect(super_admin.invite_admin('toto').errors).not_to be_empty }
it 'creates a corresponding user account for the email' do
subject
@ -36,29 +36,29 @@ describe Administration, type: :model do
end
describe 'enable_otp!' do
let(:administration) { create(:administration, otp_required_for_login: false) }
let(:subject) { administration.enable_otp! }
let(:super_admin) { create(:super_admin, otp_required_for_login: false) }
let(:subject) { super_admin.enable_otp! }
it 'updates otp_required_for_login' do
expect { subject }.to change { administration.otp_required_for_login? }.from(false).to(true)
expect { subject }.to change { super_admin.otp_required_for_login? }.from(false).to(true)
end
it 'updates otp_secret' do
expect { subject }.to change { administration.otp_secret }
expect { subject }.to change { super_admin.otp_secret }
end
end
describe 'disable_otp!' do
let(:administration) { create(:administration, otp_required_for_login: true) }
let(:subject) { administration.disable_otp! }
let(:super_admin) { create(:super_admin, otp_required_for_login: true) }
let(:subject) { super_admin.disable_otp! }
it 'updates otp_required_for_login' do
expect { subject }.to change { administration.otp_required_for_login? }.from(true).to(false)
expect { subject }.to change { super_admin.otp_required_for_login? }.from(true).to(false)
end
it 'nullifies otp_secret' do
administration.enable_otp!
expect { subject }.to change { administration.reload.otp_secret }.to(nil)
super_admin.enable_otp!
expect { subject }.to change { super_admin.reload.otp_secret }.to(nil)
end
end
end

View file

@ -164,7 +164,7 @@ describe User, type: :model do
end
describe 'invite_administrateur!' do
let(:administration) { create(:administration) }
let(:super_admin) { create(:super_admin) }
let(:administrateur) { create(:administrateur) }
let(:user) { administrateur.user }
@ -172,12 +172,12 @@ describe User, type: :model do
before { allow(AdministrationMailer).to receive(:invite_admin).and_return(mailer_double) }
subject { user.invite_administrateur!(administration.id) }
subject { user.invite_administrateur!(super_admin.id) }
context 'when the user is inactif' do
before { subject }
it { expect(AdministrationMailer).to have_received(:invite_admin).with(user, kind_of(String), administration.id) }
it { expect(AdministrationMailer).to have_received(:invite_admin).with(user, kind_of(String), super_admin.id) }
end
context 'when the user is actif' do
@ -187,7 +187,7 @@ describe User, type: :model do
end
it 'receives an invitation to update its password' do
expect(AdministrationMailer).to have_received(:invite_admin).with(user, kind_of(String), administration.id)
expect(AdministrationMailer).to have_received(:invite_admin).with(user, kind_of(String), super_admin.id)
end
end
end
@ -245,13 +245,13 @@ describe User, type: :model do
end
describe '#delete_and_keep_track_dossiers' do
let(:administration) { create(:administration) }
let(:super_admin) { create(:super_admin) }
let(:user) { create(:user) }
context 'with a dossier in instruction' do
let!(:dossier_en_instruction) { create(:dossier, :en_instruction, user: user) }
it 'raises' do
expect { user.delete_and_keep_track_dossiers(administration) }.to raise_error(RuntimeError)
expect { user.delete_and_keep_track_dossiers(super_admin) }.to raise_error(RuntimeError)
end
end
@ -261,7 +261,7 @@ describe User, type: :model do
context 'without a discarded dossier' do
it "keep track of dossiers and delete user" do
user.delete_and_keep_track_dossiers(administration)
user.delete_and_keep_track_dossiers(super_admin)
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_present
expect(DeletedDossier.find_by(dossier_id: dossier_brouillon)).to be_nil
@ -278,8 +278,8 @@ describe User, type: :model do
end
it "keep track of dossiers and delete user" do
dossier_cache.discard_and_keep_track!(administration, :user_request)
user.delete_and_keep_track_dossiers(administration)
dossier_cache.discard_and_keep_track!(super_admin, :user_request)
user.delete_and_keep_track_dossiers(super_admin)
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_present
expect(DeletedDossier.find_by(dossier_id: dossier_brouillon)).to be_nil
@ -287,8 +287,8 @@ describe User, type: :model do
end
it "doesn't destroy dossiers of another user" do
dossier_cache.discard_and_keep_track!(administration, :user_request)
user.delete_and_keep_track_dossiers(administration)
dossier_cache.discard_and_keep_track!(super_admin, :user_request)
user.delete_and_keep_track_dossiers(super_admin)
expect(Dossier.find_by(id: dossier_from_another_user.id)).to be_present
end