Skip to content

Commit bcb7655

Browse files
committed
chore: use Provider for consistency
1 parent e26d71f commit bcb7655

File tree

7 files changed

+47
-48
lines changed

7 files changed

+47
-48
lines changed

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -743,16 +743,15 @@ Whether to send a notification email when a user's phone number is changed. Defa
743743
`GOTRUE_MAILER_TEMPLATES_IDENTITY_LINKED_NOTIFICATION` - `string`
744744

745745
URL path to an email template to use when notifying a user that a new identity has been linked to their account. (e.g. `https://www.example.com/path-to-email-template.html`)
746-
`Email` and `IdentityProvider` variables are available.
746+
`Email` and `Provider` variables are available.
747747

748748
Default Content (if template is unavailable):
749749

750750
```html
751751
<h2>A new identity has been linked</h2>
752752

753753
<p>
754-
A new identity ({{ .IdentityProvider }}) has been linked to your account {{
755-
.Email }}.
754+
A new identity ({{ .Provider }}) has been linked to your account {{ .Email }}.
756755
</p>
757756
<p>If you did not make this change, please contact support immediately.</p>
758757
```
@@ -764,16 +763,16 @@ Whether to send a notification email when a new identity is linked to a user's a
764763
`GOTRUE_MAILER_TEMPLATES_IDENTITY_UNLINKED_NOTIFICATION` - `string`
765764

766765
URL path to an email template to use when notifying a user that an identity has been unlinked from their account. (e.g. `https://www.example.com/path-to-email-template.html`)
767-
`Email` and `IdentityProvider` variables are available.
766+
`Email` and `Provider` variables are available.
768767

769768
Default Content (if template is unavailable):
770769

771770
```html
772771
<h2>An identity has been unlinked</h2>
773772

774773
<p>
775-
An identity ({{ .IdentityProvider }}) has been unlinked from your account {{
776-
.Email }}.
774+
An identity ({{ .Provider }}) has been unlinked from your account {{ .Email
775+
}}.
777776
</p>
778777
<p>If you did not make this change, please contact support immediately.</p>
779778
```

internal/api/identity.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (a *API) DeleteIdentity(w http.ResponseWriter, r *http.Request) error {
5151
return apierrors.NewUnprocessableEntityError(apierrors.ErrorCodeIdentityNotFound, "Identity doesn't exist")
5252
}
5353

