Skip to content
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

Issue #2579 #2644: Analyst can merge user accounts - [BOB] #2649

Merged
merged 17 commits into from
Sep 6, 2024

Conversation

rachidatecs
Copy link
Contributor

@rachidatecs rachidatecs commented Aug 24, 2024

Ticket

Resolves #2579
Resolves #2644

Changes

  • New view/template for a transfer user page
  • Sidebar, breadcrumbs (<- @Katherine-Osos instead of a back to link), comparison panes, select and submit
  • The select is a combo box implemented outside of the DJA context which means spot-loading the required JS and CSS
  • Modal on submit
  • Transfer of user properties (portfolio and roles/perms)
  • Transfer of joined fields (DomainInfo, DomainRequest, UserDomainRole, VerifiedBy, Portfolio) defined as constants in the view class
  • Solid testing

Context for reviewers

This turned to be a bit large, so we shed a couple of items to other tickets:

Setup

  • Try transferring users who own doman requests, domains, are creators on portfolios, have entries in the verified by (edge case, I don't think we'll be merging analysts), have a portfolio and roles and perms on it.

Designers

As of Friday night the sandbox build is not running. Check for green checkmarks before you go to bob.

Code Review Verification Steps

As the original developer, I have

Satisfied acceptance criteria and met development standards

  • Met the acceptance criteria, or will meet them in a subsequent PR
  • Created/modified automated tests
  • Added at least 2 developers as PR reviewers (only 1 will need to approve)
  • Messaged on Slack or in standup to notify the team that a PR is ready for review
  • Changes to “how we do things” are documented in READMEs and or onboarding guide
  • If any model was updated to modify/add/delete columns, makemigrations was ran and the associated migrations file has been commited.

Ensured code standards are met (Original Developer)

  • All new functions and methods are commented using plain language
  • Did dependency updates in Pipfile also get changed in requirements.txt?
  • Interactions with external systems are wrapped in try/except
  • Error handling exists for unusual or missing values

Validated user-facing changes (if applicable)

  • New pages have been added to .pa11yci file so that they will be tested with our automated accessibility testing
  • Checked keyboard navigability
  • Tested general usability, landmarks, page header structure, and links with a screen reader (such as Voiceover or ANDI)
  • Add at least 1 designer as PR reviewer

As a code reviewer, I have

Reviewed, tested, and left feedback about the changes

  • Pulled this branch locally and tested it
  • Reviewed this code and left comments
  • Checked that all code is adequately covered by tests
  • Made it clear which comments need to be addressed before this work is merged
  • If any model was updated to modify/add/delete columns, makemigrations was ran and the associated migrations file has been commited.

Ensured code standards are met (Code reviewer)

  • All new functions and methods are commented using plain language
  • Interactions with external systems are wrapped in try/except
  • Error handling exists for unusual or missing values
  • (Rarely needed) Did dependency updates in Pipfile also get changed in requirements.txt?

Validated user-facing changes as a developer

  • New pages have been added to .pa11yci file so that they will be tested with our automated accessibility testing

  • Checked keyboard navigability

  • Meets all designs and user flows provided by design/product

  • Tested general usability, landmarks, page header structure, and links with a screen reader (such as Voiceover or ANDI)

  • Tested with multiple browsers, the suggestion is to use ones that the developer didn't (check off which ones were used)

    • Chrome
    • Microsoft Edge
    • FireFox
    • Safari
  • (Rarely needed) Tested as both an analyst and applicant user

Note: Multiple code reviewers can share the checklists above, a second reviewers should not make a duplicate checklist

As a designer reviewer, I have

Verified that the changes match the design intention

  • Checked that the design translated visually
  • Checked behavior
  • Checked different states (empty, one, some, error)
  • Checked for landmarks, page heading structure, and links
  • Tried to break the intended flow

Validated user-facing changes as a designer

  • Checked keyboard navigability

  • Tested general usability, landmarks, page header structure, and links with a screen reader (such as Voiceover or ANDI)

  • Tested with multiple browsers (check off which ones were used)

    • Chrome
    • Microsoft Edge
    • FireFox
    • Safari
  • (Rarely needed) Tested as both an analyst and applicant user

Screenshots

Copy link

🥳 Successfully deployed to developer sandbox bob.

console.error("Could not assign current user: no values found.")
return;
}
if (document.getElementById("id_investigator") && django && django.jQuery) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relax, this is just an additional check for document.getElementById("id_investigator") && django && django.jQuery) to get rid of a console error. Nothing else in this file.

Copy link

🥳 Successfully deployed to developer sandbox bob.

Copy link

🥳 Successfully deployed to developer sandbox bob.

Copy link

🥳 Successfully deployed to developer sandbox bob.

