mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-19 16:21:11 +01:00
[GITEA] notifies admins on new user registration (squash) cosmetic changes
Co-authored-by: delvh <dev.lh@web.de> (cherry picked from commit9f1670e040
) (cherry picked from commitde5bb2a224
)
This commit is contained in:
parent
3367dcb2cf
commit
8f8e52f31a
9 changed files with 18 additions and 18 deletions
|
@ -1455,8 +1455,8 @@ LEVEL = Info
|
||||||
;;
|
;;
|
||||||
;; Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
|
;; Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
|
||||||
;DEFAULT_EMAIL_NOTIFICATIONS = enabled
|
;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
|
;SEND_NOTIFICATION_EMAIL_ON_NEW_USER = false
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
|
@ -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
|
- `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.
|
- `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`)
|
## Security (`security`)
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,9 @@ package setting
|
||||||
|
|
||||||
// Admin settings
|
// Admin settings
|
||||||
var Admin struct {
|
var Admin struct {
|
||||||
DisableRegularOrgCreation bool
|
DisableRegularOrgCreation bool
|
||||||
DefaultEmailNotification string
|
DefaultEmailNotification string
|
||||||
NotifyNewSignUps bool
|
SendNotificationEmailOnNewUser bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadAdminFrom(rootCfg ConfigProvider) {
|
func loadAdminFrom(rootCfg ConfigProvider) {
|
||||||
|
|
|
@ -441,7 +441,7 @@ activate_email = Verify your email address
|
||||||
activate_email.title = %s, please 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 <b>%s</b>:
|
activate_email.text = Please click the following link to verify your email address within <b>%s</b>:
|
||||||
|
|
||||||
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.user_info = User Information
|
||||||
admin.new_user.text = Please <a href="%s">click here</a> to manage the user from the admin panel.
|
admin.new_user.text = Please <a href="%s">click here</a> to manage the user from the admin panel.
|
||||||
|
|
||||||
|
|
|
@ -16,14 +16,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
tplNewUserMail base.TplName = "admin_new_user"
|
tplNewUserMail base.TplName = "notify/admin_new_user"
|
||||||
)
|
)
|
||||||
|
|
||||||
var sa = SendAsyncs
|
var sa = SendAsyncs
|
||||||
|
|
||||||
// MailNewUser sends notification emails on new user registrations to all admins
|
// MailNewUser sends notification emails on new user registrations to all admins
|
||||||
func MailNewUser(ctx context.Context, u *user_model.User) {
|
func MailNewUser(ctx context.Context, u *user_model.User) {
|
||||||
if !setting.Admin.NotifyNewSignUps {
|
if !setting.Admin.SendNotificationEmailOnNewUser {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,13 +21,13 @@ func getTestUsers() []*user_model.User {
|
||||||
admin.Name = "admin"
|
admin.Name = "admin"
|
||||||
admin.IsAdmin = true
|
admin.IsAdmin = true
|
||||||
admin.Language = "en_US"
|
admin.Language = "en_US"
|
||||||
admin.Email = "admin@forgejo.org"
|
admin.Email = "admin@example.com"
|
||||||
|
|
||||||
newUser := new(user_model.User)
|
newUser := new(user_model.User)
|
||||||
newUser.Name = "new_user"
|
newUser.Name = "new_user"
|
||||||
newUser.Language = "en_US"
|
newUser.Language = "en_US"
|
||||||
newUser.IsAdmin = false
|
newUser.IsAdmin = false
|
||||||
newUser.Email = "new_user@forgejo.org"
|
newUser.Email = "new_user@example.com"
|
||||||
newUser.LastLoginUnix = 1693648327
|
newUser.LastLoginUnix = 1693648327
|
||||||
newUser.CreatedUnix = 1693648027
|
newUser.CreatedUnix = 1693648027
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ func cleanUpUsers(ctx context.Context, users []*user_model.User) {
|
||||||
|
|
||||||
func TestAdminNotificationMail_test(t *testing.T) {
|
func TestAdminNotificationMail_test(t *testing.T) {
|
||||||
mailService := setting.Mailer{
|
mailService := setting.Mailer{
|
||||||
From: "test@forgejo.org",
|
From: "test@example.com",
|
||||||
Protocol: "dummy",
|
Protocol: "dummy",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,8 +57,8 @@ func TestAdminNotificationMail_test(t *testing.T) {
|
||||||
setting.Domain = "localhost"
|
setting.Domain = "localhost"
|
||||||
setting.AppSubURL = "http://localhost"
|
setting.AppSubURL = "http://localhost"
|
||||||
|
|
||||||
// test with NOTIFY_NEW_SIGNUPS enabled
|
// test with SEND_NOTIFICATION_EMAIL_ON_NEW_USER enabled
|
||||||
setting.Admin.NotifyNewSignUps = true
|
setting.Admin.SendNotificationEmailOnNewUser = true
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
NewContext(ctx)
|
NewContext(ctx)
|
||||||
|
@ -78,10 +78,10 @@ func TestAdminNotificationMail_test(t *testing.T) {
|
||||||
}
|
}
|
||||||
MailNewUser(ctx, users[1])
|
MailNewUser(ctx, users[1])
|
||||||
|
|
||||||
// test with NOTIFY_NEW_SIGNUPS disabled; emails shouldn't be sent
|
// test with SEND_NOTIFICATION_EMAIL_ON_NEW_USER disabled; emails shouldn't be sent
|
||||||
setting.Admin.NotifyNewSignUps = false
|
setting.Admin.SendNotificationEmailOnNewUser = false
|
||||||
sa = func(msgs []*Message) {
|
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])
|
MailNewUser(ctx, users[1])
|
||||||
|
|
|
@ -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) {
|
func NewUserSignUp(ctx context.Context, newUser *user_model.User) {
|
||||||
for _, notifier := range notifiers {
|
for _, notifier := range notifiers {
|
||||||
notifier.NewUserSignUp(ctx, newUser)
|
notifier.NewUserSignUp(ctx, newUser)
|
||||||
|
|
|
@ -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) {
|
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) {
|
func (*NullNotifier) NewUserSignUp(ctx context.Context, newUser *user_model.User) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue