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

#2823: update delete domain process - [MS] #3185

Merged
merged 35 commits into from
Dec 16, 2024

Conversation

Matt-Spence
Copy link
Contributor

@Matt-Spence Matt-Spence commented Dec 3, 2024

Ticket

Resolves #2823

Changes

  • Adds new functionality to the "_delete_domain" function that removes subdomains and non-registrant contacts.
  • Small change to Registry errors to provide a way to bubble up domain names so they can be displayed to users.
  • New/updated tests

Context for reviewers

Currently domains can't be deleted by the "Delete from the Registry" button in admin unless all hosts and contacts for that domain are deleted first. This PR adds logic to automagically delete contacts and hosts, unless a contact is shared with another domain.

Setup

Poor-police.gov has been created on ms as an example of a domain that has a subdomain used by another domain (you can find this in hosts). You can use that to check that deletion fails in this case, or roll your own if you prefer.

Other than that any domain that has subdomains (usually as nameservers) can be used to test that deletion works properly. After deleting you should be able to click "check status in registry" and see a "pendingDelete" status.

Code Review Verification Steps

Go to MS -> Admin -> Pick a domain that has nameservers and/or contacts -> Put On Hold -> Delete From Registry. Try this for a few permutations including have a domain that shares a host with another domain (this should fail).

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
  • Update documentation in READMEs and/or onboarding guide

Ensured code standards are met (Original Developer)

  • If any updated dependencies on Pipfile, also update dependencies 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)

  • Tag @dotgov-designers in this PR's Reviewers for design review. If code is not user-facing, delete design reviewer checklist
  • Verify 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)

As a code reviewer, I have

Reviewed, tested, and left feedback about the changes

  • Pulled this branch locally and tested it
  • Verified code meets all checks above. Address any checks that are not satisfied
  • Reviewed this code and left comments. Indicate if comments must be addressed before code is merged
  • Checked that all code is adequately covered by tests
  • Verify migrations are valid and do not conflict with existing migrationsX

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.

  • 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)
  • (Rarely needed) Tested as both an analyst and applicant user

As a designer reviewer, I have

Verified that the changes match the design intention

  • Checked that the design translated visually
  • Checked behavior. Comment any found issues or broken flows.
  • Checked different states (empty, one, some, error)
  • Checked for landmarks, page heading structure, and links

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

References

Screenshots

@Matt-Spence Matt-Spence requested a review from allly-b as a code owner December 3, 2024 21:23
Copy link

github-actions bot commented Dec 3, 2024

🥳 Successfully deployed to developer sandbox ms.

Copy link

github-actions bot commented Dec 4, 2024

🥳 Successfully deployed to developer sandbox ms.

Copy link

github-actions bot commented Dec 4, 2024

🥳 Successfully deployed to developer sandbox ms.

Copy link

github-actions bot commented Dec 4, 2024

🥳 Successfully deployed to developer sandbox ms.

Copy link

github-actions bot commented Dec 4, 2024

🥳 Successfully deployed to developer sandbox ms.

1 similar comment
Copy link

github-actions bot commented Dec 4, 2024

🥳 Successfully deployed to developer sandbox ms.

Copy link

github-actions bot commented Dec 4, 2024

🥳 Successfully deployed to developer sandbox ms.

Copy link

github-actions bot commented Dec 5, 2024

🥳 Successfully deployed to developer sandbox ms.

Copy link

github-actions bot commented Dec 5, 2024

🥳 Successfully deployed to developer sandbox ms.

Copy link

github-actions bot commented Dec 5, 2024

🥳 Successfully deployed to developer sandbox ms.

Copy link

github-actions bot commented Dec 5, 2024

🥳 Successfully deployed to developer sandbox ms.

Copy link

github-actions bot commented Dec 9, 2024

🥳 Successfully deployed to developer sandbox ms.

Copy link

github-actions bot commented Dec 9, 2024

🥳 Successfully deployed to developer sandbox ms.

@Matt-Spence Matt-Spence changed the title [DRAFT] #2823: update delete domain process - [MS] #2823: update delete domain process - [MS] Dec 12, 2024
@zandercymatics zandercymatics self-assigned this Dec 13, 2024
Copy link
Contributor

@zandercymatics zandercymatics left a comment

Choose a reason for hiding this comment

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

Code looks good. Only real blocker is the raise error on _delete_hosts_if_not_used which may have some knock-on effects on nameserver. Might not be a problem in practice though

Will test this within a day or so (no need to monitor your sandbox though) as I am nibbling this. Posting this review so you have this earlier rather than later

message = error_messages.get(err.code, err)
message = error_messages[err.code]
Copy link
Contributor

Choose a reason for hiding this comment

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

(Q) Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is an artifact of some testing I did that involved messing with the error messages. I thought I rewrote everything the way it should have been but it appears I missed this. Will revert this change.


logger.info("Deleting subdomains for %s", self.name)
# check if any subdomains are in use by another domain
hosts = Host.objects.filter(name__regex=r".+{}".format(self.name))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice check on subdomain

Comment on lines 1044 to 1051
for host in hosts:
if host.domain != self:
logger.error("Unable to delete host: %s is in use by another domain: %s", host.name, host.domain)
raise RegistryError(
code=ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION,
note=f"Host {host.name} is in use by {host.domain}",
)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think EPP will throw an error in this case so it should be OK, but there is a potential scenario here where a nameserver exists on EPP but not on our hosts table (sandboxes for example).