Copy link

🥳 Successfully deployed to developer sandbox bob.

@Katherine-Osos Katherine-Osos removed the request for review from a team August 27, 2024 21:39
Copy link

🥳 Successfully deployed to developer sandbox bob.

Copy link

🥳 Successfully deployed to developer sandbox bob.

Copy link

🥳 Successfully deployed to developer sandbox bob.

@Katherine-Osos
Copy link
Contributor

@rachidatecs Looks good, just two small updates:

  • Can we use a different (muted) button style for the "Select and preview" button? Visually, it competes with the "Transfer ..." button, which is a much more important button. For example, could we use the gray button style that's used for the search fields in the admin?
  • In the confirmation modal: I reviewed some of the other modals we're using in the "Domains" section, and want to make a few tweaks to this one for consistency.
    • Let's update the heading to be a question: "Are you sure you want to transfer data and delete this user?"
    • Move the name & email to the body of the message and add the username (since I believe you/Kaitlin noted that's an important unique identifier).
    • Update the button label to be a response to the question: "Yes, transfer and delete user"
    • See layout below.

Are you sure you want to transfer data and delete this user?
Username: 987654321
Name: John Smith
Email: jsmith@ example.com

This action cannot be undone.

[Yes, transfer and delete user] [Cancel]

Copy link

🥳 Successfully deployed to developer sandbox bob.

@rachidatecs rachidatecs changed the title Issue #2579: Analyst can merge user accounts - [BOB] Issue #2579 #2644: Analyst can merge user accounts - [BOB] Aug 30, 2024
Copy link

🥳 Successfully deployed to developer sandbox bob.

Copy link

🥳 Successfully deployed to developer sandbox bob.

@Matt-Spence Matt-Spence self-assigned this Sep 5, 2024
Copy link
Contributor

@Matt-Spence Matt-Spence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works perfectly well for me. I have a concern with adding a hole in our csp for select2, but I don't think it's an unacceptable risk. Let me know if there's no acceptably convenient way around using it.

CSP_STYLE_SRC = [
"'self'",
"https://www.ssa.gov/accessibility/andi/andi.css",
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume there was no other easy way to do this? Adding another hole in our CSP is not something we should do lightly. If somehow that version alias of select2 were to get replaced with something malicious anybody who accesses a view that loads scripts from this source could be vulnerable.

If it's going to be super expensive to replace this then it may be worth it, but I want to make sure it's something we're considering carefully.

<script src="{% static 'admin/js/vendor/jquery/jquery.min.js' %}"></script>

<!-- Include Select2 JavaScript. Since this view technically falls outside of admin, this is needed. -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I was referencing earlier. If hypothetically the developers of select2 got hacked (or were deliberately malicious) they could upload arbitrary code at this url and it would execute in the users browser. This is a risk we take with basically all our dependencies, so it's not unacceptable, but again want to make sure it's carefully considered.

Copy link
Contributor Author

@rachidatecs rachidatecs Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

select2 makes the django admin combobox possible on the transfer page. It's django source code basically. Without it, the transfer page would have to be registered as a django admin view (which it is not), or we'd need to use USWDS's combobox in this view's context. There might be a way to load this piece of Django's source code from our existing build but I couldn't figure it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One option: We download the select2 script and load it from our static folder. Is it worth it though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ Legit question, you or Alysia would be the ones best qualified to answer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm cool with this as-is. Just wanted to make sure there wasn't an easy workaround.

</h2>
<div class="usa-prose">
{% if selected_user != logged_in_user %}
<p>Username: <b>{{ selected_user.username }}</b><br>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an instance where the selected_user would be equal to the logged_in_user? Could we make a better 'else' message if so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be refactored in a future ticket that disallows this feature for any staff (analyst, superuser) user

def test_transfer_user_modal(self):
"""Assert modal on page"""
user_transfer_page = self.app.get(reverse("transfer_user", args=[self.user1.pk]))
self.assertContains(user_transfer_page, "This action cannot be undone.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the use of tests here for different scenarios!

current_user.save()

@classmethod
def log_change(cls, obj, field_name, field_value, new_value, change_logs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really clean way of logging changes!

Copy link
Contributor

@Matt-Spence Matt-Spence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good

Copy link

github-actions bot commented Sep 6, 2024

🥳 Successfully deployed to developer sandbox bob.

Copy link

github-actions bot commented Sep 6, 2024

🥳 Successfully deployed to developer sandbox bob.

@rachidatecs rachidatecs merged commit 59b647b into main Sep 6, 2024
10 checks passed
@rachidatecs rachidatecs deleted the bob/2579-analyst-merge-user-accounts branch September 6, 2024 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants