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

Fix URLs in `user_auto_banned_email`

Fix `user_auto_banned_email` to have the correct URLs to pages where:

- the admin can unban banned users
- the admin can update settings for auto-banning

The URLs depend on whether the user is banned from an instance or from
a namespace.

Changelog: fixed
EE: true
上级 8f3b1def
No related branches found
No related tags found
无相关合并请求
...@@ -15,23 +15,7 @@ def send_unsubscribed_notification(user_id) ...@@ -15,23 +15,7 @@ def send_unsubscribed_notification(user_id)
email = user.notification_email_or_default email = user.notification_email_or_default
mail to: email, subject: "Unsubscribed from GitLab administrator notifications" mail to: email, subject: "Unsubscribed from GitLab administrator notifications"
end end
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(
to: admin.notification_email_or_default,
subject: subject(_("We've detected unusual activity")))
end
end
end end
end end
Emails::AdminNotification.prepend_mod
# frozen_string_literal: true
module EE
module Emails
module AdminNotification
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
if group.present?
@ban_scope = _('your group (%{group_name})' % { group_name: group.name })
@settings_page_url = group_settings_reporting_url(group)
@banned_page_url = group_group_members_url(group, tab: 'banned')
else
@ban_scope = _('your GitLab instance')
@settings_page_url = reporting_admin_application_settings_url
@banned_page_url = admin_users_url(filter: 'banned')
end
::Gitlab::I18n.with_locale(admin.preferred_language) do
email_with_layout(
to: admin.notification_email_or_default,
subject: subject(_("We've detected unusual activity")))
end
end
end
end
end
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
%p %p
= _('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 } = _('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 %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 } = _('If this is a mistake, you can %{link_start}unban them%{link_end}.').html_safe % { link_start: link_start % { url: @banned_page_url }, link_end: link_end }
%p %p
= _('You can adjust rules on auto-banning %{link_start}here%{link_end}.').html_safe % { link_start: link_start % { url: network_admin_application_settings_url(anchor: 'js-ip-limits-settings') }, link_end: link_end } = _('You can adjust rules on auto-banning %{link_start}here%{link_end}.').html_safe % { link_start: link_start % { url: @settings_page_url }, link_end: link_end }
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
<%= _('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 } %> <%= _('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') } %> <%= _('If this is a mistake, you can unban them: %{url}.') % { url: @banned_page_url } %>
<%= _('You can adjust rules on auto-banning here: %{url}.') % { url: network_admin_application_settings_url(anchor: 'js-ip-limits-settings') } %> <%= _('You can adjust rules on auto-banning here: %{url}.') % { url: @settings_page_url } %>
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Emails::AdminNotification do
include EmailSpec::Matchers
include_context 'gitlab email notification'
describe 'user_auto_banned_email' do
let_it_be(:admin) { create(:user) }
let_it_be(:user) { create(:user) }
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,
group: group
)
end
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like 'a user cannot unsubscribe through footer link'
it_behaves_like 'appearance header and footer enabled'
it_behaves_like 'appearance header and footer not enabled'
it 'is sent to the administrator' do
is_expected.to deliver_to admin.email
end
it 'has the correct subject' do
is_expected.to have_subject "We've detected unusual activity"
end
it 'includes the name of the user' do
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
it 'includes a link to unban the user' do
is_expected.to have_body_text admin_users_url(filter: 'banned')
end
it 'includes a link to change the settings' do
is_expected.to have_body_text reporting_admin_application_settings_url
end
it 'includes the email reason' do
is_expected.to have_body_text %r{You're receiving this email because of your account on <a .*>localhost<\/a>}
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
it 'includes a link to unban the user' do
is_expected.to have_body_text group_group_members_url(group, tab: 'banned')
end
it 'includes a link to change the settings' do
is_expected.to have_body_text group_settings_reporting_url(group)
end
end
end
end
...@@ -11,68 +11,4 @@ ...@@ -11,68 +11,4 @@
expect(Notify).to be_respond_to(email_method) expect(Notify).to be_respond_to(email_method)
end end
end end
describe 'user_auto_banned_email' do
let_it_be(:admin) { create(:user) }
let_it_be(:user) { create(:user) }
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,
group: group
)
end
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like 'a user cannot unsubscribe through footer link'
it_behaves_like 'appearance header and footer enabled'
it_behaves_like 'appearance header and footer not enabled'
it 'is sent to the administrator' do
is_expected.to deliver_to admin.email
end
it 'has the correct subject' do
is_expected.to have_subject "We've detected unusual activity"
end
it 'includes the name of the user' do
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
it 'includes a link to unban the user' do
is_expected.to have_body_text admin_users_url(filter: 'banned')
end
it 'includes a link to change the settings' do
is_expected.to have_body_text network_admin_application_settings_url(anchor: 'js-ip-limits-settings')
end
it 'includes the email reason' do
is_expected.to have_body_text %r{You're receiving this email because of your account on <a .*>localhost<\/a>}
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 end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册