Feature #22913 » 0001-Use-user-as-internal-field-instead-of-user_id-becaus.patch
app/models/time_entry_import.rb | ||
---|---|---|
66 | 66 |
end |
67 | 67 | |
68 | 68 |
def user_value |
69 |
if mapping['user_id'].to_s =~ /\Avalue:(\d+)\z/
|
|
69 |
if mapping['user'].to_s =~ /\Avalue:(\d+)\z/ |
|
70 | 70 |
$1.to_i |
71 | 71 |
end |
72 | 72 |
end |
... | ... | |
88 | 88 |
if User.current.allowed_to?(:log_time_for_other_users, project) |
89 | 89 |
if user_value |
90 | 90 |
user_id = user_value |
91 |
elsif user_name = row_value(row, 'user_id')
|
|
91 |
elsif user_name = row_value(row, 'user') |
|
92 | 92 |
user_id = Principal.detect_by_keyword(allowed_target_users, user_name).try(:id) |
93 | 93 |
end |
94 | 94 |
else |
app/views/imports/_time_entries_fields_mapping.html.erb | ||
---|---|---|
14 | 14 |
<div class="splitcontentleft"> |
15 | 15 |
<% if User.current.allowed_to?(:log_time_for_other_users, @import.project) %> |
16 | 16 |
<p> |
17 |
<label for="import_mapping_user_id"><%= l(:field_user) %></label>
|
|
18 |
<%= mapping_select_tag @import, 'user_id', :required => true,
|
|
17 |
<label for="import_mapping_user"><%= l(:field_user) %></label> |
|
18 |
<%= mapping_select_tag @import, 'user', :required => true, |
|
19 | 19 |
:values => @import.allowed_target_users.map {|u| [u.name, u.id]}, :default_value => "value:#{User.current.id}" %> |
20 | 20 |
</p> |
21 | 21 |
<% end %> |
test/fixtures/files/import_time_entries.csv | ||
---|---|---|
1 |
row;issue_id;date;hours;comment;activity;overtime;user_id
|
|
1 |
row;issue_id;date;hours;comment;activity;overtime;user |
|
2 | 2 |
1;;2020-01-01;1;Some Design;Design;yes;jsmith@somenet.foo |
3 | 3 |
2;;2020-01-02;2;Some Development;Development;yes;jsmith@somenet.foo |
4 | 4 |
3;1;2020-01-03;3;Some QA;QA;no;dlopper@somenet.foo |
test/functional/imports_controller_test.rb | ||
---|---|---|
202 | 202 | |
203 | 203 |
# 'user_id' field should be available because User#2 has both |
204 | 204 |
# 'import_time_entries' and 'log_time_for_other_users' permissions |
205 |
assert_select 'select[name=?]', 'import_settings[mapping][user_id]' do
|
|
205 |
assert_select 'select[name=?]', 'import_settings[mapping][user]' do |
|
206 | 206 |
# Current user should be the default value |
207 | 207 |
assert_select 'option[value="value:2"][selected]', :text => User.find(2).name |
208 | 208 |
assert_select 'option[value="value:3"]', :text => User.find(3).name |
test/unit/time_entry_import_test.rb | ||
---|---|---|
140 | 140 |
def test_maps_user_to_column_value |
141 | 141 |
User.current = User.find(1) |
142 | 142 |
import = generate_import_with_mapping |
143 |
import.mapping.merge!('user_id' => 'value:1')
|
|
143 |
import.mapping.merge!('user' => 'value:1') |
|
144 | 144 |
import.save! |
145 | 145 |
first, second, third, fourth = new_records(TimeEntry, 4) { import.run } |
146 | 146 | |
... | ... | |
185 | 185 |
'spent_on' => '2', |
186 | 186 |
'hours' => '3', |
187 | 187 |
'comments' => '4', |
188 |
'user_id' => '7'
|
|
188 |
'user' => '7'
|
|
189 | 189 |
} |
190 | 190 |
} |
191 | 191 |
import.save! |