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
# defined in ImportCsvService
end
private
def issuable(attributes)
create_issuable_class.new(@project, @user, attributes).execute
end
......
......@@ -11,7 +11,6 @@ module EE
prepended do
include ::Emails::AdminNotification
include ::Emails::Epics
include ::Emails::Requirements
end
attr_reader :group
......
......@@ -39,10 +39,6 @@ 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
......@@ -2,10 +2,6 @@
module RequirementsManagement
class ImportCsvService < ::Issuable::ImportCsv::BaseService
def email_results_to_user
Notify.import_requirements_csv_email(@user.id, @project.id, @results).deliver_later
end
private
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
described_class.new(user, project, uploader).execute
end
context 'when user can create requirements' do
before do
project.add_reporter(user)
stub_licensed_features(requirements: true)
shared_examples 'resource not available' do
it 'raises an error' do
expect { service }.to raise_error(Gitlab::Access::AccessDeniedError)
end
end
before do
project.add_reporter(user)
stub_licensed_features(requirements: true)
end
context 'when user can create requirements' do
include_examples 'issuable import csv service', 'requirement' do
let(:issuables) { project.requirements }
let(:email_method) { :import_requirements_csv_email }
let(:email_method) { nil }
end
end
context 'when user cannot create requirements' do
let(:file) { fixture_file_upload('spec/fixtures/csv_comma.csv') }
it 'raises an exception' do
expect { service }.to raise_error(Gitlab::Access::AccessDeniedError)
before do
project.add_guest(user)
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
......@@ -10649,9 +10649,6 @@ 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 ""
......@@ -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."
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 ""
......@@ -31610,9 +31604,6 @@ msgstr ""
msgid "has already been taken"
msgstr ""
msgid "has been completed."
msgstr ""
msgid "help"
msgstr ""
......
......@@ -18,17 +18,26 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
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
context 'invalid file' do
let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') }
it 'returns invalid file error' do
expect(Notify).to receive_message_chain(email_method, :deliver_later)
expect(subject[:success]).to eq(0)
expect(subject[:parse_error]).to eq(true)
end
it_behaves_like 'importer with email notification'
it_behaves_like 'an issuable importer'
end
......@@ -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') }
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[:error_lines]).to eq([])
expect(subject[:parse_error]).to eq(false)
......@@ -52,6 +59,7 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
)
end
it_behaves_like 'importer with email notification'
it_behaves_like 'an issuable importer'
end
......@@ -59,8 +67,6 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
let(:file) { fixture_file_upload('spec/fixtures/csv_comma.csv') }
it 'imports CSV without errors' do
expect(Notify).to receive_message_chain(email_method, :deliver_later)
expect(subject[:success]).to eq(3)
expect(subject[:error_lines]).to eq([])
expect(subject[:parse_error]).to eq(false)
......@@ -75,6 +81,7 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
)
end
it_behaves_like 'importer with email notification'
it_behaves_like 'an issuable importer'
end
......@@ -82,8 +89,6 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
let(:file) { fixture_file_upload('spec/fixtures/csv_tab.csv') }
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[:error_lines]).to eq([3])
expect(subject[:parse_error]).to eq(false)
......@@ -98,6 +103,7 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
)
end
it_behaves_like 'importer with email notification'
it_behaves_like 'an issuable importer'
end
......@@ -105,8 +111,6 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
let(:file) { fixture_file_upload('spec/fixtures/csv_semicolon.csv') }
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[:error_lines]).to eq([4])
expect(subject[:parse_error]).to eq(false)
......@@ -121,6 +125,7 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
)
end
it_behaves_like 'importer with email notification'
it_behaves_like 'an issuable importer'
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