Commit 60f50039 authored by Eugenia Grieff's avatar Eugenia Grieff

Add email notification

- Add mailer to notify user of imported
requirements
- Add email templates
- Add tests
parent 55d76ff9
......@@ -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
mail(to: @user.notification_email_for(@project.group), subject: subject('Imported requirements')) do |format|
format.html { render layout: 'mailer' }
format.text { render layout: 'mailer' }
end
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 #{'number'.pluralize(@results[:error_lines].size)}: #{@results[:error_lines].join(', ')}. Please check if these lines have a requirement title.
- if @results[:parse_error]
%p{ style: text_style }
= _('Error parsing CSV file. Please make sure it has the correct format: a delimited text file that uses a comma to separate values.')
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: a delimited text file that uses a comma to separate values.
<% end %>
---
title: Add service to import Requirements from a CSV file
merge_request: 46361
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(:user) { create(:user) }
let(:project) { create(:project) }
subject { Notify.import_requirements_csv_email(user.id, project.id, @results) }
it "shows number of successful requirements imported" do
@results = { success: 165, error_lines: [], parse_error: false }
expect(subject).to have_body_text "165 requirements imported"
end
it "shows error when file is invalid" do
@results = { success: 0, error_lines: [], parse_error: true }
expect(subject).to have_body_text "Error parsing CSV"
end
it "shows line numbers with errors" do
@results = { success: 0, error_lines: [23, 34, 58], parse_error: false }
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
......@@ -10649,6 +10649,9 @@ msgstr ""
msgid "Error occurred. User was not unlocked"
msgstr ""
msgid "Error parsing CSV file. Please make sure it has the correct format: a delimited text file that uses a comma to separate values."
msgstr ""
msgid "Error rendering markdown preview"
msgstr ""
......@@ -30848,6 +30851,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 ""
......@@ -31604,6 +31610,9 @@ msgstr ""
msgid "has already been taken"
msgstr ""
msgid "has been completed."
msgstr ""
msgid "help"
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