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

feat(fxa-admin-panel): add email bounce diagnosticCode to FXA Admin Panel #12551

Merged
merged 1 commit into from
Apr 26, 2022

Conversation

millmason
Copy link
Contributor

@millmason millmason commented Apr 18, 2022

Because

  • We want to have the diagnostic code from an email bounce available in the fxa admin panel. Currently, it only shows up in the logs.

This pull request

  • Adds a diagnosticCode column to the emailBounces panel
  • Adds a diagnosticCode key onto the appropriate models/gql queries
  • Sets diagnosticCode as a nullable, optional value (to safely allow for querying past records which will not have this value.)
  • Adds an optional --hasDiagnosticCode flag to the script for generating fake email bounces (fxa/packages/fxa-admin-server/scripts/email-bounce.ts). This allowed me to create email bounce records missing the new field, to make sure they would display properly on the frontend.
  • Displays the diagnostic code for an email bounce record within the fxa admin panel, if present on the record.
  • Updates the README that describes generating test email bounces

Issue that this pull request solves

Closes: #12137

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).

Screenshots (Optional)

Please attach the screenshots of the changes made in case of change in user interface.

Before:
Has the same data as the "after" image (i.e., a mix of email bounce records, some with diagnostic codes and some without) but does not display any of them.
before

After:
Here we can see diagnostic codes when they're present on the record.
after

Other information (Optional)

Do you think we should explicitly say when there is no diagnostic code present on the record? For example, it might be clearer if, instead of hiding the field when the diagnostic code is absent, we put something like diagnostic code: none present on record or something like that.

I'd also especially appreciate eyes on the database and gql code.

