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

Use GID to display link to work package

Klaus Zanders487c342f903a
diff --git a/modules/reporting/app/helpers/reporting_helper.rb b/modules/reporting/app/helpers/reporting_helper.rb
index a834a2ead19..2d17107464d 100644
--- a/modules/reporting/app/helpers/reporting_helper.rb
+++ b/modules/reporting/app/helpers/reporting_helper.rb
@@ -122,13 +122,13 @@ module ReportingHelper
when :work_package_id
link_to_work_package(WorkPackage.find(value.to_i))
when :entity_gid
- # TODO: All possible time entry associations need to be checked here
entity = GlobalID::Locator.locate(value, only: TimeEntry::ALLOWED_ENTITY_TYPES.map(&:safe_constantize))
- if entity.is_a?(WorkPacakge)
+
+ if entity.is_a?(::WorkPackage)
link_to_work_package(entity)
- else
- # TODO proper other links
- entity.inspect
+ elsif entity.is_a?(::Meeting)
+ # TODO: add a link
+ entity.title
end
when :entity_type
# TODO: Skip for now
diff --git a/modules/reporting/app/models/cost_query/group_by/work_package_id.rb b/modules/reporting/app/models/cost_query/group_by/work_package_id.rb
index b6e365f69e8..284dff803d2 100644
--- a/modules/reporting/app/models/cost_query/group_by/work_package_id.rb
+++ b/modules/reporting/app/models/cost_query/group_by/work_package_id.rb
@@ -31,7 +31,7 @@ class CostQuery::GroupBy::WorkPackageId < Report::GroupBy::Base
def initialize(child = nil, options = {})
super
- group_fields "entity_type", "entity_id"
+ group_fields "entity_gid"
end
def self.label
diff --git a/modules/reporting/app/models/cost_query/result.rb b/modules/reporting/app/models/cost_query/result.rb
index 41e8328b254..1f0a309aa6e 100644
--- a/modules/reporting/app/models/cost_query/result.rb
+++ b/modules/reporting/app/models/cost_query/result.rb
@@ -68,11 +68,6 @@ class CostQuery::Result < Report::Result
start + self["units"].to_f.hours
end
- def entity_gid
- # TODO: Find if there is a better way to generate the entity GID
- "gid://#{GlobalID.app}/#{self['entity_type']}/#{self['entity_id']}"
- end
-
private
def timestamp(date, time, time_zone)
diff --git a/modules/reporting/app/models/cost_query/sql_statement.rb b/modules/reporting/app/models/cost_query/sql_statement.rb
index bbacc8d996b..fd9f94b85a4 100644
--- a/modules/reporting/app/models/cost_query/sql_statement.rb
+++ b/modules/reporting/app/models/cost_query/sql_statement.rb
@@ -89,10 +89,13 @@ class CostQuery::SqlStatement < Report::SqlStatement
query.select COMMON_FIELDS
query.desc = "Subquery for #{table}"
query.select({
- count: 1, id: [model, :id], display_costs: 1,
+ count: 1,
+ id: [model, :id],
+ display_costs: 1,
real_costs: switch("#{table}.overridden_costs IS NULL" => [model, :costs], else: [model, :overridden_costs]),
week: iso_year_week(field_name_for([model, :spent_on])),
- singleton_value: 1
+ singleton_value: 1,
+ entity_gid: "CONCAT('gid://#{GlobalID.app}/', #{table}.entity_type, '/', #{table}.entity_id)"
})
# FIXME: build this subquery from a sql_statement
query.from "(SELECT *, #{typed :text, model.model_name.to_s} AS type FROM #{table}) AS #{table}"
diff --git a/modules/reporting/spec/models/cost_query/group_by_spec.rb b/modules/reporting/spec/models/cost_query/group_by_spec.rb
index afab047e0d3..4c7d6a5d8bc 100644
--- a/modules/reporting/spec/models/cost_query/group_by_spec.rb
+++ b/modules/reporting/spec/models/cost_query/group_by_spec.rb
@@ -88,9 +88,8 @@ RSpec.describe CostQuery, :reporting_query_helper do
query.group_by :work_package_id
query.group_by :cost_type_id
expect(query.all_group_fields).to eq(%w[entries.cost_type_id])
- expect(query.child.all_group_fields).to eq(%w[entries.cost_type_id entries.entity_type entries.entity_id])
- expect(query.child.child.all_group_fields).to eq(%w[entries.cost_type_id entries.entity_type entries.entity_id
- entries.project_id])
+ expect(query.child.all_group_fields).to eq(%w[entries.cost_type_id entries.entity_gid])
+ expect(query.child.child.all_group_fields).to eq(%w[entries.cost_type_id entries.entity_gid entries.project_id])
end
it "computes group_by WorkPackage" do
diff --git a/modules/reporting/spec/models/cost_query/walker_spec.rb b/modules/reporting/spec/models/cost_query/walker_spec.rb
index 9981f7e352e..38b9cb82810 100644
--- a/modules/reporting/spec/models/cost_query/walker_spec.rb
+++ b/modules/reporting/spec/models/cost_query/walker_spec.rb
@@ -59,7 +59,7 @@ RSpec.describe CostQuery, :reporting_query_helper do
query.row :user_id
result = query.transformer.column_first.values.first
- %i[tweek entity_type entity_id].each do |field|
+ %i[tweek entity_gid].each do |field|
expect(result.fields).to include(field)
result = result.values.first
end