Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

remove unused service

ulfertse20910a2c99f
diff --git a/app/models/work_package/scheduling_rules.rb b/app/models/work_package/scheduling_rules.rb
index b840adee098..1b910e14287 100644
--- a/app/models/work_package/scheduling_rules.rb
+++ b/app/models/work_package/scheduling_rules.rb
@@ -31,13 +31,6 @@
module WorkPackage::SchedulingRules
extend ActiveSupport::Concern
- def reschedule_after(date)
- WorkPackages::RescheduleService
- .new(user: User.current,
- work_package: self)
- .call(date)
- end
-
def schedule_automatically?
!schedule_manually?
end
diff --git a/app/services/work_packages/reschedule_service.rb b/app/services/work_packages/reschedule_service.rb
deleted file mode 100644
index a43ea4dd9cc..00000000000
--- a/app/services/work_packages/reschedule_service.rb
+++ /dev/null
@@ -1,133 +0,0 @@
-#-- encoding: UTF-8
-
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2020 the OpenProject GmbH
-#
-# 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 docs/COPYRIGHT.rdoc for more details.
-#++
-
-class WorkPackages::RescheduleService
- include ::Shared::ServiceContext
-
- attr_accessor :user,
- :work_package
-
- def initialize(user:, work_package:)
- self.user = user
- self.work_package = work_package
- end
-
- def call(date)
- in_context(work_package) do
- return if date.nil?
-
- update(date)
- end
- end
-
- def update(date)
- result = set_dates_on_lowest_level(date)
-
- return result if persist(result).failure?
-
- related_result = reschedule_related(result)
- combine_results(result, related_result)
-
- persist(result)
- end
-
- def set_dates_on_lowest_level(date)
- if work_package.leaf?
- reschedule(work_package, date)
- else
- reschedule_leaves(date)
- end
- end
-
- def reschedule_related(result)
- schedule_starts = if work_package.leaf?
- work_package
- else
- result.dependent_results.map(&:result)
- end
-
- set_schedule(schedule_starts)
- end
-
- def set_schedule(work_packages)
- WorkPackages::SetScheduleService
- .new(user: user,
- work_package: work_packages)
- .call(%i(start_date due_date))
- end
-
- def reschedule_leaves(date)
- result = ServiceResult.new(success: true, result: work_package)
-
- work_package.leaves.each do |leaf|
- result.add_dependent!(reschedule(leaf, date))
- end
-
- result
- end
-
- def reschedule(scheduled, date)
- if scheduled.start_date.nil? || scheduled.start_date < date
- attributes = { due_date: date + scheduled.duration - 1,
- start_date: date }
-
- set_dates(scheduled, attributes)
- else
- ServiceResult.new(success: true, result: scheduled)
- end
- end
-
- def set_dates(scheduled, attributes)
- WorkPackages::SetAttributesService
- .new(user: user,
- model: scheduled,
- contract_class: WorkPackages::UpdateContract)
- .call(attributes)
- end
-
- def persist(result)
- return result unless result.success? && result.all_errors.all?(&:empty?)
-
- result.success = result.result.save && result.dependent_results.all? { |res| res.result.save(validate: false) }
-
- result
- end
-
- def combine_results(start_result, related_result)
- related_result.dependent_results.reject! do |dr|
- if dr.result == work_package
- start_result.result = dr.result
- start_result.errors = dr.errors
- end
- end
-
- start_result.merge!(related_result)
- end
-end
diff --git a/spec/models/work_package/work_package_reschedule_after_spec.rb b/spec/models/work_package/work_package_reschedule_after_spec.rb
deleted file mode 100644
index 8c27bbeb75c..00000000000
--- a/spec/models/work_package/work_package_reschedule_after_spec.rb
+++ /dev/null
@@ -1,214 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2020 the OpenProject GmbH
-#
-# 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 docs/COPYRIGHT.rdoc for more details.
-#++
-
-require 'spec_helper'
-
-describe WorkPackage, '#reschedule_after', type: :model do
- let(:user) { FactoryBot.create(:admin) }
- let(:project) { FactoryBot.build(:project_with_types) }
- let(:work_package) { FactoryBot.create(:work_package, project: project, type: project.types.first) }
- let(:work_package2) { FactoryBot.create(:work_package, project: project, type: project.types.first) }
- let(:work_package3) { FactoryBot.create(:work_package, project: project, type: project.types.first) }
-
- let(:instance) { work_package }
- let(:child) do
- work_package2.parent = instance
-
- work_package2
- end
- let(:grandchild) do
- work_package3.parent = child
-
- work_package3
- end
-
- before do
- login_as(user)
- end
-
- describe 'for a single node having start and finish date' do
- before do
- instance.start_date = Date.today
- instance.due_date = Date.today + 7.days
-
- instance.reschedule_after(Date.today + 3.days)
- end
-
- it 'should set the start_date to the provided date' do
- expect(instance.start_date).to eq(Date.today + 3.days)
- end
-
- it 'should set the set the finish date plus the duration' do
- expect(instance.due_date).to eq(Date.today + 10.days)
- end
- end
-
- describe 'for a single node having neither start nor finish date' do
- before do
- instance.start_date = nil
- instance.due_date = nil
-
- instance.reschedule_after(Date.today + 3.days)
- end
-
- it 'should set the start_date to the provided date' do
- expect(instance.start_date).to eq(Date.today + 3.days)
- end
-
- it 'should set the set the finish date plus the duration' do
- expect(instance.due_date).to eq(Date.today + 3.days)
- end
- end
-
- describe 'for a single node having only a finish date' do
- before do
- instance.start_date = nil
- instance.due_date = Date.today + 7.days
-
- instance.reschedule_after(Date.today + 3.days)
- end
-
- it 'should set the start_date to the provided date' do
- expect(instance.start_date).to eq(Date.today + 3.days)
- end
-
- it 'should set the set the finish date plus the duration' do
- expect(instance.due_date).to eq(Date.today + 3.days)
- end
- end
-
- describe 'with a child' do
- before do
- child.start_date = Date.today
- child.due_date = Date.today + 7.days
- child.save!
- instance.reload
-
- instance.reschedule_after(Date.today + 3.days)
- end
-
- it 'should set the start_date to the provided date' do
- instance.reload
- expect(instance.start_date).to eq(Date.today + 3.days)
- end
-
- it "should set the set the finish date to the provided date plus the child's duration" do
- instance.reload
- expect(instance.due_date).to eq(Date.today + 10.days)
- end
-
- it "should set the child's start date to the provided date" do
- child.reload
- expect(child.start_date).to eq(Date.today + 3.days)
- end
-
- it "should set the set child's finish date to the provided date plus the child's duration" do
- child.reload
- expect(child.due_date).to eq(Date.today + 10.days)
- end
- end
-
- describe "with a child
- while the new date is set to be between the child's start and finish date" do
- before do
- child.start_date = Date.today + 1.day
- child.due_date = Date.today + 7.days
-
- child.save!
- instance.reload
-
- instance.start_date = Date.today
- instance.due_date = Date.today + 7.days
-
- instance.reschedule_after(Date.today + 3.days)
- end
-
- it 'should set the start_date to the provided date' do
- instance.reload
- expect(instance.start_date).to eq(Date.today + 3.days)
- end
-
- it "should set the set the finish date to the provided date plus the child's duration" do
- instance.reload
- expect(instance.due_date).to eq(Date.today + 9.days)
- end
-
- it "should set the child's start date to the provided date" do
- child.reload
- expect(child.start_date).to eq(Date.today + 3.days)
- end
-
- it "should set the set child's finish date to the provided date plus the child's duration" do
- child.reload
- expect(child.due_date).to eq(Date.today + 9.days)
- end
- end
-
- describe 'with child and grandchild' do
- before do
- child.save
- grandchild.start_date = Date.today
- grandchild.due_date = Date.today + 7.days
-
- grandchild.save!
- instance.reload
-
- instance.reschedule_after(Date.today + 3.days)
- end
-
- it 'should set the start_date to the provided date' do
- instance.reload
- expect(instance.start_date).to eq(Date.today + 3.days)
- end
-
- it "should set the set the finish date to the provided date plus the child's duration" do
- instance.reload
- expect(instance.due_date).to eq(Date.today + 10.days)
- end
-
- it "should set the child's start date to the provided date" do
- child.reload
- expect(child.start_date).to eq(Date.today + 3.days)
- end
-
- it "should set the set child's finish date to the provided date plus the grandchild's duration" do
- child.reload
- expect(child.due_date).to eq(Date.today + 10.days)
- end
-
- it "should set the grandchild's start date to the provided date" do
- grandchild.reload
- expect(grandchild.start_date).to eq(Date.today + 3.days)
- end
-
- it "should set the set grandchild's finish date to the provided date plus the grandchild's duration" do
- grandchild.reload
- expect(grandchild.due_date).to eq(Date.today + 10.days)
- end
- end
-end