From 6a4dadedf632fe8e60770736012ff189084b9f94 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Thu, 7 Sep 2023 07:11:29 +0000 Subject: [PATCH 01/10] notifies admins on new user registration Sends email with information on the new user (time of creation and time of last sign-in) and a link to manage the new user from the admin panel Refs: https://codeberg.org/forgejo/forgejo/issues/480 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/1371 Co-authored-by: Aravinth Manivannan Co-committed-by: Aravinth Manivannan (cherry picked from commit 7d2d9970115c94954dacb45684f9e3c16117ebfe) --- custom/conf/app.example.ini | 2 + modules/setting/admin.go | 1 + options/locale/locale_en-US.ini | 4 + routers/web/auth/auth.go | 3 +- services/mailer/mail_admin_new_user.go | 83 +++++++++++++++++++ services/mailer/mail_admin_new_user_test.go | 89 +++++++++++++++++++++ services/mailer/notify.go | 4 + services/notify/notifier.go | 2 + services/notify/notify.go | 7 ++ services/notify/null.go | 4 + templates/mail/admin_new_user.tmpl | 22 +++++ 11 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 services/mailer/mail_admin_new_user.go create mode 100644 services/mailer/mail_admin_new_user_test.go create mode 100644 templates/mail/admin_new_user.tmpl diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index cd6b2a914d237..a99639a8895f4 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -1450,6 +1450,8 @@ LEVEL = Info ;; ;; Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled ;DEFAULT_EMAIL_NOTIFICATIONS = enabled +;; Send email notifications to all instance admins on new user sign-ups. Options: enabled, true, false +;NOTIFY_NEW_SIGN_UPS = false ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/modules/setting/admin.go b/modules/setting/admin.go index 2d2dd26de94ae..4e2f343715608 100644 --- a/modules/setting/admin.go +++ b/modules/setting/admin.go @@ -7,6 +7,7 @@ package setting var Admin struct { DisableRegularOrgCreation bool DefaultEmailNotification string + NotifyNewSignUps bool } func loadAdminFrom(rootCfg ConfigProvider) { diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 74b8931de88ae..e4cffd78976b1 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -438,6 +438,10 @@ activate_email = Verify your email address activate_email.title = %s, please verify your email address activate_email.text = Please click the following link to verify your email address within %s: +admin.new_user.subject = New user %s +admin.new_user.user_info = User Information +admin.new_user.text = Please click here to manage the user from the admin panel. + register_notify = Welcome to Gitea register_notify.title = %[1]s, welcome to %[2]s register_notify.text_1 = this is your registration confirmation email for %s! diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index 8017602d99026..465077a909b90 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -30,6 +30,7 @@ import ( "code.gitea.io/gitea/services/externalaccount" "code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/mailer" + notify_service "code.gitea.io/gitea/services/notify" "github.com/markbates/goth" ) @@ -586,6 +587,7 @@ func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth. } } + notify_service.NewUserSignUp(ctx, u) // update external user information if gothUser != nil { if err := externalaccount.UpdateExternalUser(u, *gothUser); err != nil { @@ -609,7 +611,6 @@ func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth. ctx.Data["Email"] = u.Email ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale) ctx.HTML(http.StatusOK, TplActivate) - if setting.CacheService.Enabled { if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil { log.Error("Set cache(MailResendLimit) fail: %v", err) diff --git a/services/mailer/mail_admin_new_user.go b/services/mailer/mail_admin_new_user.go new file mode 100644 index 0000000000000..977565ea70e81 --- /dev/null +++ b/services/mailer/mail_admin_new_user.go @@ -0,0 +1,83 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// Copyright 2023 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT +package mailer + +import ( + "bytes" + "context" + "strconv" + + user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/templates" + "code.gitea.io/gitea/modules/translation" +) + +const ( + tplNewUserMail base.TplName = "admin_new_user" +) + +var sa = SendAsyncs + +// MailNewUser sends notification emails on new user registrations to all admins +func MailNewUser(ctx context.Context, u *user_model.User) { + if !setting.Admin.NotifyNewSignUps { + return + } + + if setting.MailService == nil { + // No mail service configured + return + } + + recipients, err := user_model.GetAllUsers(ctx) + if err != nil { + log.Error("user_model.GetAllUsers: %v", err) + return + } + + langMap := make(map[string][]string) + for _, r := range recipients { + if r.IsAdmin { + langMap[r.Language] = append(langMap[r.Language], r.Email) + } + } + + for lang, tos := range langMap { + mailNewUser(ctx, u, lang, tos) + } +} + +func mailNewUser(ctx context.Context, u *user_model.User, lang string, tos []string) { + locale := translation.NewLocale(lang) + + subject := locale.Tr("mail.admin.new_user.subject", u.Name) + manageUserURL := setting.AppSubURL + "/admin/users/" + strconv.FormatInt(u.ID, 10) + body := locale.Tr("mail.admin.new_user.text", manageUserURL) + mailMeta := map[string]any{ + "NewUser": u, + "Subject": subject, + "Body": body, + "Language": locale.Language(), + "locale": locale, + "Str2html": templates.Str2html, + } + + var mailBody bytes.Buffer + + if err := bodyTemplates.ExecuteTemplate(&mailBody, string(tplNewUserMail), mailMeta); err != nil { + log.Error("ExecuteTemplate [%s]: %v", string(tplNewUserMail)+"/body", err) + return + } + + msgs := make([]*Message, 0, len(tos)) + for _, to := range tos { + msg := NewMessage(to, subject, mailBody.String()) + msg.Info = subject + msgs = append(msgs, msg) + } + sa(msgs) +} diff --git a/services/mailer/mail_admin_new_user_test.go b/services/mailer/mail_admin_new_user_test.go new file mode 100644 index 0000000000000..20b65d8a8bb26 --- /dev/null +++ b/services/mailer/mail_admin_new_user_test.go @@ -0,0 +1,89 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// Copyright 2023 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package mailer + +import ( + "context" + "strconv" + "strings" + "testing" + + "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/setting" + + "github.com/stretchr/testify/assert" +) + +func getTestUsers() []*user_model.User { + admin := new(user_model.User) + admin.Name = "admin" + admin.IsAdmin = true + admin.Language = "en_US" + admin.Email = "admin@forgejo.org" + + newUser := new(user_model.User) + newUser.Name = "new_user" + newUser.Language = "en_US" + newUser.IsAdmin = false + newUser.Email = "new_user@forgejo.org" + newUser.LastLoginUnix = 1693648327 + newUser.CreatedUnix = 1693648027 + + user_model.CreateUser(db.DefaultContext, admin) + user_model.CreateUser(db.DefaultContext, newUser) + + users := make([]*user_model.User, 0) + users = append(users, admin) + users = append(users, newUser) + + return users +} + +func cleanUpUsers(ctx context.Context, users []*user_model.User) { + for _, u := range users { + db.DeleteByID(ctx, u.ID, new(user_model.User)) + } +} + +func TestAdminNotificationMail_test(t *testing.T) { + mailService := setting.Mailer{ + From: "test@forgejo.org", + Protocol: "dummy", + } + + setting.MailService = &mailService + setting.Domain = "localhost" + setting.AppSubURL = "http://localhost" + + // test with NOTIFY_NEW_SIGNUPS enabled + setting.Admin.NotifyNewSignUps = true + + ctx := context.Background() + NewContext(ctx) + + users := getTestUsers() + oldSendAsyncs := sa + defer func() { + sa = oldSendAsyncs + cleanUpUsers(ctx, users) + }() + + sa = func(msgs []*Message) { + assert.Equal(t, len(msgs), 1, "Test provides only one admin user, so only one email must be sent") + assert.Equal(t, msgs[0].To, users[0].Email, "checks if the recipient is the admin of the instance") + manageUserURL := "/admin/users/" + strconv.FormatInt(users[1].ID, 10) + assert.True(t, strings.ContainsAny(msgs[0].Body, manageUserURL), "checks if the message contains the link to manage the newly created user from the admin panel") + } + MailNewUser(ctx, users[1]) + + // test with NOTIFY_NEW_SIGNUPS disabled; emails shouldn't be sent + setting.Admin.NotifyNewSignUps = false + sa = func(msgs []*Message) { + assert.Equal(t, 1, 0, "this shouldn't execute. MailNewUser must exit early since NOTIFY_NEW_SIGNUPS is disabled") + } + + MailNewUser(ctx, users[1]) +} diff --git a/services/mailer/notify.go b/services/mailer/notify.go index 9eaf268d0ac89..1577e824a5e66 100644 --- a/services/mailer/notify.go +++ b/services/mailer/notify.go @@ -202,3 +202,7 @@ func (m *mailNotifier) RepoPendingTransfer(ctx context.Context, doer, newOwner * log.Error("SendRepoTransferNotifyMail: %v", err) } } + +func (m *mailNotifier) NewUserSignUp(ctx context.Context, newUser *user_model.User) { + MailNewUser(ctx, newUser) +} diff --git a/services/notify/notifier.go b/services/notify/notifier.go index ed053a812a6fd..3230a5e5f5c9b 100644 --- a/services/notify/notifier.go +++ b/services/notify/notifier.go @@ -59,6 +59,8 @@ type Notifier interface { EditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) + NewUserSignUp(ctx context.Context, newUser *user_model.User) + NewRelease(ctx context.Context, rel *repo_model.Release) UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) DeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) diff --git a/services/notify/notify.go b/services/notify/notify.go index 16fbb6325d0e9..1f7722f703b8e 100644 --- a/services/notify/notify.go +++ b/services/notify/notify.go @@ -347,6 +347,13 @@ func RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, r } } +// NewUserSignUp notifies deletion of a package to notifiers +func NewUserSignUp(ctx context.Context, newUser *user_model.User) { + for _, notifier := range notifiers { + notifier.NewUserSignUp(ctx, newUser) + } +} + // PackageCreate notifies creation of a package to notifiers func PackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { for _, notifier := range notifiers { diff --git a/services/notify/null.go b/services/notify/null.go index dddd421bef926..847a18d1af343 100644 --- a/services/notify/null.go +++ b/services/notify/null.go @@ -197,6 +197,10 @@ func (*NullNotifier) SyncDeleteRef(ctx context.Context, doer *user_model.User, r func (*NullNotifier) RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { } +// NotifyNewUserSignUp notifies deletion of a package to notifiers +func (*NullNotifier) NewUserSignUp(ctx context.Context, newUser *user_model.User) { +} + // PackageCreate places a place holder function func (*NullNotifier) PackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { } diff --git a/templates/mail/admin_new_user.tmpl b/templates/mail/admin_new_user.tmpl new file mode 100644 index 0000000000000..58b5c264e763a --- /dev/null +++ b/templates/mail/admin_new_user.tmpl @@ -0,0 +1,22 @@ + + + + + {{.Subject}} + + + + + + +
    +

    {{.locale.Tr "mail.admin.new_user.user_info"}}

    +
  • {{.locale.Tr "admin.users.created"}}: {{DateTime "full" .NewUser.LastLoginUnix}}
  • +
  • {{.locale.Tr "admin.users.last_login"}}: {{DateTime "full" .NewUser.CreatedUnix}}
  • +
