Class: IssueImport

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

Overview

Redmine - project management software Copyright © 2006-2022 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 =
{
  'tracker' => 'field_tracker',
  'subject' => 'field_subject',
  'description' => 'field_description',
  'status' => 'field_status',
  'priority' => 'field_priority',
  'category' => 'field_category',
  'assigned_to' => 'field_assigned_to',
  'fixed_version' => 'field_fixed_version',
  'is_private' => 'field_is_private',
  'parent_issue_id' => 'field_parent_issue',
  'start_date' => 'field_start_date',
  'due_date' => 'field_due_date',
  'estimated_hours' => 'field_estimated_hours',
  'done_ratio' => 'field_done_ratio',
  'unique_id' => 'field_unique_id',
  'relation_duplicates' => 'label_duplicates',
  'relation_duplicated' => 'label_duplicated_by',
  'relation_blocks' => 'label_blocks',
  'relation_blocked' => 'label_blocked_by',
  'relation_relates' => 'label_relates_to',
  'relation_precedes' => 'label_precedes',
  'relation_follows' =>  'label_follows',
  'relation_copied_to' => 'label_copied_to',
  'relation_copied_from' => 'label_copied_from'
}

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)


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

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


48
49
50
# File 'app/models/issue_import.rb', line 48

def self.menu_item
  :issues
end

Instance Method Details

#allowed_target_projectsObject

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



64
65
66
# File 'app/models/issue_import.rb', line 64

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



75
76
77
# File 'app/models/issue_import.rb', line 75

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)


87
88
89
90
# File 'app/models/issue_import.rb', line 87

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)


93
94
95
96
# File 'app/models/issue_import.rb', line 93

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

#mappable_custom_fieldsObject



98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/models/issue_import.rb', line 98

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



68
69
70
71
# File 'app/models/issue_import.rb', line 68

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



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

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

#trackerObject



79
80
81
82
83
84
# File 'app/models/issue_import.rb', line 79

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