From ac889d42903b2ce2129a02ace620a10a6f940920 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Fri, 15 Dec 2023 20:58:28 +0000 Subject: [PATCH] [GITEA] notifies admins on new user registration (squash) fix URL ## Changes: 1. Use absolute URL in the admin panel link sent on new registrations 2. Include absolute URL of the newly signed-up user's profile. New email looks like this:
Please click to expand ``` --153937b1864f158f4fd145c4b5d4a513568681dd489021dd466a8ad7b770 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 User Information: @realaravinth ( http://localhost:3000/realaravinth ) ---------------------------------------------------------------------- * Created: 2023-12-13 19:36:50 +05:30 Please click here ( http://localhost:3000/admin/users/9 ) to manage the use= r from the admin panel. --153937b1864f158f4fd145c4b5d4a513568681dd489021dd466a8ad7b770 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 New user realaravinth just signed up

Please click here to manage the user from the admin panel.

--153937b1864f158f4fd145c4b5d4a513568681dd489021dd466a8ad7b770-- ```
fixes: https://codeberg.org/forgejo/forgejo/issues/1927 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/1940 Reviewed-by: Earl Warren Reviewed-by: Gusted Co-authored-by: Aravinth Manivannan Co-committed-by: Aravinth Manivannan (cherry picked from commit b8d764e36a0cd8e60627805f87b84bb04152e9c1) --- services/mailer/mail_admin_new_user.go | 15 ++++++++------- services/mailer/mail_admin_new_user_test.go | 5 ++--- templates/mail/notify/admin_new_user.tmpl | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/services/mailer/mail_admin_new_user.go b/services/mailer/mail_admin_new_user.go index e6372c5200..e9610e626a 100644 --- a/services/mailer/mail_admin_new_user.go +++ b/services/mailer/mail_admin_new_user.go @@ -51,16 +51,17 @@ func MailNewUser(ctx context.Context, u *user_model.User) { func mailNewUser(ctx context.Context, u *user_model.User, lang string, tos []string) { locale := translation.NewLocale(lang) + manageUserURL := setting.AppURL + "admin/users/" + strconv.FormatInt(u.ID, 10) 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, + "NewUser": u, + "NewUserUrl": u.HTMLURL(), + "Subject": subject, + "Body": body, + "Language": locale.Language(), + "Locale": locale, + "Str2html": templates.Str2html, } var mailBody bytes.Buffer diff --git a/services/mailer/mail_admin_new_user_test.go b/services/mailer/mail_admin_new_user_test.go index 9e88972ca6..be6ecd9791 100644 --- a/services/mailer/mail_admin_new_user_test.go +++ b/services/mailer/mail_admin_new_user_test.go @@ -57,8 +57,6 @@ func TestAdminNotificationMail_test(t *testing.T) { } setting.MailService = &mailService - setting.Domain = "localhost" - setting.AppSubURL = "http://localhost" // test with SEND_NOTIFICATION_EMAIL_ON_NEW_USER enabled setting.Admin.SendNotificationEmailOnNewUser = true @@ -77,8 +75,9 @@ func TestAdminNotificationMail_test(t *testing.T) { 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) + manageUserURL := setting.AppURL + "admin/users/" + strconv.FormatInt(users[1].ID, 10) assert.Contains(t, msgs[0].Body, manageUserURL) + assert.Contains(t, msgs[0].Body, users[1].HTMLURL()) assert.Contains(t, msgs[0].Body, translatedKey, "the .Locale translates to nothing") assert.Contains(t, msgs[0].Body, users[1].Name, "user name of the newly created user") for _, untranslated := range []string{"mail.admin", "admin.users"} { diff --git a/templates/mail/notify/admin_new_user.tmpl b/templates/mail/notify/admin_new_user.tmpl index 07e7a602b2..34d1584f60 100644 --- a/templates/mail/notify/admin_new_user.tmpl +++ b/templates/mail/notify/admin_new_user.tmpl @@ -13,7 +13,7 @@
    -

    {{.Locale.Tr "mail.admin.new_user.user_info" | Str2html}}: {{.NewUser.Name}}

    +

    {{.Locale.Tr "mail.admin.new_user.user_info" | Str2html}}: @{{.NewUser.Name}}

  • {{.Locale.Tr "admin.users.created" | Str2html}}: {{DateTime "full" .NewUser.CreatedUnix}}

{{.Body | Str2html}}