diff --git a/app/mailers/emails/admin_notification.rb b/app/mailers/emails/admin_notification.rb index f44dd448a35567904d03c70a5e3f0c8cde242ad3..9d02d4132a1403f196cb529ab9b3951597ff3f63 100644 --- a/app/mailers/emails/admin_notification.rb +++ b/app/mailers/emails/admin_notification.rb @@ -16,11 +16,16 @@ def send_unsubscribed_notification(user_id) mail to: email, subject: "Unsubscribed from GitLab administrator notifications" end - def user_auto_banned_email(admin_id, user_id, max_project_downloads:, within_seconds:) + def user_auto_banned_email(admin_id, user_id, max_project_downloads:, within_seconds:, group: nil) admin = User.find(admin_id) @user = User.find(user_id) @max_project_downloads = max_project_downloads @within_minutes = within_seconds / 60 + @ban_scope = if group.present? + _('your group (%{group_name})' % { group_name: group.name }) + else + _('your GitLab instance') + end Gitlab::I18n.with_locale(admin.preferred_language) do email_with_layout( diff --git a/app/mailers/previews/notify_preview.rb b/app/mailers/previews/notify_preview.rb index 61456ef79c82b7b754c7ff6ba238d506d78af379..074aec54b1057cff3f7d36af892fe2604caf339e 100644 --- a/app/mailers/previews/notify_preview.rb +++ b/app/mailers/previews/notify_preview.rb @@ -205,10 +205,14 @@ def inactive_project_deletion_warning Notify.inactive_project_deletion_warning_email(project, user, '2022-04-22').message end - def user_auto_banned_email + def user_auto_banned_instance_email ::Notify.user_auto_banned_email(user.id, user.id, max_project_downloads: 5, within_seconds: 600).message end + def user_auto_banned_namespace_email + ::Notify.user_auto_banned_email(user.id, user.id, max_project_downloads: 5, within_seconds: 600, group: group).message + end + private def project @@ -239,6 +243,10 @@ def user @user ||= User.last end + def group + @group ||= Group.last + end + def member @member ||= Member.last end diff --git a/app/views/notify/user_auto_banned_email.html.haml b/app/views/notify/user_auto_banned_email.html.haml index d88c06526eb918e69b83565a266725812b2bd2f5..8c33cd7299db996be99476b4088e8148d45c03a0 100644 --- a/app/views/notify/user_auto_banned_email.html.haml +++ b/app/views/notify/user_auto_banned_email.html.haml @@ -2,7 +2,7 @@ - link_end = '</a>'.html_safe = email_default_heading(_("We've detected some unusual activity")) %p - = _('We want to let you know %{username} has been banned from your GitLab instance due to them downloading more than %{max_project_downloads} project repositories within %{within_minutes} minutes.') % { username: sanitize_name(@user.name), max_project_downloads: @max_project_downloads, within_minutes: @within_minutes } + = _('We want to let you know %{username} has been banned from %{scope} due to them downloading more than %{max_project_downloads} project repositories within %{within_minutes} minutes.') % { username: sanitize_name(@user.name), max_project_downloads: @max_project_downloads, within_minutes: @within_minutes, scope: @ban_scope } %p = _('If this is a mistake, you can %{link_start}unban them%{link_end}.').html_safe % { link_start: link_start % { url: admin_users_url(filter: 'banned') }, link_end: link_end } %p diff --git a/app/views/notify/user_auto_banned_email.text.erb b/app/views/notify/user_auto_banned_email.text.erb index 0469ee9788ce0a8aa48bf62c4dc04b019ef7e194..336973c2e42e0b904c7d8534c0d1a16b612d6ec9 100644 --- a/app/views/notify/user_auto_banned_email.text.erb +++ b/app/views/notify/user_auto_banned_email.text.erb @@ -1,6 +1,6 @@ <%= _("We've detected some unusual activity") %> -<%= _('We want to let you know %{username} has been banned from your GitLab instance due to them downloading more than %{max_project_downloads} project repositories within %{within_minutes} minutes.') % { username: sanitize_name(@user.name), max_project_downloads: @max_project_downloads, within_minutes: @within_minutes } %> +<%= _('We want to let you know %{username} has been banned from %{scope} due to them downloading more than %{max_project_downloads} project repositories within %{within_minutes} minutes.') % { username: sanitize_name(@user.name), max_project_downloads: @max_project_downloads, within_minutes: @within_minutes, scope: @ban_scope } %> <%= _('If this is a mistake, you can unban them: %{url}.') % { url: admin_users_url(filter: 'banned') } %> diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 1e1307276fed21d3675411f337b2376f6922cc6d..0c0a2e06dd49536fc8f5fcb0298e0d21d30c7316 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -42964,7 +42964,7 @@ msgstr "" msgid "We want to be sure it is you, please confirm you are not a robot." msgstr "" -msgid "We want to let you know %{username} has been banned from your GitLab instance due to them downloading more than %{max_project_downloads} project repositories within %{within_minutes} minutes." +msgid "We want to let you know %{username} has been banned from %{scope} due to them downloading more than %{max_project_downloads} project repositories within %{within_minutes} minutes." msgstr "" msgid "We will notify %{inviter} that you declined their invitation to join GitLab. You will stop receiving reminders." @@ -46710,6 +46710,12 @@ msgstr "" msgid "yaml invalid" msgstr "" +msgid "your GitLab instance" +msgstr "" + +msgid "your group (%{group_name})" +msgstr "" + msgid "your settings" msgstr "" diff --git a/spec/mailers/emails/admin_notification_spec.rb b/spec/mailers/emails/admin_notification_spec.rb index a233be86a83dce1bf03b8c3b8a7a3735c40824c2..bfd07f1d4389f0b1f428c9d3e1b07908f3a7bc92 100644 --- a/spec/mailers/emails/admin_notification_spec.rb +++ b/spec/mailers/emails/admin_notification_spec.rb @@ -18,12 +18,14 @@ let(:max_project_downloads) { 5 } let(:time_period) { 600 } + let(:group) { nil } subject do Notify.user_auto_banned_email( admin.id, user.id, max_project_downloads: max_project_downloads, - within_seconds: time_period + within_seconds: time_period, + group: group ) end @@ -45,6 +47,10 @@ is_expected.to have_body_text user.name end + it 'includes the scope of the ban' do + is_expected.to have_body_text "banned from your GitLab instance" + end + it 'includes the reason' do is_expected.to have_body_text "due to them downloading more than 5 project repositories within 10 minutes" end @@ -60,5 +66,13 @@ it 'includes the email reason' do is_expected.to have_body_text "You're receiving this email because of your account on localhost" end + + context 'when scoped to a group' do + let(:group) { create(:group) } + + it 'includes the scope of the ban' do + is_expected.to have_body_text "banned from your group (#{group.name})" + end + end end end