Repository navigation
Flag people with multiple user accounts and link to merging them #2661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f1fb67b
Flag people who have more than one login on their profile and edit pages
maebeale ff6ca29
Flag people with more than one user account and link to each
maebeale 796b4a8
Let admins merge a person's extra logins straight from the warning
maebeale 7b6a215
Keep the hidden ?admin internal notes off the features page
maebeale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <% decorated = person.decorate %> | ||
| <% user_accounts = decorated.user_accounts %> | ||
| <% if user_accounts.size > 1 %> | ||
| <% keeper = decorated.suggested_user_account %> | ||
| <div class="admin-only mb-4 rounded-lg border border-yellow-200 bg-yellow-50 p-4"> | ||
| <div class="flex items-start gap-3"> | ||
| <div class="flex-shrink-0 pt-0.5"> | ||
| <i class="fa-solid fa-triangle-exclamation text-yellow-600"></i> | ||
| </div> | ||
| <div class="flex-1"> | ||
| <h3 class="text-sm font-medium text-yellow-800">Multiple user accounts</h3> | ||
| <p class="mt-1 text-sm text-yellow-700"> | ||
| This person has <%= user_accounts.size %> user accounts. A person should have only one β the extras are usually a leftover from a merge. | ||
| </p> | ||
| <ul class="mt-2 space-y-1 text-sm text-yellow-700"> | ||
| <% user_accounts.each_with_index do |user, index| %> | ||
| <li> | ||
| <%= link_to user.email, user_path(user), class: "underline hover:text-yellow-900", data: { turbo_frame: "_top" } %> | ||
| <span class="text-yellow-600">Β· last signed in <%= user.decorate.last_logged_in %><%= " Β· shown on profile" if index.zero? %></span> | ||
| <% if user == keeper %> | ||
| <span class="ml-1 rounded-full border border-emerald-200 bg-emerald-50 px-2 py-0.5 text-xs font-medium text-emerald-700">Suggested keeper</span> | ||
| <% else %> | ||
| <%= link_to "Preview merge β", | ||
| dedupe_preview_users_path(user_to_delete_id: user.id, user_to_keep_id: keeper.id, return_to: return_to, person_id: person.id), | ||
| class: "ml-1 font-medium underline hover:text-yellow-900", | ||
| data: { turbo: false } %> | ||
| <% end %> | ||
| </li> | ||
| <% end %> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
spec/requests/people_multiple_user_accounts_warning_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| require "rails_helper" | ||
|
|
||
| RSpec.describe "People multiple-user-accounts warning", type: :request do | ||
| let(:admin) { create(:user, :admin) } | ||
|
|
||
| before { sign_in admin } | ||
|
|
||
| it "flags a person with more than one user account on show and edit, linking to each" do | ||
| person = create(:person) | ||
| first_login = person.user | ||
| second_login = create(:user, person: person) | ||
|
|
||
| get person_path(person) | ||
| expect(response).to have_http_status(:ok) | ||
| expect(response.body).to include("Multiple user accounts") | ||
| expect(response.body).to include(user_path(first_login), user_path(second_login)) | ||
|
|
||
| get edit_person_path(person) | ||
| expect(response).to have_http_status(:ok) | ||
| expect(response.body).to include("Multiple user accounts") | ||
| expect(response.body).to include(user_path(first_login), user_path(second_login)) | ||
| end | ||
|
|
||
| it "does not flag a person with a single user account" do | ||
| person = create(:person) | ||
|
|
||
| get person_path(person) | ||
| expect(response.body).not_to include("Multiple user accounts") | ||
|
|
||
| get edit_person_path(person) | ||
| expect(response.body).not_to include("Multiple user accounts") | ||
| end | ||
|
|
||
| it "links each extra account to a merge preview into the suggested keeper, returning to the page it came from" do | ||
| person = create(:person) | ||
| stale = person.user.tap { |user| user.update_columns(confirmed_at: nil, updated_at: 1.minute.from_now) } | ||
| keeper = create(:user, person: person) | ||
|
|
||
| get edit_person_path(person) | ||
|
|
||
| expect(response.body).to include("Suggested keeper") | ||
| expect(response.body).to include(CGI.escapeHTML(dedupe_preview_users_path(user_to_delete_id: stale.id, user_to_keep_id: keeper.id, return_to: "person_edit", person_id: person.id))) | ||
| end | ||
|
|
||
| describe "returning from the logins merge" do | ||
| let(:person) { create(:person) } | ||
| let!(:keeper) { person.user } | ||
| let!(:extra) { create(:user, person: person) } | ||
|
|
||
| it "points the preview's back link at the person page it came from" do | ||
| get dedupe_preview_users_path(user_to_delete_id: extra.id, user_to_keep_id: keeper.id, return_to: "person_show", person_id: person.id) | ||
|
|
||
| expect(response).to have_http_status(:ok) | ||
| expect(response.body).to include("Back to profile") | ||
| expect(response.body).to include(%(href="#{person_path(person)}")) | ||
| end | ||
|
|
||
| it "lands back on the person page after merging" do | ||
| post dedupe_perform_users_path, params: { user_to_delete_id: extra.id, user_to_keep_id: keeper.id, return_to: "person_edit", person_id: person.id } | ||
|
|
||
| expect(response).to redirect_to(edit_person_path(person)) | ||
| expect(User.exists?(extra.id)).to be(false) | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π€ From Claude: This is in the shared Dedupable concern, so every deduper honors
return_to. Only the person warning sends it, though, and it only targets the logins merge, where the person survives. A people merge withreturn_towould land on the deleted person.