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
Use Static::Links.url_for helper more consistently
Jan Sandbrinkdc2bfa8948fb
diff --git a/app/components/enterprise_edition/upsell_buttons_component.rb b/app/components/enterprise_edition/upsell_buttons_component.rbindex 601ee298573..88c3260f2df 100644--- a/app/components/enterprise_edition/upsell_buttons_component.rb+++ b/app/components/enterprise_edition/upsell_buttons_component.rb@@ -114,8 +114,8 @@ module EnterpriseEditionenddef enterprise_link- href_value = OpenProject::Static::Links.links.dig(:enterprise_features, feature_key, :href)- default_value = OpenProject::Static::Links.links.dig(:enterprise_features, :default, :href)+ href_value = OpenProject::Static::Links.url_for(:enterprise_features, feature_key)+ default_value = OpenProject::Static::Links.url_for(:enterprise_features, :default)href_value || default_valueenddiff --git a/lib_static/redmine/i18n.rb b/lib_static/redmine/i18n.rbindex f9c1d5ab734..f51eef30427 100644--- a/lib_static/redmine/i18n.rb+++ b/lib_static/redmine/i18n.rb@@ -116,7 +116,13 @@ module Redminetranslation = ::I18n.t(i18n_key.to_s, locale:)result = translation.scan(link_regex).inject(translation) do |t, matches|link, text, key = matches- href = String(links[key.to_sym])+ link_reference = links[key.to_sym]+ href = case link_reference+ when Array+ OpenProject::Static::Links.url_for(*link_reference)+ else+ String(link_reference)+ endlink_tag = render(Primer::Beta::Link.new(href:, target:)) { text }t.sub(link, link_tag)diff --git a/spec/lib/open_project/static/links_spec.rb b/spec/lib/open_project/static/links_spec.rbnew file mode 100644index 00000000000..b970906e140--- /dev/null+++ b/spec/lib/open_project/static/links_spec.rb@@ -0,0 +1,43 @@+# 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.+#++++require "spec_helper"++RSpec.describe OpenProject::Static::Links do+ describe ".url_for" do+ subject { described_class.url_for(*args) }++ let(:args) { %i[enterprise_features board_view] }++ it "resolves the URL stored in the href" do+ expect(subject).to eq("https://www.openproject.org/docs/user-guide/agile-boards/#action-boards-enterprise-add-on")+ end+ end+enddiff --git a/spec/lib/redmine/i18n_spec.rb b/spec/lib/redmine/i18n_spec.rbindex 9713399fb89..08ab7f6175b 100644--- a/spec/lib/redmine/i18n_spec.rb+++ b/spec/lib/redmine/i18n_spec.rb@@ -194,7 +194,7 @@ module OpenProjectbefore doallow(::I18n).to receive(:t)- .with("translation_with_a_link", locale:)+ .with("translation_with_a_link", locale: anything).and_return("There is a [link](url_1) in this translation! Maybe even [two](url_2)?")end@@ -220,6 +220,27 @@ module OpenProjectexpect(I18n).to have_received(:t).with(anything, locale:)endend++ context "when passing URLs as a list of symbols" do+ let(:urls) do+ { url_1: [:a, :b], url_2: [:a, :c] }+ end++ before do+ allow(OpenProject::Static::Links).to receive(:url_for).and_return("/no-args")+ allow(OpenProject::Static::Links).to receive(:url_for).with(:a, :b).and_return("https://example.com/a-b")+ allow(OpenProject::Static::Links).to receive(:url_for).with(:a, :c).and_return("/a-c")+ end++ it "resolves the links from static links" do+ translated = link_translate :translation_with_a_link, links: urls++ expect(translated).to eq(+ 'There is a <a href="https://example.com/a-b" data-view-component="true" class="Link">link</a> in this' ++ ' translation! Maybe even <a href="/a-c" data-view-component="true" class="Link">two</a>?'+ )+ end+ endenddescribe "#format_date" do