Feature #22913 » 0001-Use-user-as-internal-field-instead-of-user_id-becaus.patch
| app/models/time_entry_import.rb | ||
|---|---|---|
|
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
|
||
| ... | ... | |
|
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
|
||
| app/views/imports/_time_entries_fields_mapping.html.erb | ||
|---|---|---|
|
<div class="splitcontentleft">
|
||
|
<% if User.current.allowed_to?(:log_time_for_other_users, @import.project) %>
|
||
|
<p>
|
||
|
<label for="import_mapping_user_id"><%= l(:field_user) %></label>
|
||
|
<%= mapping_select_tag @import, 'user_id', :required => true,
|
||
|
<label for="import_mapping_user"><%= l(:field_user) %></label>
|
||
|
<%= mapping_select_tag @import, 'user', :required => true,
|
||
|
:values => @import.allowed_target_users.map {|u| [u.name, u.id]}, :default_value => "value:#{User.current.id}" %>
|
||
|
</p>
|
||
|
<% end %>
|
||
| test/fixtures/files/import_time_entries.csv | ||
|---|---|---|
|
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
|
||
| test/functional/imports_controller_test.rb | ||
|---|---|---|
|
# '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
|
||
| test/unit/time_entry_import_test.rb | ||
|---|---|---|
|
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 }
|
||
| ... | ... | |
|
'spent_on' => '2',
|
||
|
'hours' => '3',
|
||
|
'comments' => '4',
|
||
|
'user_id' => '7'
|
||
|
'user' => '7'
|
||
|
}
|
||
|
}
|
||
|
import.save!
|
||