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