Skip to content
代码片段 群组 项目
提交 6936d94e 编辑于 作者: eugielimpin's avatar eugielimpin 提交者: Albert Salim
浏览文件

Update user_auto_banned_email to scope the email to a group

For SaaS, we auto-ban a user in a group when they exceed unique
project download limit set for that namespace. This version of
user_auto_banned_email (with group passed in) will be sent to group
owners when that happens.
上级 0da5ff0b
No related branches found
No related tags found
无相关合并请求
......@@ -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(
......
......@@ -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
......
......@@ -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
......
<%= _("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') } %>
......
......@@ -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 ""
 
......@@ -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
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册