Class: IssueImport
- Defined in:
- app/models/issue_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 =
{ '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' }
Constants inherited from Import
Class Method Summary collapse
Instance Method Summary collapse
-
#allowed_target_projects ⇒ Object
Returns a scope of projects that user is allowed to import issue to.
-
#allowed_target_trackers ⇒ Object
Returns a scope of trackers that user is allowed to import issue to.
-
#create_categories? ⇒ Boolean
Returns true if missing categories should be created during the import.
-
#create_versions? ⇒ Boolean
Returns true if missing versions should be created during the import.
- #mappable_custom_fields ⇒ Object
- #project ⇒ Object
-
#saved_objects ⇒ Object
Returns the objects that were imported.
- #tracker ⇒ Object
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
42 43 44 |
# File 'app/models/issue_import.rb', line 42 def self.(user) user.allowed_to?(:import_issues, nil, :global => true) end |
.menu_item ⇒ Object
38 39 40 |
# File 'app/models/issue_import.rb', line 38 def self. :issues end |
Instance Method Details
#allowed_target_projects ⇒ Object
Returns a scope of projects that user is allowed to import issue to
54 55 56 |
# File 'app/models/issue_import.rb', line 54 def allowed_target_projects Project.allowed_to(user, :import_issues) end |
#allowed_target_trackers ⇒ Object
Returns a scope of trackers that user is allowed to import issue to
65 66 67 |
# File 'app/models/issue_import.rb', line 65 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
77 78 79 80 |
# File 'app/models/issue_import.rb', line 77 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
83 84 85 86 |
# File 'app/models/issue_import.rb', line 83 def create_versions? user.allowed_to?(:manage_versions, project) && mapping['create_versions'] == '1' end |
#mappable_custom_fields ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/models/issue_import.rb', line 88 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 |
#project ⇒ Object
58 59 60 61 |
# File 'app/models/issue_import.rb', line 58 def project project_id = mapping['project_id'].to_i allowed_target_projects.find_by_id(project_id) || allowed_target_projects.first end |
#saved_objects ⇒ Object
Returns the objects that were imported
47 48 49 50 |
# File 'app/models/issue_import.rb', line 47 def saved_objects object_ids = saved_items.pluck(:obj_id) objects = Issue.where(:id => object_ids).order(:id).preload(:tracker, :priority, :status) end |
#tracker ⇒ Object
69 70 71 72 73 74 |
# File 'app/models/issue_import.rb', line 69 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 |