Commit 378536cc authored by Max Woolf's avatar Max Woolf

Add CredentialsInventoryMailer and Emails

Adds a new mailer for actions
performed within the Credentials Inventory.

Additionally adds 2 new emails that will
be triggered (later) when:

SSH Key is deleted or
PAT is revoked.
parent 98c02d63
# frozen_string_literal: true
class CredentialsInventoryMailer < ApplicationMailer
helper EmailsHelper
layout 'mailer'
def personal_access_token_revoked_email(token:, revoked_by:)
@revoked_by = revoked_by
@token = token
mail(
to: token.user.notification_email,
subject: _('Your Personal Access Token was revoked')
)
end
def ssh_key_deleted_email(key:, deleted_by:)
@deleted_by = deleted_by
@key = key
mail(
to: key.user.notification_email,
subject: _('Your SSH key was deleted')
)
end
end
%p
= _("The following Personal Access Token was revoked by an administrator, %{username}.") % { username: @revoked_by.username }
%ul
%li
= @token.name
%li
= _("Created on %{created_at}") % { created_at: @token.created_at.to_date.to_s(:medium) }
- if @token.last_used_at
%li
= _("Last used %{last_used_at} ago") % { last_used_at: time_ago_in_words(@token.last_used_at) }
%li
= _("Scopes: %{scope_list}") % { scope_list: @token.scopes.join(', ') }
%p
= html_escape(_("You can create a new %{link}.")) % { link: link_to(_('Personal Access Token'), profile_personal_access_tokens_url.html_safe) }
= _("The following Personal Access Token was revoked by an administrator, %{username}.") % { username: @revoked_by.username }
= @token.name
= _("Created on %{created_at}") % { created_at: @token.created_at.to_date.to_s(:medium) }
- if @token.last_used_at
= _("Last used %{last_used_at} ago") % { last_used_at: time_ago_in_words(@token.last_used_at) }
= _("Scopes: %{scope_list}") % { scope_list: @token.scopes.join(', ') }
= html_escape(_("You can create a new Personal Access Token by visiting %{link}")) % { link: profile_personal_access_tokens_url.html_safe }
%p
= _("The following SSH key was deleted by an administrator, %{username}.") % { username: @deleted_by.username }
%ul
%li
= @key.title
%li
= _("Created on %{created_at}") % { created_at: @key.created_at.to_date.to_s(:medium) }
- if @key.last_used_at
%li
= _("Last used %{last_used_at} ago") % { last_used_at: time_ago_in_words(@key.last_used_at) }
%p
= html_escape(_("You can create a new %{link}.")) % { link: link_to(_('SSH key'), profile_keys_url.html_safe) }
= _("The following SSH key was deleted by an administrator, %{username}.") % { username: @deleted_by.username }
= @key.title
= _("Created on %{created_at}") % { created_at: @key.created_at.to_date.to_s(:medium) }
- if @key.last_used_at
= _("Last used %{last_used_at} ago") % { last_used_at: time_ago_in_words(@key.last_used_at) }
= html_escape(_("You can create a new SSH key by visiting %{link}")) % { link: profile_keys_url.html_safe }
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe CredentialsInventoryMailer do
include EmailSpec::Matchers
let_it_be(:administrator) { create(:user, :admin, username: 'Revoker') }
describe '#personal_access_token_revoked_email' do
let_it_be(:token) { create(:personal_access_token, scopes: %w(api sudo), last_used_at: 3.weeks.ago) }
subject(:email) { described_class.personal_access_token_revoked_email(token: token, revoked_by: administrator) }
it { is_expected.to have_subject 'Your Personal Access Token was revoked' }
it { is_expected.to have_body_text 'The following Personal Access Token was revoked by an administrator, Revoker' }
it { is_expected.to have_body_text token.name }
it { is_expected.to have_body_text "Created on #{token.created_at.to_date.to_s(:medium)}" }
it { is_expected.to have_body_text 'Scopes: api, sudo'}
it { is_expected.to be_delivered_to [token.user.notification_email] }
it { is_expected.to have_body_text 'Last used 21 days ago' }
end
describe '#ssh_key_deleted_email' do
let_it_be(:ssh_key) { create(:personal_key, last_used_at: 3.weeks.ago) }
subject(:email) { described_class.ssh_key_deleted_email(key: ssh_key, deleted_by: administrator) }
it { is_expected.to have_subject 'Your SSH key was deleted' }
it { is_expected.to have_body_text 'The following SSH key was deleted by an administrator, Revoker' }
it { is_expected.to be_delivered_to [ssh_key.user.notification_email] }
it { is_expected.to have_body_text ssh_key.title }
it { is_expected.to have_body_text "Created on #{ssh_key.created_at.to_date.to_s(:medium)}" }
it { is_expected.to have_body_text 'Last used 21 days ago' }
end
end
......@@ -7800,6 +7800,9 @@ msgstr ""
msgid "Created on"
msgstr ""
msgid "Created on %{created_at}"
msgstr ""
msgid "Created on:"
msgstr ""
......@@ -15282,6 +15285,9 @@ msgstr ""
msgid "Last used"
msgstr ""
msgid "Last used %{last_used_at} ago"
msgstr ""
msgid "Last used on:"
msgstr ""
......@@ -22875,6 +22881,9 @@ msgstr ""
msgid "SSH host keys are not available on this system. Please use %{ssh_keyscan} command or contact your GitLab administrator for more information."
msgstr ""
msgid "SSH key"
msgstr ""
msgid "SSH keys allow you to establish a secure connection between your computer and GitLab."
msgstr ""
......@@ -22983,6 +22992,9 @@ msgstr ""
msgid "Scopes can't be blank"
msgstr ""
msgid "Scopes: %{scope_list}"
msgstr ""
msgid "Score"
msgstr ""
......@@ -26169,6 +26181,12 @@ msgstr ""
msgid "The following %{user} can also push to this branch: %{branch}"
msgstr ""
msgid "The following Personal Access Token was revoked by an administrator, %{username}."
msgstr ""
msgid "The following SSH key was deleted by an administrator, %{username}."
msgstr ""
msgid "The following items will NOT be exported:"
msgstr ""
......@@ -30063,6 +30081,15 @@ msgstr ""
msgid "You can always edit this later"
msgstr ""
msgid "You can create a new %{link}."
msgstr ""
msgid "You can create a new Personal Access Token by visiting %{link}"
msgstr ""
msgid "You can create a new SSH key by visiting %{link}"
msgstr ""
msgid "You can create a new one or check them in your %{pat_link_start}personal access tokens%{pat_link_end} settings"
msgstr ""
......@@ -30504,6 +30531,9 @@ msgstr ""
msgid "Your License"
msgstr ""
msgid "Your Personal Access Token was revoked"
msgstr ""
msgid "Your Personal Access Tokens will expire in %{days_to_expire} days or less"
msgstr ""
......@@ -30519,6 +30549,9 @@ msgstr ""
msgid "Your Public Email will be displayed on your public profile."
msgstr ""
msgid "Your SSH key was deleted"
msgstr ""
msgid "Your SSH keys (%{count})"
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