kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.6 KiB
96 lines
2.6 KiB
7 years ago
|
#-- encoding: UTF-8
|
||
|
|
||
|
#-- copyright
|
||
|
# OpenProject is a project management system.
|
||
|
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License version 3.
|
||
|
#
|
||
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
#
|
||
|
# 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.
|
||
|
#
|
||
|
# See doc/COPYRIGHT.rdoc for more details.
|
||
|
#++
|
||
|
|
||
7 years ago
|
class WorkPackages::CreateService
|
||
|
include ::WorkPackages::Shared::UpdateAncestors
|
||
|
include ::Shared::ServiceContext
|
||
7 years ago
|
|
||
|
attr_accessor :user,
|
||
|
:work_package,
|
||
|
:contract
|
||
|
|
||
7 years ago
|
def initialize(user:, contract: WorkPackages::CreateContract)
|
||
7 years ago
|
self.user = user
|
||
7 years ago
|
self.contract = contract
|
||
7 years ago
|
end
|
||
|
|
||
7 years ago
|
def call(attributes: {},
|
||
|
work_package: WorkPackage.new,
|
||
|
send_notifications: true)
|
||
|
in_context(send_notifications) do
|
||
|
create(attributes, work_package)
|
||
|
end
|
||
7 years ago
|
end
|
||
|
|
||
7 years ago
|
protected
|
||
7 years ago
|
|
||
7 years ago
|
def create(attributes, work_package)
|
||
|
result = set_attributes(attributes, work_package)
|
||
7 years ago
|
|
||
7 years ago
|
result.success &&= work_package.save
|
||
7 years ago
|
|
||
7 years ago
|
if result.success?
|
||
|
result.merge!(reschedule_related(work_package))
|
||
7 years ago
|
|
||
7 years ago
|
update_ancestors_all_attributes(result.all_results).each do |ancestor_result|
|
||
|
result.merge!(ancestor_result)
|
||
|
end
|
||
|
else
|
||
|
result.success = false
|
||
|
end
|
||
7 years ago
|
|
||
7 years ago
|
result
|
||
7 years ago
|
end
|
||
|
|
||
7 years ago
|
def set_attributes(attributes, wp)
|
||
|
WorkPackages::SetAttributesService
|
||
|
.new(user: user,
|
||
|
work_package: wp,
|
||
|
contract: contract)
|
||
|
.call(attributes)
|
||
7 years ago
|
end
|
||
|
|
||
7 years ago
|
def reschedule_related(work_package)
|
||
|
result = WorkPackages::SetScheduleService
|
||
|
.new(user: user,
|
||
|
work_package: work_package)
|
||
|
.call
|
||
7 years ago
|
|
||
7 years ago
|
result.self_and_dependent.each do |r|
|
||
|
if !r.result.save
|
||
|
result.success = false
|
||
|
r.errors = r.result.errors
|
||
|
end
|
||
|
end
|
||
7 years ago
|
|
||
7 years ago
|
result
|
||
7 years ago
|
end
|
||
|
end
|