Skip to content

Commit d9eef41

Browse files
authored
Address identity review feedback
1 parent 1840b7f commit d9eef41

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

app/models/user.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,10 @@ def merge(*others)
348348
other_profiles = others.map(&:profile)
349349
others.each do |other|
350350
other.identities.each do |identity|
351-
existing_identity = identities.find_by(provider: identity.provider, uid: identity.uid)
352-
if existing_identity
351+
existing_identity = if identity.uid.present?
352+
identities.find_by(provider: identity.provider, uid: identity.uid)
353+
end
354+
if existing_identity.present?
353355
identity.destroy
354356
else
355357
identity.update!(user: self)

app/views/identities/index.html.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
<td><%= identity.uid.presence || content_tag(:span, 'Not set', class: 'empty') %></td>
2121
<td>
2222
<%= link_to 'Remove', user_identity_path(@user, identity),
23-
method: :delete,
24-
data: { confirm: 'Are you sure you want to remove this identity?' },
23+
data: { turbo_method: :delete, turbo_confirm: 'Are you sure you want to remove this identity?' },
2524
class: 'btn btn-danger btn-sm' %>
2625
</td>
2726
</tr>

db/migrate/20260723102000_create_identities.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ def change
2020
ON CONFLICT (provider, uid) DO NOTHING
2121
SQL
2222
end
23+
24+
dir.down do
25+
execute <<~SQL
26+
UPDATE users
27+
SET provider = source.provider,
28+
uid = source.uid
29+
FROM (
30+
SELECT DISTINCT ON (user_id) user_id, provider, uid
31+
FROM identities
32+
ORDER BY user_id, created_at ASC, id ASC
33+
) AS source
34+
WHERE users.id = source.user_id
35+
AND (users.provider IS NULL OR users.provider = '')
36+
SQL
37+
end
2338
end
2439
end
2540
end

0 commit comments

Comments
 (0)