Skip to content

Commit

Permalink
On peut refuser tous les comptes, du moment qu'il reste un admin non-…
Browse files Browse the repository at this point in the history
  • Loading branch information
etienneCharignon committed Oct 14, 2024
1 parent 5cced7b commit b277a53
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 38 deletions.
11 changes: 3 additions & 8 deletions app/models/compte.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class Compte < ApplicationRecord
validates :statut_validation, presence: true
validates :nom, :prenom, presence: { on: :create }
validate :verifie_dns_email, :structure_a_un_admin
validates :role, inclusion: { in: %w[conseiller compte_generique], message: :comptes_refuses },
if: :compte_refuse?
validates :email, uniqueness: { case_sensitive: false }
validates_with PasswordValidator, fields: [:password]

Expand All @@ -45,11 +43,8 @@ def nom_complet
end

def find_admins
Compte.where(structure: structure, role: ADMIN_ROLES).where.not(structure: nil)
end

def compte_refuse?
validation_refusee?
Compte.where(structure: structure, role: ADMIN_ROLES, statut_validation: :acceptee)
.where.not(structure: nil)
end

def anlci?
Expand Down Expand Up @@ -98,7 +93,7 @@ def verifie_dns_email

def structure_a_un_admin
return if structure.nil?
return if au_moins_admin?
return if au_moins_admin? && !validation_refusee?
return if autres_admins?

errors.add(:role, :structure_doit_avoir_un_admin)
Expand Down
2 changes: 0 additions & 2 deletions config/locales/models/compte.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ fr:
role:
structure_doit_avoir_un_admin: 'La structure doit avoir au moins un administrateur'
inclusion: n'est pas inclus dans la liste
comptes_refuses: |
ce compte ne peut pas avoir le rôle %<value>s en étant refusé. Uniquement conseiller ou compte générique
formtastic:
actions:
compte:
Expand Down
28 changes: 0 additions & 28 deletions spec/features/admin/compte_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,6 @@
it { expect(collegue.reload.validation_refusee?).to be true }
end

describe 'Refuser un admin' do
before do
visit edit_admin_compte_path(collegue)
select 'Admin'
choose 'Refusé'
click_on 'Modifier'
end

it 'ne permet pas de refuser un admin' do
expect(page).to have_content('ce compte ne peut pas avoir le rôle admin en étant ' \
'refusé. Uniquement conseiller ou compte générique')
end
end

describe 'Je vois les informations d\'un collègue' do
it do
visit admin_compte_path(collegue)
Expand Down Expand Up @@ -170,20 +156,6 @@
it { expect(collegue.reload.validation_refusee?).to be true }
end

describe 'Refuser un admin' do
before do
visit edit_admin_compte_path(collegue)
select 'Admin'
choose 'Refusé'
click_on 'Modifier'
end

it 'ne permet pas de refuser un admin' do
expect(page).to have_content('ce compte ne peut pas avoir le rôle admin en étant ' \
'refusé. Uniquement conseiller ou compte générique')
end
end

describe "modifier le mot de passe d'un collègue" do
before do
visit edit_admin_compte_path(collegue)
Expand Down
1 change: 1 addition & 0 deletions spec/integrations/compte_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
let!(:compte_admin_sans_structure) { create :compte_admin, structure: nil }
let!(:compte_admin) { create :compte_admin, structure: structure }
let!(:compte_admin2) { create :compte_admin, structure: structure }
let!(:compte_admin_refuse) { create :compte_admin, :refusee, structure: structure }
let!(:compte_superadmin) { create :compte_superadmin, structure: structure }
let(:autre_structure) { create :structure }
let!(:autre_admin) { create :compte_admin, structure: autre_structure }
Expand Down
6 changes: 6 additions & 0 deletions spec/models/compte_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@
compte.valid?
expect(compte.errors[:role]).to include 'La structure doit avoir au moins un administrateur'
end

it 'ne peut pas refuser cet admin' do
compte.statut_validation = 'refusee'
compte.valid?
expect(compte.errors[:role]).to include 'La structure doit avoir au moins un administrateur'
end
end

context "quand il n'y a pas d'admin dans la structure" do
Expand Down

0 comments on commit b277a53

Please sign in to comment.