There are some code scanning checks that are failing (for lines I didn't alter) but it looks like the alert is for "Cryptographically insecure randomness in a security context" and it seems to be pointing at randomness used in tests (as opposed to something security-related in production) so I think we can dismiss that alert.

Finally, I'd like opinions on whether there should be specific test coverage of this. It didn't look to me like we were testing other individual fields on the emailBounce queries, but I'm open to other opinions.

@millmason millmason changed the title 4700 add diagnosticcode Add email bounce diagnosticCode to FXA Admin Panel Apr 18, 2022
@millmason millmason marked this pull request as ready for review April 18, 2022 22:36
@millmason millmason requested a review from a team as a code owner April 18, 2022 22:36
@millmason millmason changed the title Add email bounce diagnosticCode to FXA Admin Panel feat(fxa-admin-panel): add email bounce diagnosticCode to FXA Admin Panel Apr 19, 2022
@dschom dschom self-requested a review April 21, 2022 17:44
@dschom
Copy link
Contributor

dschom commented Apr 21, 2022

@millsoper Concerning the diagnostic code, I'd favor explicitly stating it. Since this is an admin panel, I think a more verbose UX is better. Concerning the security warnings, since these are not lines you altered, so it shouldn't be a concern of this PR. Concerning further test coverage, if I see spots were we could improve coverage, I'll call this out in the code as I review it, thanks for bring this to attention though.

@millmason
Copy link
Contributor Author

@dschom what would you think of using the ResultListItem component here to clean up the list of Email Bounce fields? It's pretty much a perfect fit, except for the fact that it expects a test id, which in the current format would go in as undefined. It's really not necessary but seemed like a nice little clean-up, since I'm adjusting that list anyway

Copy link
Contributor

@dschom dschom left a comment

Choose a reason for hiding this comment

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

Nice work! For the time being, I am going ahead and posting some nitpicks. I still need to run some tests and do a bit of exploratory testing, but I think this PR is basically ready to go. I will do another pass after lunch.

bounce = randomEmailBounce(argv.email as string);
bounce = randomEmailBounce(
argv.email as string,
argv.withDiagnosticCode as boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

Should withDiagnosticCode be added to yargs.options on line 17?

@@ -36,6 +36,7 @@ type EmailBounce {
bounceType: BounceType!
bounceSubType: BounceSubType!
createdAt: Float!
diagnosticCode: String!
Copy link
Contributor

Choose a reason for hiding this comment

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

In the graphql.ts diagnosticCode is nullable. :String! indicates the field is not nullable whereas a type of :String would be nullable. Perhaps this should be consistent between the typescript and the graphql schema?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It definitely should, thanks!

}: Pick<EmailBounce, 'email'> & {
templateName: string;
bounceType: BounceType;
bounceSubType: BounceSubType;
diagnosticCode?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Random nit, you could also define diagnosticCode in the Pick, which is a more type centric way of declaring this, e.g. Pick<EmailBounce, 'email' | 'diagnosticCode'>. Note that the set of unioned types here are either not present on EmailBounce, or they are being represented with a more specific type, whereas diagnosticCode's type is already aligned with EmailBounce.diagnosticCode.

@@ -4,5 +4,6 @@ CREATE TABLE `emailBounces` (
`bounceType` tinyint(3) unsigned NOT NULL,
`bounceSubType` tinyint(3) unsigned NOT NULL,
`createdAt` bigint(20) unsigned NOT NULL,
`diagnosticCode` varchar(255) NOT NULL,
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking on state again. This collumn is explictily being declared NOT NULL, yet in graphql.ts the field is marked as Nullable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhh that's an error, I'll fix that. Thank you!!

export function randomEmailBounce(email: string): BounceIsh {
export function randomEmailBounce(
email: string,
withDiagnosticCode: boolean = false
Copy link
Contributor

Choose a reason for hiding this comment

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

So I feel a bit conflicted suggesting this, since IMO randomness in tests is bad. However, this is already the approach being used, so I would suggest leaving the daignosticCode up to chance as well. As far as I can tell, nothing ever sets withDiagnosticCode to true, so this path isn't actually being invoked or tested at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh I see what you mean -- I set it as the default here because it's being used in the fxa-admin-server script that we use for manually faking bounces, so I was thinking of it more as a dev tool than a test helper, and setting the default to false allowed it to keep being used the way it had been. It is confusing though. Would it be clearer if I added randomization to the tests? Or should I drop this altogether?

@millmason millmason force-pushed the 4700-add-diagnosticcode branch from 9063344 to 523c87c Compare April 25, 2022 22:27
@millmason millmason closed this Apr 25, 2022
@millmason millmason reopened this Apr 25, 2022
…e obj

feat(fxa-admin-panel): add diagnosticCode to auth bounce model

feat(fxa-admin-panel): add diagnosticCode col to emailBounces table

feat(fxa-admin-panel): fix patch to include procedures and use them

feat(fxa-admin-panel): update helpers/email bounce faker to include diagnostic code

feat(fxa-admin-panel): add diagnostic code to admin panel display

feat(fxa-admin-panel): make diagnosticCode field optional

chore(fxa-admin-server) update README with new script flag

feat(fxa-admin-panel) explicitly show lack of diagnostic code if none present

fix(fxa-admin-panel) fix types for diagnostic code

fix(fxa-admin-server) gql type fixes

fix(fxa-admin-server) gql

fix(fxa-admin-panel) set diagnosticCode default value to empty string
@millmason millmason force-pushed the 4700-add-diagnosticcode branch from 523c87c to 24e4b40 Compare April 26, 2022 17:09
CALL assertPatchLevel('126');

ALTER TABLE emailBounces
ADD COLUMN diagnosticCode VARCHAR(255) DEFAULT '',
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@dschom dschom self-requested a review April 26, 2022 19:41
Copy link
Contributor

@dschom dschom left a comment

Choose a reason for hiding this comment

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

LGTM!

@millmason millmason merged commit 3a1c36f into main Apr 26, 2022
@millmason millmason deleted the 4700-add-diagnosticcode branch May 4, 2022 18:58
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.

Add diagnosticcode to admin panel bounce display
2 participants