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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
add project id of project embeds to macro node, so frontend does not need to search; Closes https://github.com/opf/openproject/pull/16542#discussion_r1736053003
as-opb10caed5b3c8
diff --git a/lib/open_project/text_formatting/matchers/attribute_macros.rb b/lib/open_project/text_formatting/matchers/attribute_macros.rbindex 81aecdeae09..9d21b035a0c 100644--- a/lib/open_project/text_formatting/matchers/attribute_macros.rb+++ b/lib/open_project/text_formatting/matchers/attribute_macros.rb@@ -53,11 +53,21 @@ module OpenProject::TextFormattingenddef self.work_package_context?(context)+ # workPackageValue can be used in e.g. wiki and meeting notes without a work package,+ # relative embedding is not supported in these casescontext[:object].is_a?(WorkPackage) || context[:object].is_a?(API::V3::WorkPackages::WorkPackageEagerLoadingWrapper)end- def self.relative_work_package_embed?(macro_attributes)- macro_attributes[:id].nil? && macro_attributes[:model] == "workPackage"+ def self.work_package_embed?(macro_attributes)+ macro_attributes[:model] == "workPackage"+ end++ def self.project_embed?(macro_attributes)+ macro_attributes[:model] == "project"+ end++ def self.relative_embed?(macro_attributes)+ macro_attributes[:id].nil?enddef self.process_match(match, _matched_string, context)@@ -69,11 +79,12 @@ module OpenProject::TextFormatting}type = match[2].downcase- # If no ID is given, try to use the current work package ID if applicable- # workPackageValue can be used in e.g. wiki and meeting notes without a work package,- # relative embedding is not supported in these cases- if relative_work_package_embed?(macro_attributes) && work_package_context?(context)- macro_attributes[:id] = context[:object].try(:id)+ if relative_embed?(macro_attributes)+ if project_embed?(macro_attributes) && context[:project].present?+ macro_attributes[:id] = context[:project].try(:id)+ elsif work_package_embed?(macro_attributes) && work_package_context?(context)+ macro_attributes[:id] = context[:object].try(:id)+ endendApplicationController.helpers.content_tag "opce-macro-attribute-#{type}",diff --git a/spec/lib/open_project/text_formatting/markdown/attribute_macros_spec.rb b/spec/lib/open_project/text_formatting/markdown/attribute_macros_spec.rbindex 23c7ff244cd..476ed7156a0 100644--- a/spec/lib/open_project/text_formatting/markdown/attribute_macros_spec.rb+++ b/spec/lib/open_project/text_formatting/markdown/attribute_macros_spec.rb@@ -32,7 +32,7 @@ require_relative "expected_markdown"RSpec.describe OpenProject::TextFormatting,"Attribute macros" doinclude_context "expected markdown modules"- shared_let(:project) { create(:valid_project) }+ shared_let(:project) { create(:valid_project, id: 4321) }let(:work_package) { create(:work_package, project:, id: 1234) }let(:options) { { project:, object: work_package } }@@ -50,7 +50,9 @@ RSpec.describe OpenProject::TextFormatting,Inline reference to project: projectLabel:status- Inline reference to project with id: projectLabel:"some id":status+ Inline reference to project with id: projectLabel:4321:status++ Inline reference to project with name: projectLabel:"some name":statusRAWend@@ -70,10 +72,13 @@ RSpec.describe OpenProject::TextFormatting,Inline reference to WP by subject: <opce-macro-attribute-label data-model="workPackage" data-id="Some subject" data-attribute="Some custom field with spaces"></opce-macro-attribute-label></p><p class="op-uc-p">- Inline reference to project: <opce-macro-attribute-label data-model="project" data-attribute="status"></opce-macro-attribute-label>+ Inline reference to project: <opce-macro-attribute-label data-model="project" data-id="4321" data-attribute="status"></opce-macro-attribute-label>+ </p>+ <p class="op-uc-p">+ Inline reference to project with id: <opce-macro-attribute-label data-model="project" data-id="4321" data-attribute="status"></opce-macro-attribute-label></p><p class="op-uc-p">- Inline reference to project with id: <opce-macro-attribute-label data-model="project" data-id="some id" data-attribute="status"></opce-macro-attribute-label>+ Inline reference to project with name: <opce-macro-attribute-label data-model="project" data-id="some name" data-attribute="status"></opce-macro-attribute-label></p>EXPECTEDend@@ -94,7 +99,9 @@ RSpec.describe OpenProject::TextFormatting,Inline reference to project: projectValue:status- Inline reference to project with id: projectValue:"some id":status+ Inline reference to project with id: projectValue:4321:status++ Inline reference to project with name: projectValue:"some name":statusRAWend@@ -114,10 +121,13 @@ RSpec.describe OpenProject::TextFormatting,Inline reference to WP by subject: <opce-macro-attribute-value data-model="workPackage" data-id="Some subject" data-attribute="Some custom field with spaces"></opce-macro-attribute-value></p><p class="op-uc-p">- Inline reference to project: <opce-macro-attribute-value data-model="project" data-attribute="status"></opce-macro-attribute-value>+ Inline reference to project: <opce-macro-attribute-value data-model="project" data-id="4321" data-attribute="status"></opce-macro-attribute-value>+ </p>+ <p class="op-uc-p">+ Inline reference to project with id: <opce-macro-attribute-value data-model="project" data-id="4321" data-attribute="status"></opce-macro-attribute-value></p><p class="op-uc-p">- Inline reference to project with id: <opce-macro-attribute-value data-model="project" data-id="some id" data-attribute="status"></opce-macro-attribute-value>+ Inline reference to project with name: <opce-macro-attribute-value data-model="project" data-id="some name" data-attribute="status"></opce-macro-attribute-value></p>EXPECTEDend