Commit 1b1494b5 authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'namespace-storage-notification-email' into 'master'

Add Mailer for Namespace Storage Limit Exceeded

See merge request gitlab-org/gitlab!82431
parents cc7aec8e 77bdc7c9
...@@ -87,5 +87,13 @@ module EE ...@@ -87,5 +87,13 @@ module EE
profile_usage_quotas_path(*args) profile_usage_quotas_path(*args)
end end
end end
def usage_quotas_url(namespace, *args)
if namespace.group_namespace?
group_usage_quotas_url(namespace, *args)
else
profile_usage_quotas_url(*args)
end
end
end end
end end
...@@ -55,6 +55,12 @@ module EE ...@@ -55,6 +55,12 @@ module EE
buy_storage_subscriptions_path(selected_group: namespace.id) buy_storage_subscriptions_path(selected_group: namespace.id)
end end
def buy_storage_url(namespace)
return EE::SUBSCRIPTIONS_MORE_STORAGE_URL if use_customers_dot_for_addon_path?(namespace)
buy_storage_subscriptions_url(selected_group: namespace.id)
end
private private
def use_customers_dot_for_addon_path?(namespace) def use_customers_dot_for_addon_path?(namespace)
......
# frozen_string_literal: true
module Emails
class NamespaceStorageUsageMailer < ApplicationMailer
include NamespacesHelper
include GitlabRoutingHelper
helper EmailsHelper
layout 'mailer'
def notify_out_of_storage(namespace, recipients)
@namespace = namespace
@usage_quotas_url = usage_quotas_url(namespace, anchor: 'storage-quota-tab')
@buy_storage_url = buy_storage_url(namespace)
mail(
bcc: recipients,
subject: s_("NamespaceStorage|Action required: Storage has been exceeded for %{namespace_name}" % { namespace_name: namespace.name })
)
end
def notify_limit_warning(namespace, recipients, percentage_of_available_storage)
@namespace = namespace
@usage_quotas_url = usage_quotas_url(namespace, anchor: 'storage-quota-tab')
@buy_storage_url = buy_storage_url(namespace)
@percentage_of_available_storage = percentage_of_available_storage
mail(
bcc: recipients,
subject: s_("NamespaceStorage|Action required: Less than %{percentage_of_available_storage}%% of namespace storage remains for %{namespace_name}" %
{ percentage_of_available_storage: percentage_of_available_storage, namespace_name: namespace.name })
)
end
end
end
# frozen_string_literal: true
module Emails
class NamespaceStorageUsageMailerPreview < ActionMailer::Preview
def out_of_storage
::Emails::NamespaceStorageUsageMailer.notify_out_of_storage(Group.last, %w(bob@example.com))
end
def limit_warning
::Emails::NamespaceStorageUsageMailer.notify_limit_warning(Group.last, %w(bob@example.com), 25)
end
end
end
%p
- name_link = link_to @namespace.name, @usage_quotas_url
= html_escape(s_('NamespaceStorage|%{name_with_link} namespace has %{percent} or less namespace storage space remaining.')) % { name_with_link: name_link.html_safe, percent: "#{@percentage_of_available_storage}%" }
%p
= s_('NamespaceStorage|We recommend that you buy additional storage to ensure your service is not interrupted.')
%p
= link_to sprintf('%{link_label} →', { link_label: s_('NamespaceStorage|Buy more storage') }), @buy_storage_url
<%= s_('NamespaceStorage|%{name}(%{url}) namespace has %{percent} or less namespace storage space remaining.') % { name: @namespace.name, url: @usage_quotas_url, percent: "#{@percentage_of_available_storage}%" }%>
<%= s_('NamespaceStorage|We recommend that you buy additional storage to ensure your service is not interrupted.') %>
<%= s_('NamespaceStorage|Buy more storage') %><%= @buy_storage_url %>
%p
- name_link = link_to @namespace.name, @usage_quotas_url
= html_escape(s_('NamespaceStorage|%{name_with_link} namespace has exceeded its namespace storage limit.')) % { name_with_link: name_link.html_safe }
%p
= s_('NamespaceStorage|We recommend that you buy additional storage to resume normal service.')
%p
= link_to sprintf('%{link_label} →', { link_label: s_('NamespaceStorage|Buy more storage') }), @buy_storage_url
<%= s_('NamespaceStorage|%{name}(%{url}) namespace has exceeded its namespace storage limit.') % { name: @namespace.name, url: @usage_quotas_url }%>
<%= s_('NamespaceStorage|We recommend that you buy additional storage to resume normal service.') %>
<%= s_('NamespaceStorage|Buy more storage') %><%= @buy_storage_url %>
...@@ -197,4 +197,24 @@ RSpec.describe EE::GitlabRoutingHelper do ...@@ -197,4 +197,24 @@ RSpec.describe EE::GitlabRoutingHelper do
expect(usage_quotas_path(namespace, foo: 'bar', anchor: 'quotas-tab')).to eq('/-/profile/usage_quotas?foo=bar#quotas-tab') expect(usage_quotas_path(namespace, foo: 'bar', anchor: 'quotas-tab')).to eq('/-/profile/usage_quotas?foo=bar#quotas-tab')
end end
end end
describe '#usage_quotas_url' do
it 'returns the group usage quota url for a group namespace' do
group = build(:group)
expect(usage_quotas_url(group)).to eq("http://test.host/groups/#{group.full_path}/-/usage_quotas")
end
it 'returns the profile usage quotas url for any other namespace' do
namespace = build(:namespace)
expect(usage_quotas_url(namespace)).to eq('http://test.host/-/profile/usage_quotas')
end
it 'returns the url with any args supplied' do
namespace = build(:namespace)
expect(usage_quotas_url(namespace, foo: 'bar', anchor: 'quotas-tab')).to eq('http://test.host/-/profile/usage_quotas?foo=bar#quotas-tab')
end
end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Emails::NamespaceStorageUsageMailer do
include EmailSpec::Matchers
let_it_be(:group) { create(:group) }
let_it_be(:namespace) { create(:namespace) }
let(:recipients) { %w(bob@example.com john@example.com) }
describe '#notify_out_of_storage' do
it 'creates an email message for a group' do
mail = described_class.notify_out_of_storage(group, recipients)
expect(mail).to have_subject "Action required: Storage has been exceeded for #{group.name}"
expect(mail).to bcc_to recipients
expect(mail).to have_body_text "#{usage_quotas_url(group, anchor: 'storage-quota-tab')}"
expect(mail).to have_body_text "has exceeded its namespace storage limit"
expect(mail).to have_body_text "#{buy_storage_subscriptions_url(selected_group: group.id)}"
end
it 'creates an email message for a namespace' do
mail = described_class.notify_out_of_storage(namespace, recipients)
expect(mail).to have_subject "Action required: Storage has been exceeded for #{namespace.name}"
expect(mail).to bcc_to recipients
expect(mail).to have_body_text "#{usage_quotas_url(namespace, anchor: 'storage-quota-tab')}"
expect(mail).to have_body_text "has exceeded its namespace storage limit"
expect(mail).to have_body_text EE::SUBSCRIPTIONS_MORE_STORAGE_URL
end
end
describe '#notify_limit_warning' do
it 'creates an email message for a group' do
mail = described_class.notify_limit_warning(group, recipients, 25)
expect(mail).to have_subject "Action required: Less than 25% of namespace storage remains for #{group.name}"
expect(mail).to bcc_to recipients
expect(mail).to have_body_text "#{usage_quotas_url(group, anchor: 'storage-quota-tab')}"
expect(mail).to have_body_text "has 25% or less namespace storage space remaining"
expect(mail).to have_body_text "#{buy_storage_subscriptions_url(selected_group: group.id)}"
end
it 'creates an email message for a namespace' do
mail = described_class.notify_limit_warning(namespace, recipients, 30)
expect(mail).to have_subject "Action required: Less than 30% of namespace storage remains for #{namespace.name}"
expect(mail).to bcc_to recipients
expect(mail).to have_body_text "#{usage_quotas_url(namespace, anchor: 'storage-quota-tab')}"
expect(mail).to have_body_text "has 30% or less namespace storage space remaining"
expect(mail).to have_body_text EE::SUBSCRIPTIONS_MORE_STORAGE_URL
end
end
end
...@@ -24176,6 +24176,33 @@ msgstr "" ...@@ -24176,6 +24176,33 @@ msgstr ""
msgid "NamespaceStorageSize|push to your repository, create pipelines, create issues or add comments. To reduce storage capacity, delete unused repositories, artifacts, wikis, issues, and pipelines." msgid "NamespaceStorageSize|push to your repository, create pipelines, create issues or add comments. To reduce storage capacity, delete unused repositories, artifacts, wikis, issues, and pipelines."
msgstr "" msgstr ""
msgid "NamespaceStorage|%{name_with_link} namespace has %{percent} or less namespace storage space remaining."
msgstr ""
msgid "NamespaceStorage|%{name_with_link} namespace has exceeded its namespace storage limit."
msgstr ""
msgid "NamespaceStorage|%{name}(%{url}) namespace has %{percent} or less namespace storage space remaining."
msgstr ""
msgid "NamespaceStorage|%{name}(%{url}) namespace has exceeded its namespace storage limit."
msgstr ""
msgid "NamespaceStorage|Action required: Less than %{percentage_of_available_storage}%% of namespace storage remains for %{namespace_name}"
msgstr ""
msgid "NamespaceStorage|Action required: Storage has been exceeded for %{namespace_name}"
msgstr ""
msgid "NamespaceStorage|Buy more storage"
msgstr ""
msgid "NamespaceStorage|We recommend that you buy additional storage to ensure your service is not interrupted."
msgstr ""
msgid "NamespaceStorage|We recommend that you buy additional storage to resume normal service."
msgstr ""
msgid "NamespaceUserCap|Pending users must be reviewed and approved by a group owner. Learn more about %{user_caps_link_start}user caps%{link_end} and %{users_pending_approval_link_start}users pending approval%{link_end}." msgid "NamespaceUserCap|Pending users must be reviewed and approved by a group owner. Learn more about %{user_caps_link_start}user caps%{link_end} and %{users_pending_approval_link_start}users pending approval%{link_end}."
msgstr "" msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment