summaryrefslogtreecommitdiff
path: root/internal/processing/workers/surfaceemail.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-04-13 13:25:10 +0200
committerLibravatar GitHub <noreply@github.com>2024-04-13 13:25:10 +0200
commit89e0cfd8741b6763ca04e90558bccf4c3c380cfa (patch)
tree5858ada73473816fa1982f12717b66996d163f9d /internal/processing/workers/surfaceemail.go
parent[performance] update GetAccountsByIDs() to use the new multi cache loader end... (diff)
downloadgotosocial-89e0cfd8741b6763ca04e90558bccf4c3c380cfa.tar.xz
[feature] Admin accounts endpoints; approve/reject sign-ups (#2826)
* update settings panels, add pending overview + approve/deny functions * add admin accounts get, approve, reject * send approved/rejected emails * use signup URL * docs! * email * swagger * web linting * fix email tests * wee lil fixerinos * use new paging logic for GetAccounts() series of admin endpoints, small changes to query building * shuffle useAccountIDIn check *before* adding to query * fix parse from toot react error * use `netip.Addr` * put valid slices in globals * optimistic updates for account state --------- Co-authored-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/processing/workers/surfaceemail.go')
-rw-r--r--internal/processing/workers/surfaceemail.go65
1 files changed, 64 insertions, 1 deletions
diff --git a/internal/processing/workers/surfaceemail.go b/internal/processing/workers/surfaceemail.go
index c00b22c86..3a5b5e7f4 100644
--- a/internal/processing/workers/surfaceemail.go
+++ b/internal/processing/workers/surfaceemail.go
@@ -129,6 +129,69 @@ func (s *surface) emailUserPleaseConfirm(ctx context.Context, user *gtsmodel.Use
return nil
}
+// emailUserSignupApproved emails the given user
+// to inform them their sign-up has been approved.
+func (s *surface) emailUserSignupApproved(ctx context.Context, user *gtsmodel.User) error {
+ // User may have been approved without
+ // their email address being confirmed
+ // yet. Just send to whatever we have.
+ emailAddr := user.Email
+ if emailAddr == "" {
+ emailAddr = user.UnconfirmedEmail
+ }
+
+ instance, err := s.state.DB.GetInstance(ctx, config.GetHost())
+ if err != nil {
+ return gtserror.Newf("db error getting instance: %w", err)
+ }
+
+ // Assemble email contents and send the email.
+ if err := s.emailSender.SendSignupApprovedEmail(
+ emailAddr,
+ email.SignupApprovedData{
+ Username: user.Account.Username,
+ InstanceURL: instance.URI,
+ InstanceName: instance.Title,
+ },
+ ); err != nil {
+ return err
+ }
+
+ // Email sent, update the user
+ // entry with the emailed time.
+ now := time.Now()
+ user.LastEmailedAt = now
+
+ if err := s.state.DB.UpdateUser(
+ ctx,
+ user,
+ "last_emailed_at",
+ ); err != nil {
+ return gtserror.Newf("error updating user entry after email sent: %w", err)
+ }
+
+ return nil
+}
+
+// emailUserSignupApproved emails the given user
+// to inform them their sign-up has been approved.
+func (s *surface) emailUserSignupRejected(ctx context.Context, deniedUser *gtsmodel.DeniedUser) error {
+ instance, err := s.state.DB.GetInstance(ctx, config.GetHost())
+ if err != nil {
+ return gtserror.Newf("db error getting instance: %w", err)
+ }
+
+ // Assemble email contents and send the email.
+ return s.emailSender.SendSignupRejectedEmail(
+ deniedUser.Email,
+ email.SignupRejectedData{
+ Message: deniedUser.Message,
+ InstanceURL: instance.URI,
+ InstanceName: instance.Title,
+ },
+ )
+}
+
// emailAdminReportOpened emails all active moderators/admins
// of this instance that a new report has been created.
func (s *surface) emailAdminReportOpened(ctx context.Context, report *gtsmodel.Report) error {
@@ -193,7 +256,7 @@ func (s *surface) emailAdminNewSignup(ctx context.Context, newUser *gtsmodel.Use
SignupEmail: newUser.UnconfirmedEmail,
SignupUsername: newUser.Account.Username,
SignupReason: newUser.Reason,
- SignupURL: "TODO",
+ SignupURL: instance.URI + "/settings/admin/accounts/" + newUser.AccountID,
}
if err := s.emailSender.SendNewSignupEmail(toAddresses, newSignupData); err != nil {