Class: IssueImport

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

Overview

Redmine - project management software Copyright (C) 2006-2016 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

Constants inherited from Import

Import::DATE_FORMATS

Instance Method Summary collapse

Methods inherited from Import

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

Constructor Details

This class inherits a constructor from Import

Instance Method Details

#allowed_target_projectsObject

Returns a scope of projects that user is allowed to import issue to



28
29
30
# File 'app/models/issue_import.rb', line 28

def allowed_target_projects
  Project.allowed_to(user, :import_issues)
end

#allowed_target_trackersObject

Returns a scope of trackers that user is allowed to import issue to



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

def allowed_target_trackers
  Issue.allowed_target_trackers(project, user)
end

#create_categories?Boolean

Returns true if missing categories should be created during the import

Returns:

  • (Boolean)


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

def create_categories?
  user.allowed_to?(:manage_categories, project) &&
    mapping['create_categories'] == '1'
end

#create_versions?Boolean

Returns true if missing versions should be created during the import

Returns:

  • (Boolean)


57
58
59
60
# File 'app/models/issue_import.rb', line 57

def create_versions?
  user.allowed_to?(:manage_versions, project) &&
    mapping['create_versions'] == '1'
end

#mappable_custom_fieldsObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/issue_import.rb', line 62

def mappable_custom_fields
  if tracker
    issue = Issue.new
    issue.project = project
    issue.tracker = tracker
    issue.editable_custom_field_values(user).map(&:custom_field)
  elsif project
    project.all_issue_custom_fields
  else
    []
  end
end

#projectObject



32
33
34
35
# File 'app/models/issue_import.rb', line 32

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



21
22
23
24
# File 'app/models/issue_import.rb', line 21

def saved_objects
  object_ids = saved_items.pluck(:obj_id)
  objects = Issue.where(:id => object_ids).order(:id).preload(:tracker, :priority, :status)
end

#trackerObject



43
44
45
46
47
48
# File 'app/models/issue_import.rb', line 43

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