From ce6cedd25364da7f6f35f50cf37af9e134d5a041 Mon Sep 17 00:00:00 2001 From: pabois <pierreandre.boissinot@noesya.coop> Date: Mon, 16 Oct 2023 15:27:18 +0200 Subject: [PATCH] destroy server admin from every universities --- app/models/user/with_sync_between_universities.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/models/user/with_sync_between_universities.rb b/app/models/user/with_sync_between_universities.rb index da5871829..660f9f4e6 100644 --- a/app/models/user/with_sync_between_universities.rb +++ b/app/models/user/with_sync_between_universities.rb @@ -5,6 +5,7 @@ module User::WithSyncBetweenUniversities attr_accessor :skip_server_admin_sync after_save :sync_between_universities, if: Proc.new { |user| user.server_admin? && !user.skip_server_admin_sync } + after_destroy :remove_from_all_universities, if: Proc.new { |user| user.server_admin? } def self.synchronize_server_admin_users(source_university, target_university) source_university.users.server_admin.each do |user| @@ -48,4 +49,9 @@ module User::WithSyncBetweenUniversities user.update_column(:encrypted_password, self.encrypted_password) if user.valid? end + def remove_from_all_universities + # As a "server_admin" is synced between universities, any removal destroys the accounts of the concerned user in every university + User.where(email: email, role: :server_admin).destroy_all + end + end -- GitLab