From c2bd1b0d81a36908cb3e003cf3daddb8e603e0bb Mon Sep 17 00:00:00 2001 From: Jyri-Petteri Paloposki Date: Wed, 9 Feb 2022 11:28:05 +0200 Subject: [PATCH 1/3] Error message fixes for CSV import. Add the necessary directory to Docker image. --- Dockerfile | 17 ++++++++++++++++- app/controllers/data_controller.rb | 8 ++++++-- app/models/todo.rb | 4 ++++ public/uploads/csv/.keep | 0 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 public/uploads/csv/.keep diff --git a/Dockerfile b/Dockerfile index 6faeffe5..d17e68ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,10 +17,25 @@ RUN apt-get update && apt-get install -y yarn netcat RUN mkdir /app/log -COPY . /app/ +COPY COPYING /app/ +COPY config /app/config/ COPY config/database.docker.yml /app/config/database.yml COPY config/site.docker.yml /app/config/site.yml +COPY bin /app/bin/ +COPY script /app/script/ +COPY public /app/public/ +COPY vendor /app/vendor/ + +COPY .yardopts /app/ +COPY Rakefile /app/ +COPY config.ru /app/ +COPY docker-entrypoint.sh /app/ + +COPY lib /app/lib/ +COPY app /app/app/ +COPY db /app/db/ + RUN RAILS_ENV=production bundle exec rake assets:precompile ENTRYPOINT ["/app/docker-entrypoint.sh"] diff --git a/app/controllers/data_controller.rb b/app/controllers/data_controller.rb index e9893f16..9ed72b43 100644 --- a/app/controllers/data_controller.rb +++ b/app/controllers/data_controller.rb @@ -62,12 +62,16 @@ class DataController < ApplicationController flash[:notice] = t 'data.import.projects_count', count: count when 'todos' count = Todo.import path_and_file, params, current_user - flash[:notice] = t 'data.import.todos.count', count: count + if not count + flash[:error] = t('data.import.errors.invalid_destination') + else + flash[:notice] = t 'data.import.todos_count', count: count + end else flash[:error] = t('data.import.errors.invalid_destination') end rescue Exception => e - flash[:error] = t 'data.import.invalid_destination', e: e + flash[:error] = t 'data.import.errors.invalid_destination', e: e end File.delete(path_and_file) redirect_to import_data_path diff --git a/app/models/todo.rb b/app/models/todo.rb index c97f3ade..79972055 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -353,6 +353,10 @@ class Todo < ApplicationRecord def self.import(filename, params, user) default_context = user.contexts.order('id').first + if default_context.nil? + logger.error "No available contexts in import" + return FALSE + end count = 0 CSV.foreach(filename, headers: true) do |row| diff --git a/public/uploads/csv/.keep b/public/uploads/csv/.keep new file mode 100644 index 00000000..e69de29b From 511a4a23b6535c7507ede54e8b864cc059824f10 Mon Sep 17 00:00:00 2001 From: Jyri-Petteri Paloposki Date: Wed, 9 Feb 2022 11:48:09 +0200 Subject: [PATCH 2/3] Better error messages --- app/controllers/data_controller.rb | 4 ++-- app/models/todo.rb | 5 +---- config/locales/en.yml | 1 + 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/data_controller.rb b/app/controllers/data_controller.rb index 9ed72b43..218de1e0 100644 --- a/app/controllers/data_controller.rb +++ b/app/controllers/data_controller.rb @@ -62,8 +62,8 @@ class DataController < ApplicationController flash[:notice] = t 'data.import.projects_count', count: count when 'todos' count = Todo.import path_and_file, params, current_user - if not count - flash[:error] = t('data.import.errors.invalid_destination') + if ! count + flash[:error] = t('data.import.errors.no_context') else flash[:notice] = t 'data.import.todos_count', count: count end diff --git a/app/models/todo.rb b/app/models/todo.rb index 79972055..acfe032f 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -353,10 +353,7 @@ class Todo < ApplicationRecord def self.import(filename, params, user) default_context = user.contexts.order('id').first - if default_context.nil? - logger.error "No available contexts in import" - return FALSE - end + return false if default_context.nil? count = 0 CSV.foreach(filename, headers: true) do |row| diff --git a/config/locales/en.yml b/config/locales/en.yml index 983aee73..67613cee 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -207,6 +207,7 @@ en: invalid_csv: "Invalid CSV: could not read headers: %{e}" save_error: "Could not save uploaded CSV (%{path_and_file}). Can Tracks write\ \ to the upload directory? %{e}" + no_context: No default context could be found map_title: Map fields to be imported header: Importing data submit: Import From dfdab8af557fa259ead3bd6e6d94642f1b7e0b11 Mon Sep 17 00:00:00 2001 From: Jyri-Petteri Paloposki Date: Wed, 9 Feb 2022 11:50:16 +0200 Subject: [PATCH 3/3] CS fix --- app/controllers/data_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/data_controller.rb b/app/controllers/data_controller.rb index 218de1e0..610ae047 100644 --- a/app/controllers/data_controller.rb +++ b/app/controllers/data_controller.rb @@ -62,7 +62,7 @@ class DataController < ApplicationController flash[:notice] = t 'data.import.projects_count', count: count when 'todos' count = Todo.import path_and_file, params, current_user - if ! count + if !count flash[:error] = t('data.import.errors.no_context') else flash[:notice] = t 'data.import.todos_count', count: count