From 4f42929bd3c95d9e70ab8832026aafcf14d0e6a3 Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Sat, 15 Feb 2020 17:29:23 +0200 Subject: [PATCH 1/2] Use 'user' as internal field instead of user_id because the column accepts also user login as value, not only the id. --- app/models/time_entry_import.rb | 4 ++-- app/views/imports/_time_entries_fields_mapping.html.erb | 4 ++-- test/fixtures/files/import_time_entries.csv | 2 +- test/functional/imports_controller_test.rb | 2 +- test/unit/time_entry_import_test.rb | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/time_entry_import.rb b/app/models/time_entry_import.rb index 0ac4429f4..fa33b60c5 100644 --- a/app/models/time_entry_import.rb +++ b/app/models/time_entry_import.rb @@ -66,7 +66,7 @@ class TimeEntryImport < Import end def user_value - if mapping['user_id'].to_s =~ /\Avalue:(\d+)\z/ + if mapping['user'].to_s =~ /\Avalue:(\d+)\z/ $1.to_i end end @@ -88,7 +88,7 @@ class TimeEntryImport < Import if User.current.allowed_to?(:log_time_for_other_users, project) if user_value user_id = user_value - elsif user_name = row_value(row, 'user_id') + elsif user_name = row_value(row, 'user') user_id = Principal.detect_by_keyword(allowed_target_users, user_name).try(:id) end else diff --git a/app/views/imports/_time_entries_fields_mapping.html.erb b/app/views/imports/_time_entries_fields_mapping.html.erb index 1b4f7a0e4..c455d3b91 100644 --- a/app/views/imports/_time_entries_fields_mapping.html.erb +++ b/app/views/imports/_time_entries_fields_mapping.html.erb @@ -14,8 +14,8 @@
<% if User.current.allowed_to?(:log_time_for_other_users, @import.project) %>

- - <%= mapping_select_tag @import, 'user_id', :required => true, + + <%= mapping_select_tag @import, 'user', :required => true, :values => @import.allowed_target_users.map {|u| [u.name, u.id]}, :default_value => "value:#{User.current.id}" %>

<% end %> diff --git a/test/fixtures/files/import_time_entries.csv b/test/fixtures/files/import_time_entries.csv index b89cfdfaa..dfd2abfd6 100644 --- a/test/fixtures/files/import_time_entries.csv +++ b/test/fixtures/files/import_time_entries.csv @@ -1,4 +1,4 @@ -row;issue_id;date;hours;comment;activity;overtime;user_id +row;issue_id;date;hours;comment;activity;overtime;user 1;;2020-01-01;1;Some Design;Design;yes;jsmith@somenet.foo 2;;2020-01-02;2;Some Development;Development;yes;jsmith@somenet.foo 3;1;2020-01-03;3;Some QA;QA;no;dlopper@somenet.foo diff --git a/test/functional/imports_controller_test.rb b/test/functional/imports_controller_test.rb index 6b22bb19a..7b5a132fc 100644 --- a/test/functional/imports_controller_test.rb +++ b/test/functional/imports_controller_test.rb @@ -202,7 +202,7 @@ class ImportsControllerTest < Redmine::ControllerTest # 'user_id' field should be available because User#2 has both # 'import_time_entries' and 'log_time_for_other_users' permissions - assert_select 'select[name=?]', 'import_settings[mapping][user_id]' do + assert_select 'select[name=?]', 'import_settings[mapping][user]' do # Current user should be the default value assert_select 'option[value="value:2"][selected]', :text => User.find(2).name assert_select 'option[value="value:3"]', :text => User.find(3).name diff --git a/test/unit/time_entry_import_test.rb b/test/unit/time_entry_import_test.rb index d84de22f4..c974707b0 100644 --- a/test/unit/time_entry_import_test.rb +++ b/test/unit/time_entry_import_test.rb @@ -140,7 +140,7 @@ class TimeEntryImportTest < ActiveSupport::TestCase def test_maps_user_to_column_value User.current = User.find(1) import = generate_import_with_mapping - import.mapping.merge!('user_id' => 'value:1') + import.mapping.merge!('user' => 'value:1') import.save! first, second, third, fourth = new_records(TimeEntry, 4) { import.run } @@ -185,7 +185,7 @@ class TimeEntryImportTest < ActiveSupport::TestCase 'spent_on' => '2', 'hours' => '3', 'comments' => '4', - 'user_id' => '7' + 'user' => '7' } } import.save! -- 2.22.0