54-
identityProvider := identityToBeDeleted.Provider
54+
provider := identityToBeDeleted.Provider
5555
err = db.Transaction(func(tx *storage.Connection) error {
5656
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.IdentityUnlinkAction, "", map[string]interface{}{
5757
"identity_id": identityToBeDeleted.ID,
@@ -92,7 +92,7 @@ func (a *API) DeleteIdentity(w http.ResponseWriter, r *http.Request) error {
9292

9393
// Send identity unlinked notification email if enabled and user has an email
9494
if config.Mailer.Notifications.IdentityUnlinkedEnabled && user.GetEmail() != "" {
95-
if err := a.sendIdentityUnlinkedNotification(r, db, user, identityProvider); err != nil {
95+
if err := a.sendIdentityUnlinkedNotification(r, db, user, provider); err != nil {
9696
// Log the error but don't fail the unlinking
9797
logrus.WithError(err).Warn("Unable to send identity unlinked notification email")
9898
}

internal/api/identity_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (ts *IdentityTestSuite) TestLinkIdentitySendsNotificationEmailEnabled() {
257257
// Assert that identity linked notification email was sent
258258
require.Len(ts.T(), mockMailer.IdentityLinkedMailCalls, 1, "Expected 1 identity linked notification email(s) to be sent")
259259
require.Equal(ts.T(), u.ID, mockMailer.IdentityLinkedMailCalls[0].User.ID, "Email should be sent to the correct user")
260-
require.Equal(ts.T(), "google", mockMailer.IdentityLinkedMailCalls[0].IdentityProvider, "Provider should match")
260+
require.Equal(ts.T(), "google", mockMailer.IdentityLinkedMailCalls[0].Provider, "Provider should match")
261261
require.Equal(ts.T(), "one@example.com", mockMailer.IdentityLinkedMailCalls[0].User.GetEmail(), "Email should be sent to the correct email address")
262262
}
263263

@@ -313,7 +313,7 @@ func (ts *IdentityTestSuite) TestUnlinkIdentitySendsNotificationEmailEnabled() {
313313
// Assert that identity unlinked notification email was sent
314314
require.Len(ts.T(), mockMailer.IdentityUnlinkedMailCalls, 1, "Expected 1 identity unlinked notification email(s) to be sent")
315315
require.Equal(ts.T(), u.ID, mockMailer.IdentityUnlinkedMailCalls[0].User.ID, "Email should be sent to the correct user")
316-
require.Equal(ts.T(), "phone", mockMailer.IdentityUnlinkedMailCalls[0].IdentityProvider, "Provider should match")
316+
require.Equal(ts.T(), "phone", mockMailer.IdentityUnlinkedMailCalls[0].Provider, "Provider should match")
317317
require.Equal(ts.T(), "two@example.com", mockMailer.IdentityUnlinkedMailCalls[0].User.GetEmail(), "Email should be sent to the correct email address")
318318
}
319319

internal/api/mail.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,10 @@ func (a *API) sendPhoneChangedNotification(r *http.Request, tx *storage.Connecti
634634
return nil
635635
}
636636

637-
func (a *API) sendIdentityLinkedNotification(r *http.Request, tx *storage.Connection, u *models.User, identityProvider string) error {
637+
func (a *API) sendIdentityLinkedNotification(r *http.Request, tx *storage.Connection, u *models.User, provider string) error {
638638
err := a.sendEmail(r, tx, u, sendEmailParams{
639-
emailActionType: mail.IdentityLinkedNotification,
640-
identityProvider: identityProvider,
639+
emailActionType: mail.IdentityLinkedNotification,
640+
provider: provider,
641641
})
642642
if err != nil {
643643
if errors.Is(err, EmailRateLimitExceeded) {
@@ -651,10 +651,10 @@ func (a *API) sendIdentityLinkedNotification(r *http.Request, tx *storage.Connec
651651
return nil
652652
}
653653

654-
func (a *API) sendIdentityUnlinkedNotification(r *http.Request, tx *storage.Connection, u *models.User, identityProvider string) error {
654+
func (a *API) sendIdentityUnlinkedNotification(r *http.Request, tx *storage.Connection, u *models.User, provider string) error {
655655
err := a.sendEmail(r, tx, u, sendEmailParams{
656-
emailActionType: mail.IdentityUnlinkedNotification,
657-
identityProvider: identityProvider,
656+
emailActionType: mail.IdentityUnlinkedNotification,
657+
provider: provider,
658658
})
659659
if err != nil {
660660
if errors.Is(err, EmailRateLimitExceeded) {
@@ -749,7 +749,7 @@ type sendEmailParams struct {
749749
tokenHashWithPrefix string
750750
oldEmail string
751751
oldPhone string
752-
identityProvider string
752+
provider string
753753
factorType string
754754
}
755755

@@ -874,9 +874,9 @@ func (a *API) sendEmail(r *http.Request, tx *storage.Connection, u *models.User,
874874
case mail.PhoneChangedNotification:
875875
err = mr.PhoneChangedNotificationMail(r, u, params.oldPhone)
876876
case mail.IdentityLinkedNotification:
877-
err = mr.IdentityLinkedNotificationMail(r, u, params.identityProvider)
877+
err = mr.IdentityLinkedNotificationMail(r, u, params.provider)
878878
case mail.IdentityUnlinkedNotification:
879-
err = mr.IdentityUnlinkedNotificationMail(r, u, params.identityProvider)
879+
err = mr.IdentityUnlinkedNotificationMail(r, u, params.provider)
880880
case mail.MFAFactorEnrolledNotification:
881881
err = mr.MFAFactorEnrolledNotificationMail(r, u, params.factorType)
882882
case mail.MFAFactorUnenrolledNotification:

internal/mailer/mailer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ type Mailer interface {
4343
PasswordChangedNotificationMail(r *http.Request, user *models.User) error
4444
EmailChangedNotificationMail(r *http.Request, user *models.User, oldEmail string) error
4545
PhoneChangedNotificationMail(r *http.Request, user *models.User, oldPhone string) error
46-
IdentityLinkedNotificationMail(r *http.Request, user *models.User, identityProvider string) error
47-
IdentityUnlinkedNotificationMail(r *http.Request, user *models.User, identityProvider string) error
46+
IdentityLinkedNotificationMail(r *http.Request, user *models.User, provider string) error
47+
IdentityUnlinkedNotificationMail(r *http.Request, user *models.User, provider string) error
4848
MFAFactorEnrolledNotificationMail(r *http.Request, user *models.User, factorType string) error
4949
MFAFactorUnenrolledNotificationMail(r *http.Request, user *models.User, factorType string) error
5050
}

internal/mailer/mockclient/mockclient.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ type PhoneChangedMailCall struct {
9191
}
9292

9393
type IdentityLinkedMailCall struct {
94-
User *models.User
95-
IdentityProvider string
94+
User *models.User
95+
Provider string
9696
}
9797

9898
type IdentityUnlinkedMailCall struct {
99-
User *models.User
100-
IdentityProvider string
99+
User *models.User
100+
Provider string
101101
}
102102

103103
type MFAFactorEnrolledMailCall struct {
@@ -205,18 +205,18 @@ func (m *MockMailer) PhoneChangedNotificationMail(r *http.Request, user *models.
205205
return nil
206206
}
207207

208-
func (m *MockMailer) IdentityLinkedNotificationMail(r *http.Request, user *models.User, identityProvider string) error {
208+
func (m *MockMailer) IdentityLinkedNotificationMail(r *http.Request, user *models.User, provider string) error {
209209
m.IdentityLinkedMailCalls = append(m.IdentityLinkedMailCalls, IdentityLinkedMailCall{
210-
User: user,
211-
IdentityProvider: identityProvider,
210+
User: user,
211+
Provider: provider,
212212
})
213213
return nil
214214
}
215215

216-
func (m *MockMailer) IdentityUnlinkedNotificationMail(r *http.Request, user *models.User, identityProvider string) error {
216+
func (m *MockMailer) IdentityUnlinkedNotificationMail(r *http.Request, user *models.User, provider string) error {
217217
m.IdentityUnlinkedMailCalls = append(m.IdentityUnlinkedMailCalls, IdentityUnlinkedMailCall{
218-
User: user,
219-
IdentityProvider: identityProvider,
218+
User: user,
219+
Provider: provider,
220220
})
221221
return nil
222222
}

internal/mailer/templatemailer/templatemailer.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ const (
2020
ReauthenticationTemplate = "reauthentication"
2121

2222
// Account Changes Notifications
23-
PasswordChangedNotificationTemplate = "password_changed_notification"
24-
EmailChangedNotificationTemplate = "email_changed_notification"
25-
PhoneChangedNotificationTemplate = "phone_changed_notification"
26-
IdentityLinkedNotificationTemplate = "identity_linked_notification"
27-
IdentityUnlinkedNotificationTemplate = "identity_unlinked_notification"
28-
MFAFactorEnrolledNotificationTemplate = "mfa_factor_enrolled_notification"
29-
MFAFactorUnenrolledNotificationTemplate = "mfa_factor_unenrolled_notification"
23+
PasswordChangedNotificationTemplate = "password_changed_notification"
24+
EmailChangedNotificationTemplate = "email_changed_notification"
25+
PhoneChangedNotificationTemplate = "phone_changed_notification"
26+
IdentityLinkedNotificationTemplate = "identity_linked_notification"
27+
IdentityUnlinkedNotificationTemplate = "identity_unlinked_notification"
28+
MFAFactorEnrolledNotificationTemplate = "mfa_factor_enrolled_notification"
29+
MFAFactorUnenrolledNotificationTemplate = "mfa_factor_unenrolled_notification"
3030
)
3131

3232
const defaultInviteMail = `<h2>You have been invited</h2>
@@ -86,13 +86,13 @@ const defaultPhoneChangedNotificationMail = `<h2>Your phone number has been chan
8686

8787
const defaultIdentityLinkedNotificationMail = `<h2>A new identity has been linked</h2>
8888
89-
<p>A new identity ({{ .IdentityProvider }}) has been linked to your account {{ .Email }}.</p>
89+
<p>A new identity ({{ .Provider }}) has been linked to your account {{ .Email }}.</p>
9090
<p>If you did not make this change, please contact support immediately.</p>
9191
`
9292

9393
const defaultIdentityUnlinkedNotificationMail = `<h2>An identity has been unlinked</h2>
9494
95-
<p>An identity ({{ .IdentityProvider }}) has been unlinked from your account {{ .Email }}.</p>
95+
<p>An identity ({{ .Provider }}) has been unlinked from your account {{ .Email }}.</p>
9696
<p>If you did not make this change, please contact support immediately.</p>
9797
`
9898

@@ -450,20 +450,20 @@ func (m *Mailer) PhoneChangedNotificationMail(r *http.Request, user *models.User
450450
return m.mail(r.Context(), m.cfg, PhoneChangedNotificationTemplate, user.GetEmail(), data)
451451
}
452452

453-
func (m *Mailer) IdentityLinkedNotificationMail(r *http.Request, user *models.User, identityProvider string) error {
453+
func (m *Mailer) IdentityLinkedNotificationMail(r *http.Request, user *models.User, provider string) error {
454454
data := map[string]any{
455-
"Email": user.GetEmail(),
456-
"IdentityProvider": identityProvider, // the provider of the newly linked identity
457-
"Data": user.UserMetaData,
455+
"Email": user.GetEmail(),
456+
"Provider": provider, // the provider of the newly linked identity
457+
"Data": user.UserMetaData,
458458
}
459459
return m.mail(r.Context(), m.cfg, IdentityLinkedNotificationTemplate, user.GetEmail(), data)
460460
}
461461

462-
func (m *Mailer) IdentityUnlinkedNotificationMail(r *http.Request, user *models.User, identityProvider string) error {
462+
func (m *Mailer) IdentityUnlinkedNotificationMail(r *http.Request, user *models.User, provider string) error {
463463
data := map[string]any{
464-
"Email": user.GetEmail(),
465-
"IdentityProvider": identityProvider, // the provider of the unlinked identity
466-
"Data": user.UserMetaData,
464+
"Email": user.GetEmail(),
465+
"Provider": provider, // the provider of the unlinked identity
466+
"Data": user.UserMetaData,
467467
}
468468
return m.mail(r.Context(), m.cfg, IdentityUnlinkedNotificationTemplate, user.GetEmail(), data)
469469
}

0 commit comments

Comments
 (0)