#4769: Add standard users to fixtures - [ab]#4972
Conversation
| def _set_foreign_key_fields(cls, request: DomainRequest, request_dict: dict, user: User): | ||
| """Helper method used by `load`.""" | ||
| if not user.is_staff: | ||
| user = random.choice(User.objects.filter(is_staff=True)) # nosec |
There was a problem hiding this comment.
I'm having trouble following this. Why was this done?
There was a problem hiding this comment.
Good question! The "user" variable is used to set investigator on the next line. But, investigator has to a staff member as only staff members should be approving/investigating the validity of a request. Now that these new users are meant to be purely non staff users for UAT, the code hits an error if any of them are assigned as investigators. Hence, I'm checking if the user is not a staff member, then pick a random staff member as the investigator just so it doesn't error when it gets to approving the domain request.
There was a problem hiding this comment.
Just one other question:
Would the team ever run ./manage.py load multiple times? Just wondering if we need an idempotency check here to prevent multiple domain requests and domain approvals (although I think we block those already).
Otherwise, I think this is pretty bullet-proof. Great work, Alysia.
@abe-alam-ecs If the load command is run multiple times you do get multiple domains & requests which was intentional originally for when people wanted to test code with a lot of domains (such as filtering and pagination which is better when you have a decent amount domains & requests). However, it will not create duplicate users, luckily that logic was already in place like you thought. I don't think we need to worry about idempotency for this one just given if this is used for UAT testing and someone triggers it twice it's likely intentional and if not, it will just require deleting some of the requests & domains manually if for some reason it's too many. |


Ticket
Resolves #4769
Changes
STANDARD_USERSlist (feedback+1@get.govthroughfeedback+8@get.gov) tosrc/registrar/fixtures/fixtures_users.pysrc/registrar/fixtures/fixtures_standard_user_domains.py— a newStandardUserDomainFixtureclass that creates domain requests in everyDomainRequestStatusand domains in everyDomain.Statefor each standard userload_standard_user_permissions()tosrc/registrar/fixtures/fixtures_user_portfolio_permissions.py— assigns each standard user anORGANIZATION_MEMBERportfolio role withEDIT_REQUESTSandVIEW_MEMBERSpermissionssrc/registrar/management/commands/load.pyto callStandardUserDomainFixture.load()docs/developer/README.mdwith a new "Adding Standard Users" sectionContext for reviewers
Domain states are forced so no EPP commands are sent. However, there is a desire to have fixtures send epp commands for only these domains in the future. As of now these domains will show as "unknown" in EPP and may throw errors if any code attempts to interact with the registry for them. However, given the desire to add in epp down the road for these I opted to isolate this code into a separate file to not mix it's logic in with the existing fixture items.
Setup
On a sandbox (not advised approach but worth mentioning)
Standard users load automatically when
./manage.py loadruns as part ofreset-db.yml. This will reset everything in the database though.On a sandbox (less annoying approach)
For running this locally (easiest):
load.pyand comment out if not settings.IS_LOCAL:and replace it withif True:`docker compose down && docker compose up(I'd suggest avoiding using the headless commands so you can see the fixtures output)How to verify the right things were created
For designers
Code Review Verification Steps
As the original developer, I have
Satisfied acceptance criteria and met development standards
Ensured code standards are met (Original Developer)
Validated user-facing changes (if applicable)
As a code reviewer, I have
Reviewed, tested, and left feedback about the changes
Validated user-facing changes as a developer
Note: Multiple code reviewers can share the checklists above, a second reviewer should not make a duplicate checklist. All checks should be checked before approving, even those labeled N/A.
As a designer reviewer, I have
Verified that the changes match the design intention
Validated user-facing changes as a designer
References
Screenshots