Class: TimeEntryImport

Inherits:
Import
  • Object
show all
Defined in:
app/models/time_entry_import.rb

Overview

Redmine - project management software Copyright (C) 2006-2020 Jean-Philippe Lang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Constant Summary collapse

AUTO_MAPPABLE_FIELDS =
{
  'activity' => 'field_activity',
  'user' => 'field_user',
  'issue_id' => 'field_issue',
  'spent_on' => 'field_spent_on',
  'hours' => 'field_hours',
  'comments' => 'field_comments'
}

Constants inherited from Import

Import::DATE_FORMATS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Import

#add_callback, #columns_options, #do_callbacks, #file=, #file_exists?, #filepath, #first_rows, #headers, #initialize, layout, #mapping, #parse_file, #read_items, #run, #saved_items, #set_default_settings, #to_param, #unsaved_items

Constructor Details

This class inherits a constructor from Import

Class Method Details

.authorized?(user) ⇒ Boolean

Returns:

  • (Boolean)

34
35
36
# File 'app/models/time_entry_import.rb', line 34

def self.authorized?(user)
  user.allowed_to?(:import_time_entries, nil, :global => true)
end

30
31
32
# File 'app/models/time_entry_import.rb', line 30

def self.menu_item
  :time_entries
end

Instance Method Details

#activityObject


70
71
72
73
74
75
# File 'app/models/time_entry_import.rb', line 70

def activity
  if mapping['activity'].to_s =~ /\Avalue:(\d+)\z/
    activity_id = $1.to_i
    allowed_target_activities.find_by_id(activity_id)
  end
end

#allowed_target_activitiesObject


51
52
53
# File 'app/models/time_entry_import.rb', line 51

def allowed_target_activities
  project.activities
end

#allowed_target_projectsObject


47
48
49
# File 'app/models/time_entry_import.rb', line 47

def allowed_target_projects
  Project.allowed_to(user, :log_time).order(:lft)
end

#allowed_target_usersObject


55
56
57
58
59
60
61
62
63
# File 'app/models/time_entry_import.rb', line 55

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

#mappable_custom_fieldsObject


43
44
45
# File 'app/models/time_entry_import.rb', line 43

def mappable_custom_fields
  TimeEntryCustomField.all
end

#projectObject


65
66
67
68
# File 'app/models/time_entry_import.rb', line 65

def project
  project_id = mapping['project_id'].to_i
  allowed_target_projects.find_by_id(project_id) || allowed_target_projects.first
end

#saved_objectsObject

Returns the objects that were imported


39
40
41
# File 'app/models/time_entry_import.rb', line 39

def saved_objects
  TimeEntry.where(:id => saved_items.pluck(:obj_id)).order(:id).preload(:activity, :project, :issue => [:tracker, :priority, :status])
end

#user_valueObject


77
78
79
80
81
# File 'app/models/time_entry_import.rb', line 77

def user_value
  if mapping['user'].to_s =~ /\Avalue:(\d+)\z/
    $1.to_i
  end
end