Skip to content

Commit

Permalink
is: FIx linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaplots committed Oct 22, 2024
1 parent 6fd6ed4 commit bacd252
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
21 changes: 10 additions & 11 deletions pkg/identityserver/invitation_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,16 @@ func (is *IdentityServer) sendInvitation(ctx context.Context, in *ttnpb.SendInvi
return nil, err
}
events.Publish(evtCreateInvitation.NewWithIdentifiersAndData(ctx, nil, invitation))
go is.SendTemplateEmailToUsers(is.FromRequestContext(ctx), ttnpb.NotificationType_INVITATION, func(ctx context.Context, data email.TemplateData) (email.TemplateData, error) {
if err != nil {
return nil, err
}
return &templates.InvitationData{
TemplateData: data,
SenderIds: authInfo.GetEntityIdentifiers().GetUserIds(),
InvitationToken: invitation.Token,
TTL: ttl,
}, nil
}, &ttnpb.User{PrimaryEmailAddress: in.Email})
go is.SendTemplateEmailToUsers( // nolint:errcheck
is.FromRequestContext(ctx), ttnpb.NotificationType_INVITATION,
func(ctx context.Context, data email.TemplateData) (email.TemplateData, error) {

Check failure on line 73 in pkg/identityserver/invitation_registry.go

View workflow job for this annotation

GitHub Actions / Code Quality

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
return &templates.InvitationData{
TemplateData: data,
SenderIds: authInfo.GetEntityIdentifiers().GetUserIds(),
InvitationToken: invitation.Token,
TTL: ttl,
}, nil
}, &ttnpb.User{PrimaryEmailAddress: in.Email})
return invitation, nil
}

Expand Down
21 changes: 14 additions & 7 deletions pkg/identityserver/notification_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ func notificationTypeAllowed(notificationType ttnpb.NotificationType, allowedNot
return false
}

func filterAllowedEmailReveivers(emailReceiverUsers []*ttnpb.User, notificationType ttnpb.NotificationType) []*ttnpb.UserIdentifiers {
var emailReceiverIDs []*ttnpb.UserIdentifiers
// Collect IDs of users that have email notifications enabled for that notification type.
for _, user := range emailReceiverUsers {
userNotificationPreferences := user.GetEmailNotificationPreferences().GetTypes()
if notificationTypeAllowed(notificationType, userNotificationPreferences) {
emailReceiverIDs = append(emailReceiverIDs, user.GetIds())
}
}
return emailReceiverIDs
}

func uniqueOrganizationOrUserIdentifiers(ctx context.Context, ids []*ttnpb.OrganizationOrUserIdentifiers) []*ttnpb.OrganizationOrUserIdentifiers {
out := make([]*ttnpb.OrganizationOrUserIdentifiers, 0, len(ids))
seen := make(map[string]struct{}, len(ids))
Expand Down Expand Up @@ -232,13 +244,8 @@ func (is *IdentityServer) lookupNotificationReceivers(ctx context.Context, req *

// Get the email notification preferences of the receiver users.
emailReceiverUsers, _ := st.FindUsers(ctx, receiverUserIDs, []string{"email_notification_preferences"})
// Collect IDs of users that have email notifications enabled for that notification type.
for _, user := range emailReceiverUsers {
userNotificationPreferences := user.GetEmailNotificationPreferences().GetTypes()
if notificationTypeAllowed(req.NotificationType, userNotificationPreferences) {
emailReceiverIDs = append(emailReceiverIDs, user.Ids)
}
}
// Filter only the users that have email notifications enabled for the notification type.
emailReceiverIDs = filterAllowedEmailReveivers(emailReceiverUsers, req.NotificationType)

return nil
})
Expand Down
19 changes: 9 additions & 10 deletions pkg/identityserver/user_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,16 +679,15 @@ func (is *IdentityServer) createTemporaryPassword(ctx context.Context, req *ttnp
"temporary_password", temporaryPassword,
)).Info("Created temporary password")
events.Publish(evtUpdateUser.NewWithIdentifiersAndData(ctx, req.GetUserIds(), updateTemporaryPasswordFieldMask))
go is.SendTemplateEmailToUserIDs(is.FromRequestContext(ctx), ttnpb.NotificationType_TEMPORARY_PASSWORD, func(ctx context.Context, data email.TemplateData) (email.TemplateData, error) {
if err != nil {
return nil, err
}
return &templates.TemporaryPasswordData{
TemplateData: data,
TemporaryPassword: temporaryPassword,
TTL: ttl,
}, nil
}, req.GetUserIds())
go is.SendTemplateEmailToUserIDs( // nolint:errcheck
is.FromRequestContext(ctx), ttnpb.NotificationType_TEMPORARY_PASSWORD,
func(ctx context.Context, data email.TemplateData) (email.TemplateData, error) {

Check failure on line 684 in pkg/identityserver/user_registry.go

View workflow job for this annotation

GitHub Actions / Code Quality

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
return &templates.TemporaryPasswordData{
TemplateData: data,
TemporaryPassword: temporaryPassword,
TTL: ttl,
}, nil
}, req.GetUserIds())

return ttnpb.Empty, nil
}
Expand Down

0 comments on commit bacd252

Please sign in to comment.