SFDO-Tooling / Metecho

Web-based tool for collaborating on Salesforce projects
BSD 3-Clause "New" or "Revised" License
44 stars 35 forks source link

Do not delete scratch orgs on task reassignment #2121

Closed davidmreed closed 1 year ago

davidmreed commented 1 year ago

This PR ensures that when a user reassigns a task that already has a scratch org, one of two things happens:

Metecho no longer deletes scratch orgs during transfers.

In order for a person to be a valid transfer target, all of these things must be true.

There are three areas in the code where org transfer is implicated. Note that these areas also implicate assignment, not just reassignment. This means that each area of code involved in the process has a lot of different states to check before it takes action.

The previous code did not work correctly (orgs were always deleted!), repeated itself in numerous places, was very difficult to follow, and was not tested effectively for the org transfer case.

In this PR, the API checks are factored into a new module, metecho.api.reassignment, using full typing and breaking down checks into reusable elements. The code in can_reassign and the TaskAssigneeSerializer is simplified. The existing tests for TaskAssigneeSerializer and the can_reassign() API call are completely rewritten, and cover the new module effectively. The front end now detects issues via can_reassign() and presents them to the user in a toast message, rather than deleting an existing scratch org.

The one remaining case in which an org is deleted is if a transfer is attempted but fails.

To test hands-on:

  1. Open local in Dev Container

  2. Run yarn serve

  3. Access the CCI-Food-Bank project

  4. Create a task and scratch org

  5. Open a terminal and run python manage.py shell.

  6. Create a secondary user that can receive a scratch org transfer:

    from metecho.api.models import * gh = GitHubUser.objects.get(login='davidjray') # Assuming you are not David Ray u = User.objects.create(username = 'Test Recipient', email='d.reed@salesforce.com') SocialAccount.objects.create(user=u, provider='github', uid=gh.pk)

  7. Transfer the task to the created user. You should see the scratch org transfer to them as well.

  8. Attempt to transfer the task to a different user, who does not have an account. You should see a Toast error message with details of the issue.

davidmreed commented 1 year ago

W-13140495

kdvenkata commented 1 year ago

Reviewed