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: deprecate xxx_token columns from users table (phase iii) #1614

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

kangmingtay
Copy link
Member

@kangmingtay kangmingtay commented Jun 7, 2024

What kind of change does this PR introduce?

  • This PR removes the the reliance on using the xxx_token columns in the user model to store information about the token and use the one_time_tokens table as the single source of truth

  • CreateOneTimeToken now returns the models.OneTimeToken struct

  • Decouple sending the email change emails from the sendEmail function into sendEmailChangeEmails

  • This PR does not address changing the xxx_sent_at columns to use the one_time_tokens table yet

  • Do not merge until phase ii has been deployed for some time

@kangmingtay kangmingtay requested a review from a team as a code owner June 7, 2024 08:57
Comment on lines -603 to -607
case mail.EmailChangeVerification:
return mailer.EmailChangeMail(r, u, otpNew, otp, referrerURL, externalURL)
Copy link
Member Author

Choose a reason for hiding this comment

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

moved this into it's own function (see sendEmailChangeEmails because we're passing way too many arguments into the function just to satisfy this case

if we were to combine them, the sendEmail function would need to take in:

  • r *http.Request
  • tx *storage.Connection
  • u *models.User
  • emailActionType
  • otp, otpNew string
  • ott, ottNew *models.OneTimeToken

where otpNew and ottNew are only needed in the email change case.

further refactoring can be done in a subsequent PR to use the ott.TokenType rather than passing in an emailActionType

Comment on lines 581 to 588
if config.Mailer.SecureEmailChangeEnabled && u.GetEmail() != "" {
go func(c chan error) {
c <- mailer.EmailChangeMail(r, u, ottCurrent, otp, referrerURL, externalURL)
}(errors)
}
go func(c chan error) {
c <- mailer.EmailChangeMail(r, u, ottNew, otpNew, referrerURL, externalURL)
}(errors)
Copy link
Member Author

@kangmingtay kangmingtay Jun 7, 2024

Choose a reason for hiding this comment

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

previously, EmailChangeMail handled multiplexing between the current and new email - i find it alot cleaner for it just to do 1 thing (send the email for email change) and have a separate function that wraps it to decide whether to send 2 emails or just 1 based on whether secure email change is enabled

@coveralls
Copy link

coveralls commented Jun 7, 2024

Pull Request Test Coverage Report for Build 9414598574

Details

  • 171 of 236 (72.46%) changed or added relevant lines in 7 files are covered.
  • 21 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.2%) to 57.362%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/models/one_time_token.go 3 5 60.0%
internal/mailer/template.go 54 57 94.74%
internal/api/reauthenticate.go 1 7 14.29%
internal/api/verify.go 23 32 71.88%
internal/api/mail.go 80 125 64.0%
Files with Coverage Reduction New Missed Lines %
internal/mailer/template.go 1 88.94%
internal/api/verify.go 2 71.7%
internal/api/mail.go 18 57.35%
Totals Coverage Status
Change from base Build 9404687053: -0.2%
Covered Lines: 8438
Relevant Lines: 14710

💛 - Coveralls

Copy link
Contributor

@hf hf left a comment

Choose a reason for hiding this comment

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

Generally code-wise looks good. I'd reconsider the channel / parallelism introduced for sending emails, but fine either way (so long as we wait for the 2 goroutines to finish).

internal/api/mail.go Outdated Show resolved Hide resolved
internal/api/user_test.go Show resolved Hide resolved
internal/models/user.go Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Jun 10, 2024

Pull Request Test Coverage Report for Build 9445054800

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 168 of 234 (71.79%) changed or added relevant lines in 7 files are covered.
  • 96 unchanged lines in 8 files lost coverage.
  • Overall coverage decreased (-0.2%) to 57.377%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/models/one_time_token.go 3 5 60.0%
internal/mailer/template.go 54 57 94.74%
internal/api/reauthenticate.go 1 7 14.29%
internal/api/verify.go 23 32 71.88%
internal/api/mail.go 77 123 62.6%
Files with Coverage Reduction New Missed Lines %
internal/mailer/template.go 1 88.94%
internal/api/verify.go 2 71.7%
internal/models/cleanup.go 8 88.37%
internal/observability/request-tracing.go 9 81.98%
internal/crypto/password.go 14 78.29%
internal/api/middleware.go 16 80.81%
internal/api/mail.go 18 56.97%
internal/observability/metrics.go 28 4.96%
Totals Coverage Status
Change from base Build 9404687053: -0.2%
Covered Lines: 8435
Relevant Lines: 14701

💛 - Coveralls

internal/api/verify.go Outdated Show resolved Hide resolved
Copy link
Contributor

@J0 J0 left a comment

Choose a reason for hiding this comment

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

Thanks!

@coveralls
Copy link

coveralls commented Jun 10, 2024

Pull Request Test Coverage Report for Build 9450374191

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 169 of 238 (71.01%) changed or added relevant lines in 7 files are covered.
  • 98 unchanged lines in 8 files lost coverage.
  • Overall coverage decreased (-0.2%) to 57.355%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/models/one_time_token.go 3 5 60.0%
internal/mailer/template.go 54 57 94.74%
internal/api/reauthenticate.go 1 7 14.29%
internal/api/verify.go 24 36 66.67%
internal/api/mail.go 77 123 62.6%
Files with Coverage Reduction New Missed Lines %
internal/mailer/template.go 1 88.94%
internal/api/verify.go 4 71.03%
internal/models/cleanup.go 8 88.37%
internal/observability/request-tracing.go 9 81.98%
internal/crypto/password.go 14 78.29%
internal/api/middleware.go 16 80.81%
internal/api/mail.go 18 56.97%
internal/observability/metrics.go 28 4.96%
Totals Coverage Status
Change from base Build 9404687053: -0.2%
Covered Lines: 8434
Relevant Lines: 14705

💛 - Coveralls

@coveralls
Copy link

Pull Request Test Coverage Report for Build 10034317134

Details

  • 171 of 240 (71.25%) changed or added relevant lines in 7 files are covered.
  • 23 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.2%) to 57.77%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/models/one_time_token.go 3 5 60.0%
internal/mailer/template.go 54 57 94.74%
internal/api/reauthenticate.go 1 7 14.29%
internal/api/verify.go 24 36 66.67%
internal/api/mail.go 79 125 63.2%
Files with Coverage Reduction New Missed Lines %
internal/mailer/template.go 1 88.94%
internal/api/verify.go 4 72.06%
internal/api/mail.go 18 56.97%
Totals Coverage Status
Change from base Build 10015664673: -0.2%
Covered Lines: 8744
Relevant Lines: 15136

💛 - Coveralls

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.

4 participants