+

{{.Body | Str2html}}

+ + From c65ac7cc5bb4fe2f2baf1e641ef61203ca9bdcc6 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 19 Sep 2023 18:40:01 +0200 Subject: [PATCH 02/10] performance bottleneck Refs: https://codeberg.org/forgejo/forgejo/issues/1479 --- models/user/user.go | 6 ++++++ models/user/user_test.go | 10 ++++++++++ services/mailer/mail_admin_new_user.go | 8 +++----- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/models/user/user.go b/models/user/user.go index 63b95816cefce..a3bdff33d2e25 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -223,6 +223,12 @@ func GetAllUsers(ctx context.Context) ([]*User, error) { return users, db.GetEngine(ctx).OrderBy("id").Where("type = ?", UserTypeIndividual).Find(&users) } +// GetAllAdmins returns a slice of all adminusers found in DB. +func GetAllAdmins(ctx context.Context) ([]*User, error) { + users := make([]*User, 0) + return users, db.GetEngine(ctx).OrderBy("id").Where("type = ?", UserTypeIndividual).And("is_admin = ?", true).Find(&users) +} + // IsLocal returns true if user login type is LoginPlain. func (u *User) IsLocal() bool { return u.LoginType <= auth.Plain diff --git a/models/user/user_test.go b/models/user/user_test.go index 971117482c2d4..fed2cb2c4887e 100644 --- a/models/user/user_test.go +++ b/models/user/user_test.go @@ -544,3 +544,13 @@ func Test_ValidateUser(t *testing.T) { assert.EqualValues(t, expected, err == nil, fmt.Sprintf("case: %+v", kase)) } } + +func TestGetAllAdmins(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + + admins, err := user_model.GetAllAdmins(db.DefaultContext) + assert.NoError(t, err) + + assert.Len(t, admins, 1) + assert.Equal(t, int64(1), admins[0].ID) +} diff --git a/services/mailer/mail_admin_new_user.go b/services/mailer/mail_admin_new_user.go index 977565ea70e81..9af4ee12bdd5c 100644 --- a/services/mailer/mail_admin_new_user.go +++ b/services/mailer/mail_admin_new_user.go @@ -33,17 +33,15 @@ func MailNewUser(ctx context.Context, u *user_model.User) { return } - recipients, err := user_model.GetAllUsers(ctx) + recipients, err := user_model.GetAllAdmins(ctx) if err != nil { - log.Error("user_model.GetAllUsers: %v", err) + log.Error("user_model.GetAllAdmins: %v", err) return } langMap := make(map[string][]string) for _, r := range recipients { - if r.IsAdmin { - langMap[r.Language] = append(langMap[r.Language], r.Email) - } + langMap[r.Language] = append(langMap[r.Language], r.Email) } for lang, tos := range langMap { From da0c7732a9af58da087cf0bc46653ddf3df7e035 Mon Sep 17 00:00:00 2001 From: Earl Warren <109468362+earl-warren@users.noreply.github.com> Date: Wed, 20 Sep 2023 06:18:10 +0200 Subject: [PATCH 03/10] Update custom/conf/app.example.ini Co-authored-by: delvh --- custom/conf/app.example.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index a99639a8895f4..3e98980376bbc 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -1450,7 +1450,7 @@ LEVEL = Info ;; ;; Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled ;DEFAULT_EMAIL_NOTIFICATIONS = enabled -;; Send email notifications to all instance admins on new user sign-ups. Options: enabled, true, false +;; Send an email to all admins when a new user signs up to inform the admins about this act. Options: true, false ;NOTIFY_NEW_SIGN_UPS = false ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; From 90ebec7bd14660cb6d0ba6a4181cf2336d2da414 Mon Sep 17 00:00:00 2001 From: Earl Warren <109468362+earl-warren@users.noreply.github.com> Date: Wed, 20 Sep 2023 06:18:42 +0200 Subject: [PATCH 04/10] Update options/locale/locale_en-US.ini Co-authored-by: delvh --- options/locale/locale_en-US.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index e4cffd78976b1..daa919f0980d5 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -438,7 +438,7 @@ activate_email = Verify your email address activate_email.title = %s, please verify your email address activate_email.text = Please click the following link to verify your email address within %s: -admin.new_user.subject = New user %s +admin.new_user.subject = New user %s just signed up admin.new_user.user_info = User Information admin.new_user.text = Please click here to manage the user from the admin panel. From c3e9f90a9b77400fcf9ae9eef4993d612ae380e3 Mon Sep 17 00:00:00 2001 From: Earl Warren <109468362+earl-warren@users.noreply.github.com> Date: Wed, 20 Sep 2023 06:19:11 +0200 Subject: [PATCH 05/10] Update services/notify/null.go Co-authored-by: delvh --- services/notify/null.go | 1 - 1 file changed, 1 deletion(-) diff --git a/services/notify/null.go b/services/notify/null.go index 847a18d1af343..894d118eacd47 100644 --- a/services/notify/null.go +++ b/services/notify/null.go @@ -197,7 +197,6 @@ func (*NullNotifier) SyncDeleteRef(ctx context.Context, doer *user_model.User, r func (*NullNotifier) RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { } -// NotifyNewUserSignUp notifies deletion of a package to notifiers func (*NullNotifier) NewUserSignUp(ctx context.Context, newUser *user_model.User) { } From 8c79764fa0e9578980936abfa82a8c84039fb0ac Mon Sep 17 00:00:00 2001 From: Earl Warren <109468362+earl-warren@users.noreply.github.com> Date: Wed, 20 Sep 2023 06:19:53 +0200 Subject: [PATCH 06/10] Update services/notify/notify.go Co-authored-by: delvh --- services/notify/notify.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/notify/notify.go b/services/notify/notify.go index 1f7722f703b8e..9cb329d302317 100644 --- a/services/notify/notify.go +++ b/services/notify/notify.go @@ -347,7 +347,7 @@ func RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, r } } -// NewUserSignUp notifies deletion of a package to notifiers +// NewUserSignUp notifies about a newly signed up user to notifiers func NewUserSignUp(ctx context.Context, newUser *user_model.User) { for _, notifier := range notifiers { notifier.NewUserSignUp(ctx, newUser) From 5338f81d9dde256c974defbf6cf80cabe4682e64 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 20 Sep 2023 06:25:15 +0200 Subject: [PATCH 07/10] s/forgejo.org/example.com/ --- services/mailer/mail_admin_new_user_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/mailer/mail_admin_new_user_test.go b/services/mailer/mail_admin_new_user_test.go index 20b65d8a8bb26..916aa579fb664 100644 --- a/services/mailer/mail_admin_new_user_test.go +++ b/services/mailer/mail_admin_new_user_test.go @@ -22,13 +22,13 @@ func getTestUsers() []*user_model.User { admin.Name = "admin" admin.IsAdmin = true admin.Language = "en_US" - admin.Email = "admin@forgejo.org" + admin.Email = "admin@example.com" newUser := new(user_model.User) newUser.Name = "new_user" newUser.Language = "en_US" newUser.IsAdmin = false - newUser.Email = "new_user@forgejo.org" + newUser.Email = "new_user@example.com" newUser.LastLoginUnix = 1693648327 newUser.CreatedUnix = 1693648027 @@ -50,7 +50,7 @@ func cleanUpUsers(ctx context.Context, users []*user_model.User) { func TestAdminNotificationMail_test(t *testing.T) { mailService := setting.Mailer{ - From: "test@forgejo.org", + From: "test@example.com", Protocol: "dummy", } From 99dbec58f9d4b2e6e63e089d0a7a231a2eb58aa6 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 20 Sep 2023 06:25:33 +0200 Subject: [PATCH 08/10] s/NOTIFY_NEW_SIGN_UPS/SEND_NOTIFICATION_EMAIL_ON_NEW_USER/ --- custom/conf/app.example.ini | 2 +- modules/setting/admin.go | 6 +++--- services/mailer/mail_admin_new_user.go | 2 +- services/mailer/mail_admin_new_user_test.go | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 3e98980376bbc..5cb80635e42df 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -1451,7 +1451,7 @@ LEVEL = Info ;; Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled ;DEFAULT_EMAIL_NOTIFICATIONS = enabled ;; Send an email to all admins when a new user signs up to inform the admins about this act. Options: true, false -;NOTIFY_NEW_SIGN_UPS = false +;SEND_NOTIFICATION_EMAIL_ON_NEW_USER = false ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/modules/setting/admin.go b/modules/setting/admin.go index 4e2f343715608..d7f0ee827dbc1 100644 --- a/modules/setting/admin.go +++ b/modules/setting/admin.go @@ -5,9 +5,9 @@ package setting // Admin settings var Admin struct { - DisableRegularOrgCreation bool - DefaultEmailNotification string - NotifyNewSignUps bool + DisableRegularOrgCreation bool + DefaultEmailNotification string + SendNotificationEmailOnNewUser bool } func loadAdminFrom(rootCfg ConfigProvider) { diff --git a/services/mailer/mail_admin_new_user.go b/services/mailer/mail_admin_new_user.go index 9af4ee12bdd5c..9ec24b75341b1 100644 --- a/services/mailer/mail_admin_new_user.go +++ b/services/mailer/mail_admin_new_user.go @@ -24,7 +24,7 @@ var sa = SendAsyncs // MailNewUser sends notification emails on new user registrations to all admins func MailNewUser(ctx context.Context, u *user_model.User) { - if !setting.Admin.NotifyNewSignUps { + if !setting.Admin.SendNotificationEmailOnNewUser { return } diff --git a/services/mailer/mail_admin_new_user_test.go b/services/mailer/mail_admin_new_user_test.go index 916aa579fb664..67212c9a26c91 100644 --- a/services/mailer/mail_admin_new_user_test.go +++ b/services/mailer/mail_admin_new_user_test.go @@ -58,8 +58,8 @@ func TestAdminNotificationMail_test(t *testing.T) { setting.Domain = "localhost" setting.AppSubURL = "http://localhost" - // test with NOTIFY_NEW_SIGNUPS enabled - setting.Admin.NotifyNewSignUps = true + // test with SEND_NOTIFICATION_EMAIL_ON_NEW_USER enabled + setting.Admin.SendNotificationEmailOnNewUser = true ctx := context.Background() NewContext(ctx) @@ -79,10 +79,10 @@ func TestAdminNotificationMail_test(t *testing.T) { } MailNewUser(ctx, users[1]) - // test with NOTIFY_NEW_SIGNUPS disabled; emails shouldn't be sent - setting.Admin.NotifyNewSignUps = false + // test with SEND_NOTIFICATION_EMAIL_ON_NEW_USER disabled; emails shouldn't be sent + setting.Admin.SendNotificationEmailOnNewUser = false sa = func(msgs []*Message) { - assert.Equal(t, 1, 0, "this shouldn't execute. MailNewUser must exit early since NOTIFY_NEW_SIGNUPS is disabled") + assert.Equal(t, 1, 0, "this shouldn't execute. MailNewUser must exit early since SEND_NOTIFICATION_EMAIL_ON_NEW_USER is disabled") } MailNewUser(ctx, users[1]) From ac8bfe4629fc4450a35650c2368e319d1e079211 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 20 Sep 2023 06:37:35 +0200 Subject: [PATCH 09/10] move template to mail/notify/admin_new_user.tmpl --- services/mailer/mail_admin_new_user.go | 2 +- templates/mail/{ => notify}/admin_new_user.tmpl | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename templates/mail/{ => notify}/admin_new_user.tmpl (100%) diff --git a/services/mailer/mail_admin_new_user.go b/services/mailer/mail_admin_new_user.go index 9ec24b75341b1..6a164130c30f4 100644 --- a/services/mailer/mail_admin_new_user.go +++ b/services/mailer/mail_admin_new_user.go @@ -17,7 +17,7 @@ import ( ) const ( - tplNewUserMail base.TplName = "admin_new_user" + tplNewUserMail base.TplName = "notify/admin_new_user" ) var sa = SendAsyncs diff --git a/templates/mail/admin_new_user.tmpl b/templates/mail/notify/admin_new_user.tmpl similarity index 100% rename from templates/mail/admin_new_user.tmpl rename to templates/mail/notify/admin_new_user.tmpl From d852d5c191dff87da1cf3146fa7c12fe3683dc7f Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 20 Sep 2023 06:44:07 +0200 Subject: [PATCH 10/10] update config-cheat-sheet --- docs/content/administration/config-cheat-sheet.en-us.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/content/administration/config-cheat-sheet.en-us.md b/docs/content/administration/config-cheat-sheet.en-us.md index aa29f8be4b8ca..120c918ddc141 100644 --- a/docs/content/administration/config-cheat-sheet.en-us.md +++ b/docs/content/administration/config-cheat-sheet.en-us.md @@ -510,6 +510,7 @@ And the following unique queues: - `DEFAULT_EMAIL_NOTIFICATIONS`: **enabled**: Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled - `DISABLE_REGULAR_ORG_CREATION`: **false**: Disallow regular (non-admin) users from creating organizations. +- `SEND_NOTIFICATION_EMAIL_ON_NEW_USER`: **false**: Send an email to all admins when a new user signs up to inform the admins about this act. ## Security (`security`)