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

Deprecation of work package methods in one module

Klaus Zandersdce1ed146a14
diff --git a/modules/costs/app/models/cost_entry.rb b/modules/costs/app/models/cost_entry.rb
index fd68708a572..9955eec215e 100644
--- a/modules/costs/app/models/cost_entry.rb
+++ b/modules/costs/app/models/cost_entry.rb
@@ -61,6 +61,7 @@ class CostEntry < ApplicationRecord
extend CostEntryScopes
include Entry::Costs
include Entry::SplashedDates
+ include Entry::DeprecatedAssociation
def after_initialize
return unless new_record?
@@ -96,37 +97,9 @@ class CostEntry < ApplicationRecord
update_costs
end
- def work_package
- OpenProject::Deprecation.replaced(:work_package, :entity, caller_locations)
-
- if entity_type == "WorkPackage"
- entity
- end
- end
-
- def work_package_id
- OpenProject::Deprecation.replaced(:work_package_id, :entity_id, caller_locations)
-
- if entity_type == "WorkPackage"
- entity_id
- end
- end
-
- def work_package=(value)
- OpenProject::Deprecation.replaced(:work_package=, :entity=, caller_locations)
- self.entity = value
- end
-
- def work_package_id=(value)
- OpenProject::Deprecation.replaced(:work_package_id=, :entity_id=, caller_locations)
-
- self.entity_type = "WorkPackage"
- self.entity_id = value
- end
-
def entity=(value)
if value.is_a?(String) && value.starts_with?("gid://")
- super(GlobalID::Locator.locate(value, only: ALLOWED_ENTITY_TYPES.map(&:constantize)))
+ super(GlobalID::Locator.locate(value, only: ALLOWED_ENTITY_TYPES.map(&:safe_constantize)))
else
super
end
diff --git a/modules/costs/app/models/entry/deprecated_association.rb b/modules/costs/app/models/entry/deprecated_association.rb
new file mode 100644
index 00000000000..ba9e2c4e4f4
--- /dev/null
+++ b/modules/costs/app/models/entry/deprecated_association.rb
@@ -0,0 +1,65 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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-2013 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 COPYRIGHT and LICENSE files for more details.
+#++
+
+module Entry::DeprecatedAssociation
+ extend ActiveSupport::Concern
+
+ included do |base|
+ base.ignored_columns += %w[work_package_id]
+ end
+
+ def work_package
+ OpenProject::Deprecation.replaced(:work_package, :entity, caller_locations)
+
+ if entity_type == "WorkPackage"
+ entity
+ end
+ end
+
+ def work_package_id
+ OpenProject::Deprecation.replaced(:work_package_id, :entity_id, caller_locations)
+
+ if entity_type == "WorkPackage"
+ entity_id
+ end
+ end
+
+ def work_package=(value)
+ OpenProject::Deprecation.replaced(:work_package=, :entity=, caller_locations)
+ self.entity = value
+ end
+
+ def work_package_id=(value)
+ OpenProject::Deprecation.replaced(:work_package_id=, :entity_id=, caller_locations)
+
+ self.entity_type = "WorkPackage"
+ self.entity_id = value
+ end
+end
diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rb
index 69d02b3b6e9..3b49b539868 100644
--- a/modules/costs/app/models/time_entry.rb
+++ b/modules/costs/app/models/time_entry.rb
@@ -31,8 +31,6 @@
class TimeEntry < ApplicationRecord
ALLOWED_ENTITY_TYPES = %w[WorkPackage Meeting].freeze
- self.ignored_columns += %w[work_package_id]
-
# could have used polymorphic association
# project association here allows easy loading of time entries at project level with one database trip
belongs_to :project
@@ -89,6 +87,7 @@ class TimeEntry < ApplicationRecord
include ::Scopes::Scoped
include Entry::Costs
include Entry::SplashedDates
+ include Entry::DeprecatedAssociation
scopes :of_user_and_day,
:ongoing,
@@ -117,37 +116,9 @@ class TimeEntry < ApplicationRecord
end
end
- def work_package
- OpenProject::Deprecation.replaced(:work_package, :entity, caller_locations)
-
- if entity_type == "WorkPackage"
- entity
- end
- end
-
- def work_package_id
- OpenProject::Deprecation.replaced(:work_package_id, :entity_id, caller_locations)
-
- if entity_type == "WorkPackage"
- entity_id
- end
- end
-
- def work_package=(value)
- OpenProject::Deprecation.replaced(:work_package=, :entity=, caller_locations)
- self.entity = value
- end
-
- def work_package_id=(value)
- OpenProject::Deprecation.replaced(:work_package_id=, :entity_id=, caller_locations)
-
- self.entity_type = "WorkPackage"
- self.entity_id = value
- end
-
def entity=(value)
if value.is_a?(String) && value.starts_with?("gid://")
- super(GlobalID::Locator.locate(value, only: ALLOWED_ENTITY_TYPES.map(&:constantize)))
+ super(GlobalID::Locator.locate(value, only: ALLOWED_ENTITY_TYPES.map(&:safe_constantize)))
else
super
end