Commit 2ae93baa authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch '246857-requirements-management-import-csv-email-notification' into 'master'

Add email notifications for CSV requirements import

See merge request gitlab-org/gitlab!46484
parents 8bb137a9 33acb7a2
......@@ -11,6 +11,7 @@ module EE
prepended do
include ::Emails::AdminNotification
include ::Emails::Epics
include ::Emails::Requirements
end
attr_reader :group
......
......@@ -39,6 +39,10 @@ module EE
def send_unsubscribed_notification
::Notify.send_unsubscribed_notification(user.id).message
end
def import_requirements_csv_email
Notify.import_requirements_csv_email(user.id, project.id, { success: 3, errors: [5, 6, 7], valid_file: true })
end
end
private
......
# frozen_string_literal: true
module Emails
module Requirements
def import_requirements_csv_email(user_id, project_id, results)
@user = User.find(user_id)
@project = Project.find(project_id)
@results = results
requirement_email_with_layout(@user, @project.group, _('Imported requirements'))
end
def requirement_email_with_layout(user, group, subj)
mail(to: user.notification_email_for(group), subject: subject(subj)) do |format|
format.html { render layout: 'mailer' }
format.text { render layout: 'mailer' }
end
end
end
end
......@@ -7,5 +7,9 @@ module RequirementsManagement
def create_issuable_class
RequirementsManagement::CreateRequirementService
end
def email_results_to_user
Notify.import_requirements_csv_email(@user.id, @project.id, @results).deliver_later
end
end
end
- text_style = 'font-size:16px; text-align:center; line-height:30px;'
%p{ style: text_style }
= _('Your CSV import for project')
%a{ href: project_url(@project), style: "color:#3777b0; text-decoration:none;" }
= @project.full_name
= _('has been completed.')
%p{ style: text_style }
#{pluralize(@results[:success], 'requirement')} imported.
- if @results[:error_lines].present?
%p{ style: text_style }
= _('Errors found on line %{line_number}: %{error_lines}. Please check if these lines have a requirement title.') % { line_number: 'number'.pluralize(@results[:error_lines].size), error_lines: @results[:error_lines].join(', ') }
- if @results[:parse_error]
%p{ style: text_style }
= _('Error parsing CSV file. Please make sure it has')
%a{ href: help_page_url('user/project/issues/csv_import', anchor: 'csv-file-format') }
= _('the correct format.')
Your CSV import for project <%= @project.full_name %> (<%= project_url(@project) %>) has been completed.
<%= pluralize(@results[:success], 'requirement') %> imported.
<% if @results[:error_lines].present? %>
Errors found on line <%= 'number'.pluralize(@results[:error_lines].size) %>: <%= @results[:error_lines].join(', ') %>. Please check if these lines have a requirement title.
<% end %>
<% if @results[:parse_error] %>
Error parsing CSV file. Please make sure it has the correct format (<%= help_page_url('user/project/issues/csv_import', anchor: 'csv-file-format') %>).
<% end %>
---
title: Add email notification to notify result of CSV requirements import
merge_request: 46484
author:
type: added
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Emails::Requirements do
include EmailSpec::Matchers
describe "#import_requirements_csv_email" do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let(:results) { { success: 0, error_lines: [], parse_error: false } }
subject { Notify.import_requirements_csv_email(user.id, project.id, results) }
it "shows number of successful requirements imported" do
results[:success] = 165
expect(subject).to have_body_text "165 requirements imported"
end
it "shows error when file is invalid" do
results[:parse_error] = true
expect(subject).to have_body_text "Error parsing CSV"
end
it "shows line numbers with errors" do
results[:error_lines] = [23, 34, 58]
expect(subject).to have_body_text "23, 34, 58"
end
context 'with header and footer' do
let(:results) { { success: 165, error_lines: [], parse_error: false } }
subject { Notify.import_requirements_csv_email(user.id, project.id, results) }
it_behaves_like 'appearance header and footer enabled'
it_behaves_like 'appearance header and footer not enabled'
end
end
end
......@@ -27,7 +27,7 @@ RSpec.describe RequirementsManagement::ImportCsvService do
context 'when user can create requirements' do
include_examples 'issuable import csv service', 'requirement' do
let(:issuables) { project.requirements }
let(:email_method) { nil }
let(:email_method) { :import_requirements_csv_email }
end
end
......
......@@ -10842,6 +10842,9 @@ msgstr ""
msgid "Error occurred. User was not unlocked"
msgstr ""
msgid "Error parsing CSV file. Please make sure it has"
msgstr ""
msgid "Error rendering markdown preview"
msgstr ""
......@@ -10920,6 +10923,9 @@ msgstr ""
msgid "Errors"
msgstr ""
msgid "Errors found on line %{line_number}: %{error_lines}. Please check if these lines have a requirement title."
msgstr ""
msgid "Errors:"
msgstr ""
......@@ -14163,6 +14169,9 @@ msgstr ""
msgid "ImportProjects|Update of imported projects with realtime changes failed"
msgstr ""
msgid "Imported requirements"
msgstr ""
msgid "Improve Issue Boards"
msgstr ""
......@@ -31214,6 +31223,9 @@ msgstr ""
msgid "Your CSV export of %{written_count} from project %{project_name} (%{project_url}) has been added to this email as an attachment."
msgstr ""
msgid "Your CSV import for project"
msgstr ""
msgid "Your Commit Email will be used for web based operations, such as edits and merges."
msgstr ""
......@@ -31979,6 +31991,9 @@ msgstr ""
msgid "has already been taken"
msgstr ""
msgid "has been completed."
msgstr ""
msgid "help"
msgstr ""
......@@ -32815,6 +32830,9 @@ msgstr ""
msgid "teammate%{number}@company.com"
msgstr ""
msgid "the correct format."
msgstr ""
msgid "the following issue(s)"
msgstr ""
......
......@@ -19,14 +19,12 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
end
shared_examples_for 'importer with email notification' do
if issuable_type == 'issue'
it 'notifies user of import result' do
expect(Notify).to receive_message_chain(email_method, :deliver_later)
subject
end
end
end
describe '#execute' do
context 'invalid file' do
......
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