Skip to content

Commit 27e1f6b

Browse files
committed
Patch migration
1 parent 38a4444 commit 27e1f6b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

db/migrate/20250929094333_convert_user_groups_into_users.decidim.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,23 @@ class UserGroup < ApplicationRecord
2020
self.inheritance_column = nil
2121
end
2222

23+
# Identify if there is another user with the same email in the same organization
24+
# @param [User] group
25+
# @return [Boolean]
26+
def another_user_with_same_email_in_organization?(group)
27+
User.where.not(id: group.id).exists?(decidim_organization_id: group.decidim_organization_id, email: group.email)
28+
end
29+
2330
# rubocop:disable Rails/SkipsModelValidations
2431
def up
2532
User.old_group.find_each do |group|
33+
if group.email.blank? || another_user_with_same_email_in_organization?(group)
34+
group.update_attribute(:email, "user_group_#{group.id}@#{group.organization.host}.invalid")
35+
group.update_attribute(:extended_data, (group.extended_data || {}).merge("patched" => true, "previous_email" => group.email))
36+
37+
group.reload
38+
end
39+
2640
group.update_attribute(:extended_data, (group.extended_data || {}).merge("group" => true))
2741
group.update_attribute(:type, "Decidim::User")
2842
group.update_attribute(:officialized_at, group.verified_at) if group.verified_at.present?

0 commit comments

Comments
 (0)