I think the way you handled this is totally fine though. Just curious to hear your perspective and thoughts on that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point that I had considered, but in general there's not a great way to handle it. I haven't found a method in EPP that lets us list object based on their relationships, so we have to rely on our database foreign key relationships being an accurate-enough reflection. That said, it would be a relatively simple task to add more error handling if need be.

Copy link
Contributor

@zandercymatics zandercymatics Dec 13, 2024

Choose a reason for hiding this comment

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

Did some digging. There is a function in our epplib library called ListDomainsByNsset and ListDomainsByContact as well as a few others.

The process involved in using these though would go way outside the scope of the ticket. The commands may work on their own by default but you'd need to extend what we currently have here. And if they don't work on their own, you'd need to modify the repo which Dave and I did before. For it being a rare edgecase we can just send out these commands manually if we run into this scenario

if responseCode != ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY:
raise NameserverError(code=nsErrorCodes.BAD_DATA)

self._delete_hosts_if_not_used(hostsToDelete=deleted_values)
Copy link
Contributor

Choose a reason for hiding this comment

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

(Nitpick / optional) A comment explaining as to why delete hosts is called after 1062 would be a nice to have but not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea

@@ -1026,10 +1033,49 @@ def _remove_client_hold(self):
# if registry error occurs, log the error, and raise it as well
logger.error(f"registry error removing client hold: {err}")
raise (err)

def _delete_domain(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice work on this function. I also like how you doing error handling / raising, very clean

Comment on lines +1816 to 1818
raise e

def _fix_unknown_state(self, cleaned):
Copy link
Contributor

Choose a reason for hiding this comment

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

(potentially blocking) This will have some knock-on effects for the nameservers setter as it seems to assume that no error is raised by this helper function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I'll add a try/catch to the nameservers setter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice

def mockDeleteHostCommands(self, _request, cleaned):
host = getattr(_request, "name", None)
if "sharedhost.com" in host:
print("raising registry error")
Copy link
Contributor

Choose a reason for hiding this comment

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

Remember to remove before merging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another good catch, I thought I caught all of these!

@@ -1748,6 +1765,7 @@ def mockInfoDomainCommands(self, _request, cleaned):
"subdomainwoip.gov": (self.mockDataInfoDomainSubdomainNoIP, None),
"ddomain3.gov": (self.InfoDomainWithContacts, None),
"igorville.gov": (self.InfoDomainWithContacts, None),
"sharingiscaring.gov": (self.infoDomainSharedHost, None),
Copy link
Contributor

@zandercymatics zandercymatics Dec 13, 2024

Choose a reason for hiding this comment

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

😄

cleaned=True,
),
],
any_order=True,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ordering of these matters in some cases, but the database doesn't always return things in the same order so for things like the contacts it can break the test. I'll break that part out though, because in general you have the right idea and I had meant to do so anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah gotcha. Yeah that'd be totally fine then

Comment on lines 885 to 890
"[email protected],True,[email protected],2022-04-01,2024-02-01,Viewer Requester,Manager,False,0,\n"
"[email protected],False,[email protected],2022-04-01,Invalid date,None,"
'Manager,True,2,"adomain2.gov,cdomain1.gov"\n'
"[email protected],False,[email protected],Unretrieved,Invited,None,Manager,False,0,\n"
"[email protected],False,[email protected],Unretrieved,Invited,None,Viewer,False,0,\n"
"[email protected],False,[email protected],Unretrieved,Invited,Viewer,None,False,0,\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this fix is on latest now so you don't need to add it manually

Copy link
Contributor

@zandercymatics zandercymatics left a comment

Choose a reason for hiding this comment

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

looks great

Comment on lines 755 to 758
except:
# the error will be logged in the erring function and we don't
# need this part to succeed in order to continue.s
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

Would suggest logging the error + some minor grammar things in the comment, but other than that looks good

Copy link

🥳 Successfully deployed to developer sandbox ms.

Copy link
Contributor

@zandercymatics zandercymatics left a comment

Choose a reason for hiding this comment

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

LGTM. Was able to reproduce the subdomain error, though its actually a non-issue, imo.

When adding nameserver records, I am getting the Error deleting this Domain: This subdomain is being used as a hostname on another domain: error that you mentioned.

This error would only occur when nameservers were added. So if I deleted the domain in dns needed or if I deleted those nameserver records when it was in "ready", this error would disappear. This actually makes total sense - the underlying error is OBJECT_ASSOCIATION_PROHIBITS_OPERATION. This tells me that the messaging was faulty rather than your code

In unrelated news, on your sandbox I seem to be getting a 500 on team-loss-within.gov for a missing contact. This is "on hold". If you set this record to on hold manually from deleted then that would make sense, though otherwise that is strange
image

@zandercymatics
Copy link
Contributor

That said, I am curious as to what @dave-kennedy-ecs thinks

@zandercymatics
Copy link
Contributor

@Matt-Spence Also forgot to mention, but your linter is failing

Copy link

🥳 Successfully deployed to developer sandbox ms.

Copy link

🥳 Successfully deployed to developer sandbox ms.

Copy link

🥳 Successfully deployed to developer sandbox ms.

@Matt-Spence Matt-Spence merged commit c02b036 into main Dec 16, 2024
9 of 10 checks passed
@Matt-Spence Matt-Spence deleted the ms/2823-update-delete-domain-process branch December 16, 2024 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update delete domain process to remove hosts and/or contacts
3 participants