Skip to content

Commit

Permalink
Permet à un conseiller de créer un compte pour un de ses collègues
Browse files Browse the repository at this point in the history
Co-authored-by: Marine Dominé <[email protected]>
  • Loading branch information
2 people authored and etienneCharignon committed Mar 3, 2021
1 parent bf938c2 commit d80f7d9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
8 changes: 6 additions & 2 deletions app/admin/comptes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
form do |f|
f.inputs do
f.input :email
f.input :role, as: :select, collection: %w[administrateur organisation]
f.input :structure
if can? :manage, Compte
f.input :role, as: :select, collection: %w[administrateur organisation]
f.input :structure
else
f.input :structure_id, as: :hidden, input_html: { value: current_compte.structure_id }
end
f.input :password
f.input :password_confirmation
end
Expand Down
1 change: 1 addition & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def droit_question
end

def droit_compte(compte)
can :create, Compte
can :read, Compte, structure_id: compte.structure_id
cannot :destroy, Compte do |q|
Campagne.where(compte: q).present?
Expand Down
33 changes: 26 additions & 7 deletions spec/features/admin/compte_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,21 @@

context 'en conseiller' do
let(:ma_structure) { create :structure }
let(:autre_structure) { create :structure }
let(:conseiller_connecte) do
create :compte_organisation, structure: ma_structure, email: 'moi@structure'
end
let!(:collegue) do
create :compte_organisation, structure: ma_structure, email: 'collegue@structure'
end
let!(:inconnu) do
create :compte_organisation, structure: autre_structure, email: 'inconnu@structure'
end

before(:each) { connecte conseiller_connecte }

describe 'je vois mes collègues' do
let(:autre_structure) { create :structure }
let!(:inconnu) do
create :compte_organisation, structure: autre_structure, email: 'inconnu@structure'
end
let!(:collegue) do
create :compte_organisation, structure: ma_structure, email: 'collegue@structure'
end

before { visit admin_comptes_path }

it do
Expand All @@ -58,5 +59,23 @@
expect(page).to_not have_content 'inconnu@structure'
end
end

describe 'ajouter un collegue' do
before { visit new_admin_compte_path }

it do
fill_in :compte_email, with: '[email protected]'
fill_in :compte_password, with: 'billyjoel'
fill_in :compte_password_confirmation, with: 'billyjoel'

expect do
click_on 'Créer un compte'
end.to change(Compte, :count)

compte_cree = Compte.last
expect(compte_cree.structure).to eq ma_structure
expect(compte_cree.role).to eq 'organisation'
end
end
end
end
1 change: 1 addition & 0 deletions spec/integrations/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
it { is_expected.to_not be_able_to(:create, Campagne.new) }
it { is_expected.to_not be_able_to(:read, SourceAide.new) }
it { is_expected.to_not be_able_to(:read, Aide::QuestionFrequente.new) }
it { is_expected.to be_able_to(:create, Compte.new) }
it { is_expected.to be_able_to(:read, Question.new) }
it { is_expected.to be_able_to(%i[read destroy], evaluation_organisation) }
it { is_expected.to be_able_to(:read, evenement_organisation) }
Expand Down

0 comments on commit d80f7d9

Please sign in to comment.