Commit e2698d5d authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Improve email messages

Also refactored cleanup view to use the same localized string
parent 63e9969c
...@@ -7,12 +7,12 @@ module UploadsActions ...@@ -7,12 +7,12 @@ module UploadsActions
UPLOAD_MOUNTS = %w(avatar attachment file logo header_logo favicon).freeze UPLOAD_MOUNTS = %w(avatar attachment file logo header_logo favicon).freeze
def create def create
link_to_file = UploadService.new(model, params[:file], uploader_class).execute.to_h link_to_file = UploadService.new(model, params[:file], uploader_class).execute
respond_to do |format| respond_to do |format|
if link_to_file if link_to_file
format.json do format.json do
render json: { link: link_to_file } render json: { link: link_to_file.to_h }
end end
else else
format.json do format.json do
......
...@@ -222,8 +222,9 @@ class ProjectPolicy < BasePolicy ...@@ -222,8 +222,9 @@ class ProjectPolicy < BasePolicy
rule { owner | admin | guest | group_member }.prevent :request_access rule { owner | admin | guest | group_member }.prevent :request_access
rule { ~request_access_enabled }.prevent :request_access rule { ~request_access_enabled }.prevent :request_access
rule { developer & can?(:create_issue) }.enable :import_issues
rule { can?(:developer_access) }.policy do rule { can?(:developer_access) }.policy do
enable :import_issues
enable :admin_merge_request enable :admin_merge_request
enable :admin_milestone enable :admin_milestone
enable :update_merge_request enable :update_merge_request
......
...@@ -6,7 +6,7 @@ module Issues ...@@ -6,7 +6,7 @@ module Issues
@user = user @user = user
@project = project @project = project
@uploader = upload.build_uploader @uploader = upload.build_uploader
@results = { success: 0, errors: [], valid_file: true } @results = { success: 0, error_lines: [], parse_error: false }
end end
def execute def execute
...@@ -30,11 +30,11 @@ module Issues ...@@ -30,11 +30,11 @@ module Issues
if issue.persisted? if issue.persisted?
@results[:success] += 1 @results[:success] += 1
else else
@results[:errors].push(line_no) @results[:error_lines].push(line_no)
end end
end end
rescue ArgumentError, CSV::MalformedCSVError rescue ArgumentError, CSV::MalformedCSVError
@results[:valid_file] = false @results[:parse_error] = true
end end
def email_results_to_user def email_results_to_user
......
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
has been completed. has been completed.
%p{ style: text_style } %p{ style: text_style }
#{pluralize(@results[:success], 'issue')} imported successfully. #{pluralize(@results[:success], 'issue')} imported.
- if @results[:errors].present? - if @results[:error_lines].present?
%p{ style: text_style } %p{ style: text_style }
Errors found on line #{'number'.pluralize(@results[:errors].size)}: #{@results[:errors].join(', ')}. Errors found on line #{'number'.pluralize(@results[:error_lines].size)}: #{@results[:error_lines].join(', ')}. Please check if these lines have an issue title.
- unless @results[:valid_file] - if @results[:parse_error]
%p{ style: text_style } %p{ style: text_style }
Error parsing CSV file. 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. Your CSV import for project <%= @project.full_name %> (<%= project_url(@project) %>) has been completed.
<%= pluralize(@results[:success], 'issue') %> imported successfully. <%= pluralize(@results[:success], 'issue') %> imported.
<% if @results[:errors].present? %> <% if @results[:error_lines].present? %>
Errors found on line <%= 'number'.pluralize(@results[:errors].size) %>: <%= @results[:errors].join(', ') %>. Errors found on line <%= 'number'.pluralize(@results[:error_lines].size) %>: <%= @results[:error_lines].join(', ') %>. Please check if these lines have an issue title.
<% end %> <% end %>
<% unless @results[:valid_file] %> <% if @results[:parse_error] %>
Error parsing CSV file. Error parsing CSV file. Please make sure it has the correct format: a delimited text file that uses a comma to separate values.
<% end %> <% end %>
...@@ -24,6 +24,6 @@ ...@@ -24,6 +24,6 @@
= _("No file selected") = _("No file selected")
= f.file_field :bfg_object_map, accept: 'text/plain', class: "hidden js-object-map-input", required: true = f.file_field :bfg_object_map, accept: 'text/plain', class: "hidden js-object-map-input", required: true
.form-text.text-muted .form-text.text-muted
= _("The maximum file size allowed is %{max_attachment_size}mb") % { max_attachment_size: Gitlab::CurrentSettings.max_attachment_size } = _("The maximum file size allowed is %{size}.") % { size: number_to_human_size(Gitlab::CurrentSettings.max_attachment_size.megabytes) }
= f.submit _('Start cleanup'), class: 'btn btn-success' = f.submit _('Start cleanup'), class: 'btn btn-success'
.issues-import-modal.modal .issues-import-modal.modal
.modal-dialog .modal-dialog
.modal-content .modal-content
= form_tag [:import_csv, @project.namespace.becomes(Namespace), @project, :issues], multipart: true do = form_tag import_csv_namespace_project_issues_path, multipart: true do
.modal-header .modal-header
%h3 %h3
= _('Import issues') = _('Import issues')
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
= file_field_tag :file, accept: 'text/csv', required: true = file_field_tag :file, accept: 'text/csv', required: true
%p.text-secondary %p.text-secondary
= _('It must have a header row and at least two columns: the first column is the issue title and the second column is the issue description. The separator is automatically detected.') = _('It must have a header row and at least two columns: the first column is the issue title and the second column is the issue description. The separator is automatically detected.')
%p.text-secondary = _('The maximum file size allowed is %{size}.') % { size: number_to_human_size(Gitlab::CurrentSettings.max_attachment_size.megabytes) }
= _('The maximum file size allowed is %{size}.') % {size: number_to_human_size(Gitlab::CurrentSettings.max_attachment_size.megabytes)}
.modal-footer .modal-footer
%button{ type: 'submit', class: 'btn btn-success', title: _('Import issues') } %button{ type: 'submit', class: 'btn btn-success', title: _('Import issues') }
= _('Import issues') = _('Import issues')
...@@ -6620,9 +6620,6 @@ msgstr "" ...@@ -6620,9 +6620,6 @@ msgstr ""
msgid "The issue stage shows the time it takes from creating an issue to assigning the issue to a milestone, or add the issue to a list on your Issue Board. Begin creating issues to see data for this stage." msgid "The issue stage shows the time it takes from creating an issue to assigning the issue to a milestone, or add the issue to a list on your Issue Board. Begin creating issues to see data for this stage."
msgstr "" msgstr ""
msgid "The maximum file size allowed is %{max_attachment_size}mb"
msgstr ""
msgid "The maximum file size allowed is %{size}." msgid "The maximum file size allowed is %{size}."
msgstr "" msgstr ""
......
...@@ -21,7 +21,7 @@ describe Issues::ImportCsvService do ...@@ -21,7 +21,7 @@ describe Issues::ImportCsvService do
expect_any_instance_of(Notify).to receive(:import_issues_csv_email) expect_any_instance_of(Notify).to receive(:import_issues_csv_email)
expect(subject[:success]).to eq(0) expect(subject[:success]).to eq(0)
expect(subject[:valid_file]).to eq(false) expect(subject[:parse_error]).to eq(true)
end end
end end
...@@ -32,8 +32,8 @@ describe Issues::ImportCsvService do ...@@ -32,8 +32,8 @@ describe Issues::ImportCsvService do
expect_any_instance_of(Notify).to receive(:import_issues_csv_email) expect_any_instance_of(Notify).to receive(:import_issues_csv_email)
expect(subject[:success]).to eq(3) expect(subject[:success]).to eq(3)
expect(subject[:errors]).to eq([]) expect(subject[:error_lines]).to eq([])
expect(subject[:valid_file]).to eq(true) expect(subject[:parse_error]).to eq(false)
end end
end end
...@@ -44,8 +44,8 @@ describe Issues::ImportCsvService do ...@@ -44,8 +44,8 @@ describe Issues::ImportCsvService do
expect_any_instance_of(Notify).to receive(:import_issues_csv_email) expect_any_instance_of(Notify).to receive(:import_issues_csv_email)
expect(subject[:success]).to eq(2) expect(subject[:success]).to eq(2)
expect(subject[:errors]).to eq([3]) expect(subject[:error_lines]).to eq([3])
expect(subject[:valid_file]).to eq(true) expect(subject[:parse_error]).to eq(false)
end end
end end
...@@ -56,8 +56,8 @@ describe Issues::ImportCsvService do ...@@ -56,8 +56,8 @@ describe Issues::ImportCsvService do
expect_any_instance_of(Notify).to receive(:import_issues_csv_email) expect_any_instance_of(Notify).to receive(:import_issues_csv_email)
expect(subject[:success]).to eq(3) expect(subject[:success]).to eq(3)
expect(subject[:errors]).to eq([4]) expect(subject[:error_lines]).to eq([4])
expect(subject[:valid_file]).to eq(true) expect(subject[:parse_error]).to eq(false)
end end
end end
end end
......
...@@ -63,7 +63,7 @@ describe UploadService do ...@@ -63,7 +63,7 @@ describe UploadService do
@link_to_file = upload_file(@project, txt) @link_to_file = upload_file(@project, txt)
end end
it { expect(@link_to_file).to eq(nil) } it { expect(@link_to_file).to eq({}) }
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