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

Add globalid behavior

Klaus Zandersb53e25d171b0
diff --git a/Gemfile b/Gemfile
index cc4951b27a2..9583faa751b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -173,6 +173,9 @@ gem "paper_trail", "~> 16.0.0"
gem "op-clamav-client", "~> 3.4", require: "clamav"
+# Global ID for polymorphic associations
+gem "globalid", "~> 1.2"
+
# Recurring meeting events definition
gem "ice_cube", "~> 0.17.0"
diff --git a/Gemfile.lock b/Gemfile.lock
index b26ebc918e1..47c4c2fca76 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1399,6 +1399,7 @@ DEPENDENCIES
fog-aws
friendly_id (~> 5.5.0)
fuubar (~> 2.5.0)
+ globalid (~> 1.2)
gon (~> 6.4.0)
good_job (= 3.99.1)
google-apis-gmail_v1
diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rb
index 325c4d5977c..e5de0f3c379 100644
--- a/modules/costs/app/models/time_entry.rb
+++ b/modules/costs/app/models/time_entry.rb
@@ -48,7 +48,7 @@ class TimeEntry < ApplicationRecord
acts_as_journalized
- validates :user_id, :project_id, :spent_on,
+ validates :user_id, :project_id, :spent_on, :entity,
presence: true
validates :hours,
@@ -128,8 +128,16 @@ class TimeEntry < ApplicationRecord
self.entity = 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)))
+ else
+ super
+ end
+ end
+
def hours=(value)
- write_attribute :hours, (value.is_a?(String) ? (value.to_hours || value) : value)
+ super(value.is_a?(String) ? (value.to_hours || value) : value)
end
def ongoing_hours
diff --git a/modules/costs/config/locales/en.yml b/modules/costs/config/locales/en.yml
index 707aef6fae1..3661f8e2536 100644
--- a/modules/costs/config/locales/en.yml
+++ b/modules/costs/config/locales/en.yml
@@ -58,6 +58,7 @@ en:
time_entry:
project: Project
user: User
+ entity: Entity
work_package: Work package
subject: Subject
hours: Hours