Skip to content

Commit 9f1670e

Browse files
earl-warrendelvh
andcommitted
[GITEA] notifies admins on new user registration (squash) cosmetic changes
Co-authored-by: delvh <[email protected]>
1 parent 97ac914 commit 9f1670e

File tree

9 files changed

+18
-18
lines changed

9 files changed

+18
-18
lines changed

custom/conf/app.example.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,8 +1455,8 @@ LEVEL = Info
14551455
;;
14561456
;; Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
14571457
;DEFAULT_EMAIL_NOTIFICATIONS = enabled
1458-
;; Send email notifications to all instance admins on new user sign-ups. Options: enabled, true, false
1459-
;NOTIFY_NEW_SIGN_UPS = false
1458+
;; Send an email to all admins when a new user signs up to inform the admins about this act. Options: true, false
1459+
;SEND_NOTIFICATION_EMAIL_ON_NEW_USER = false
14601460

14611461
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14621462
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ And the following unique queues:
510510

511511
- `DEFAULT_EMAIL_NOTIFICATIONS`: **enabled**: Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
512512
- `DISABLE_REGULAR_ORG_CREATION`: **false**: Disallow regular (non-admin) users from creating organizations.
513+
- `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.
513514

514515
## Security (`security`)
515516

modules/setting/admin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ package setting
55

66
// Admin settings
77
var Admin struct {
8-
DisableRegularOrgCreation bool
9-
DefaultEmailNotification string
10-
NotifyNewSignUps bool
8+
DisableRegularOrgCreation bool
9+
DefaultEmailNotification string
10+
SendNotificationEmailOnNewUser bool
1111
}
1212

1313
func loadAdminFrom(rootCfg ConfigProvider) {

options/locale/locale_en-US.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ activate_email = Verify your email address
439439
activate_email.title = %s, please verify your email address
440440
activate_email.text = Please click the following link to verify your email address within <b>%s</b>:
441441

442-
admin.new_user.subject = New user %s
442+
admin.new_user.subject = New user %s just signed up
443443
admin.new_user.user_info = User Information
444444
admin.new_user.text = Please <a href="%s">click here</a> to manage the user from the admin panel.
445445

services/mailer/mail_admin_new_user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import (
1616
)
1717

1818
const (
19-
tplNewUserMail base.TplName = "admin_new_user"
19+
tplNewUserMail base.TplName = "notify/admin_new_user"
2020
)
2121

2222
var sa = SendAsyncs
2323

2424
// MailNewUser sends notification emails on new user registrations to all admins
2525
func MailNewUser(ctx context.Context, u *user_model.User) {
26-
if !setting.Admin.NotifyNewSignUps {
26+
if !setting.Admin.SendNotificationEmailOnNewUser {
2727
return
2828
}
2929

services/mailer/mail_admin_new_user_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ func getTestUsers() []*user_model.User {
2121
admin.Name = "admin"
2222
admin.IsAdmin = true
2323
admin.Language = "en_US"
24-
admin.Email = "admin@forgejo.org"
24+
admin.Email = "admin@example.com"
2525

2626
newUser := new(user_model.User)
2727
newUser.Name = "new_user"
2828
newUser.Language = "en_US"
2929
newUser.IsAdmin = false
30-
newUser.Email = "new_user@forgejo.org"
30+
newUser.Email = "new_user@example.com"
3131
newUser.LastLoginUnix = 1693648327
3232
newUser.CreatedUnix = 1693648027
3333

@@ -49,16 +49,16 @@ func cleanUpUsers(ctx context.Context, users []*user_model.User) {
4949

5050
func TestAdminNotificationMail_test(t *testing.T) {
5151
mailService := setting.Mailer{
52-
From: "test@forgejo.org",
52+
From: "test@example.com",
5353
Protocol: "dummy",
5454
}
5555

5656
setting.MailService = &mailService
5757
setting.Domain = "localhost"
5858
setting.AppSubURL = "http://localhost"
5959

60-
// test with NOTIFY_NEW_SIGNUPS enabled
61-
setting.Admin.NotifyNewSignUps = true
60+
// test with SEND_NOTIFICATION_EMAIL_ON_NEW_USER enabled
61+
setting.Admin.SendNotificationEmailOnNewUser = true
6262

6363
ctx := context.Background()
6464
NewContext(ctx)
@@ -78,10 +78,10 @@ func TestAdminNotificationMail_test(t *testing.T) {
7878
}
7979
MailNewUser(ctx, users[1])
8080

81-
// test with NOTIFY_NEW_SIGNUPS disabled; emails shouldn't be sent
82-
setting.Admin.NotifyNewSignUps = false
81+
// test with SEND_NOTIFICATION_EMAIL_ON_NEW_USER disabled; emails shouldn't be sent
82+
setting.Admin.SendNotificationEmailOnNewUser = false
8383
sa = func(msgs []*Message) {
84-
assert.Equal(t, 1, 0, "this shouldn't execute. MailNewUser must exit early since NOTIFY_NEW_SIGNUPS is disabled")
84+
assert.Equal(t, 1, 0, "this shouldn't execute. MailNewUser must exit early since SEND_NOTIFICATION_EMAIL_ON_NEW_USER is disabled")
8585
}
8686

8787
MailNewUser(ctx, users[1])

services/notify/notify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, r
347347
}
348348
}
349349

350-
// NewUserSignUp notifies deletion of a package to notifiers
350+
// NewUserSignUp notifies about a newly signed up user to notifiers
351351
func NewUserSignUp(ctx context.Context, newUser *user_model.User) {
352352
for _, notifier := range notifiers {
353353
notifier.NewUserSignUp(ctx, newUser)

services/notify/null.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ func (*NullNotifier) SyncDeleteRef(ctx context.Context, doer *user_model.User, r
197197
func (*NullNotifier) RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) {
198198
}
199199

200-
// NotifyNewUserSignUp notifies deletion of a package to notifiers
201200
func (*NullNotifier) NewUserSignUp(ctx context.Context, newUser *user_model.User) {
202201
}
203202

0 commit comments

Comments
 (0)