summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2019-11-02 08:23:35 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2019-11-02 08:23:35 +0000
commit3afd17f83e6cc5c3314c7dab0499d56deda2ec12 (patch)
treea5ba9f0eeda5f38a6dfdd4b05e6849a751759c57 /app/models
parent7c0ecb4703a16b2c4345e8abd7150412ea86d1ce (diff)
downloadredmine-3afd17f83e6cc5c3314c7dab0499d56deda2ec12.tar.gz
redmine-3afd17f83e6cc5c3314c7dab0499d56deda2ec12.zip
Allow import time entries for other users (#32196).
Patch by Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@18890 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r--app/models/time_entry_import.rb26
1 files changed, 25 insertions, 1 deletions
diff --git a/app/models/time_entry_import.rb b/app/models/time_entry_import.rb
index 66b762f74..49c6de375 100644
--- a/app/models/time_entry_import.rb
+++ b/app/models/time_entry_import.rb
@@ -43,6 +43,16 @@ class TimeEntryImport < Import
project.activities
end
+ def allowed_target_users
+ users = []
+ if project
+ users = project.members.active.preload(:user)
+ users = users.map(&:user).select{ |u| u.allowed_to?(:log_time, project) }
+ end
+ users << User.current if User.current.logged? && !users.include?(User.current)
+ users
+ end
+
def project
project_id = mapping['project_id'].to_i
allowed_target_projects.find_by_id(project_id) || allowed_target_projects.first
@@ -55,11 +65,17 @@ class TimeEntryImport < Import
end
end
+ def user_value
+ if mapping['user_id'].to_s =~ /\Avalue:(\d+)\z/
+ $1.to_i
+ end
+ end
+
private
def build_object(row, item)
object = TimeEntry.new
- object.user = user
+ object.author = user
activity_id = nil
if activity
@@ -68,9 +84,17 @@ class TimeEntryImport < Import
activity_id = allowed_target_activities.named(activity_name).first.try(:id)
end
+ user_id = nil
+ if User.current.allowed_to?(:log_time_for_other_users, project)
+ user_id = user_value || row_value(row, 'user_id')
+ else
+ user_id = user.id
+ end
+
attributes = {
:project_id => project.id,
:activity_id => activity_id,
+ :user_id => user_id,
:issue_id => row_value(row, 'issue_id'),
:spent_on => row_date(row, 'spent_on'),