Commit 0c5e65ae authored by Eugenia Grieff's avatar Eugenia Grieff

Remove notification email

- Move code that adds a mailer to notify user of
import result a new MR
parent 63752fe3
...@@ -60,8 +60,6 @@ module Issuable ...@@ -60,8 +60,6 @@ module Issuable
# defined in ImportCsvService # defined in ImportCsvService
end end
private
def issuable(attributes) def issuable(attributes)
create_issuable_class.new(@project, @user, attributes).execute create_issuable_class.new(@project, @user, attributes).execute
end end
......
...@@ -11,7 +11,6 @@ module EE ...@@ -11,7 +11,6 @@ module EE
prepended do prepended do
include ::Emails::AdminNotification include ::Emails::AdminNotification
include ::Emails::Epics include ::Emails::Epics
include ::Emails::Requirements
end end
attr_reader :group attr_reader :group
......
...@@ -39,10 +39,6 @@ module EE ...@@ -39,10 +39,6 @@ module EE
def send_unsubscribed_notification def send_unsubscribed_notification
::Notify.send_unsubscribed_notification(user.id).message ::Notify.send_unsubscribed_notification(user.id).message
end 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 end
private 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
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
module RequirementsManagement module RequirementsManagement
class ImportCsvService < ::Issuable::ImportCsv::BaseService class ImportCsvService < ::Issuable::ImportCsv::BaseService
def email_results_to_user
Notify.import_requirements_csv_email(@user.id, @project.id, @results).deliver_later
end
private private
def create_issuable_class def create_issuable_class
......
- 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 %>
# 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
...@@ -13,23 +13,41 @@ RSpec.describe RequirementsManagement::ImportCsvService do ...@@ -13,23 +13,41 @@ RSpec.describe RequirementsManagement::ImportCsvService do
described_class.new(user, project, uploader).execute described_class.new(user, project, uploader).execute
end end
context 'when user can create requirements' do shared_examples 'resource not available' do
it 'raises an error' do
expect { service }.to raise_error(Gitlab::Access::AccessDeniedError)
end
end
before do before do
project.add_reporter(user) project.add_reporter(user)
stub_licensed_features(requirements: true) stub_licensed_features(requirements: true)
end end
context 'when user can create requirements' do
include_examples 'issuable import csv service', 'requirement' do include_examples 'issuable import csv service', 'requirement' do
let(:issuables) { project.requirements } let(:issuables) { project.requirements }
let(:email_method) { :import_requirements_csv_email } let(:email_method) { nil }
end end
end end
context 'when user cannot create requirements' do context 'when user cannot create requirements' do
let(:file) { fixture_file_upload('spec/fixtures/csv_comma.csv') } let(:file) { fixture_file_upload('spec/fixtures/csv_comma.csv') }
it 'raises an exception' do before do
expect { service }.to raise_error(Gitlab::Access::AccessDeniedError) project.add_guest(user)
end end
it_behaves_like 'resource not available'
end
context 'when requirements feature is not available' do
let(:file) { fixture_file_upload('spec/fixtures/csv_comma.csv') }
before do
stub_licensed_features(requirements: false)
end
it_behaves_like 'resource not available'
end end
end end
...@@ -10649,9 +10649,6 @@ msgstr "" ...@@ -10649,9 +10649,6 @@ msgstr ""
msgid "Error occurred. User was not unlocked" msgid "Error occurred. User was not unlocked"
msgstr "" 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" msgid "Error rendering markdown preview"
msgstr "" msgstr ""
...@@ -30851,9 +30848,6 @@ msgstr "" ...@@ -30851,9 +30848,6 @@ msgstr ""
msgid "Your CSV export of %{written_count} from project %{project_name} (%{project_url}) has been added to this email as an attachment." msgid "Your CSV export of %{written_count} from project %{project_name} (%{project_url}) has been added to this email as an attachment."
msgstr "" msgstr ""
msgid "Your CSV import for project"
msgstr ""
msgid "Your Commit Email will be used for web based operations, such as edits and merges." msgid "Your Commit Email will be used for web based operations, such as edits and merges."
msgstr "" msgstr ""
...@@ -31610,9 +31604,6 @@ msgstr "" ...@@ -31610,9 +31604,6 @@ msgstr ""
msgid "has already been taken" msgid "has already been taken"
msgstr "" msgstr ""
msgid "has been completed."
msgstr ""
msgid "help" msgid "help"
msgstr "" msgstr ""
......
...@@ -18,17 +18,26 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type| ...@@ -18,17 +18,26 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
end end
end end
shared_examples_for 'importer with email notification' do
it 'notifies user of import result' do
if issuable_type == 'issue'
expect(Notify).to receive_message_chain(email_method, :deliver_later)
subject
end
end
end
describe '#execute' do describe '#execute' do
context 'invalid file' do context 'invalid file' do
let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') } let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') }
it 'returns invalid file error' do it 'returns invalid file error' do
expect(Notify).to receive_message_chain(email_method, :deliver_later)
expect(subject[:success]).to eq(0) expect(subject[:success]).to eq(0)
expect(subject[:parse_error]).to eq(true) expect(subject[:parse_error]).to eq(true)
end end
it_behaves_like 'importer with email notification'
it_behaves_like 'an issuable importer' it_behaves_like 'an issuable importer'
end end
...@@ -36,8 +45,6 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type| ...@@ -36,8 +45,6 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
let(:file) { fixture_file_upload('spec/fixtures/csv_gitlab_export.csv') } let(:file) { fixture_file_upload('spec/fixtures/csv_gitlab_export.csv') }
it 'imports the CSV without errors' do it 'imports the CSV without errors' do
expect(Notify).to receive_message_chain(email_method, :deliver_later)
expect(subject[:success]).to eq(4) expect(subject[:success]).to eq(4)
expect(subject[:error_lines]).to eq([]) expect(subject[:error_lines]).to eq([])
expect(subject[:parse_error]).to eq(false) expect(subject[:parse_error]).to eq(false)
...@@ -52,6 +59,7 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type| ...@@ -52,6 +59,7 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
) )
end end
it_behaves_like 'importer with email notification'
it_behaves_like 'an issuable importer' it_behaves_like 'an issuable importer'
end end
...@@ -59,8 +67,6 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type| ...@@ -59,8 +67,6 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
let(:file) { fixture_file_upload('spec/fixtures/csv_comma.csv') } let(:file) { fixture_file_upload('spec/fixtures/csv_comma.csv') }
it 'imports CSV without errors' do it 'imports CSV without errors' do
expect(Notify).to receive_message_chain(email_method, :deliver_later)
expect(subject[:success]).to eq(3) expect(subject[:success]).to eq(3)
expect(subject[:error_lines]).to eq([]) expect(subject[:error_lines]).to eq([])
expect(subject[:parse_error]).to eq(false) expect(subject[:parse_error]).to eq(false)
...@@ -75,6 +81,7 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type| ...@@ -75,6 +81,7 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
) )
end end
it_behaves_like 'importer with email notification'
it_behaves_like 'an issuable importer' it_behaves_like 'an issuable importer'
end end
...@@ -82,8 +89,6 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type| ...@@ -82,8 +89,6 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
let(:file) { fixture_file_upload('spec/fixtures/csv_tab.csv') } let(:file) { fixture_file_upload('spec/fixtures/csv_tab.csv') }
it 'imports CSV with some error rows' do it 'imports CSV with some error rows' do
expect(Notify).to receive_message_chain(email_method, :deliver_later)
expect(subject[:success]).to eq(2) expect(subject[:success]).to eq(2)
expect(subject[:error_lines]).to eq([3]) expect(subject[:error_lines]).to eq([3])
expect(subject[:parse_error]).to eq(false) expect(subject[:parse_error]).to eq(false)
...@@ -98,6 +103,7 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type| ...@@ -98,6 +103,7 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
) )
end end
it_behaves_like 'importer with email notification'
it_behaves_like 'an issuable importer' it_behaves_like 'an issuable importer'
end end
...@@ -105,8 +111,6 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type| ...@@ -105,8 +111,6 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
let(:file) { fixture_file_upload('spec/fixtures/csv_semicolon.csv') } let(:file) { fixture_file_upload('spec/fixtures/csv_semicolon.csv') }
it 'imports CSV with a blank row' do it 'imports CSV with a blank row' do
expect(Notify).to receive_message_chain(email_method, :deliver_later)
expect(subject[:success]).to eq(3) expect(subject[:success]).to eq(3)
expect(subject[:error_lines]).to eq([4]) expect(subject[:error_lines]).to eq([4])
expect(subject[:parse_error]).to eq(false) expect(subject[:parse_error]).to eq(false)
...@@ -121,6 +125,7 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type| ...@@ -121,6 +125,7 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
) )
end end
it_behaves_like 'importer with email notification'
it_behaves_like 'an issuable importer' it_behaves_like 'an issuable importer'
end end
end end
......
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