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

Fix links with edited opSetting:base_url in them

Christophe Bliard246ff4b14d06
diff --git a/lib/open_project/text_formatting/filters/setting_macros_filter.rb b/lib/open_project/text_formatting/filters/setting_macros_filter.rb
index 66d079c15e3..295dbd1513a 100644
--- a/lib/open_project/text_formatting/filters/setting_macros_filter.rb
+++ b/lib/open_project/text_formatting/filters/setting_macros_filter.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
@@ -37,6 +39,8 @@ module OpenProject::TextFormatting
def self.regexp
%r{
\{\{opSetting:(.+?)\}\}
+ |
+ https?://[^% ]+?/%7B%7BopSetting:(base_url)%7D%7D
}x
end
@@ -44,7 +48,7 @@ module OpenProject::TextFormatting
return html unless applicable?
html.gsub(self.class.regexp) do |matched_string|
- variable = $1.to_s
+ variable = ($1.presence || $2.presence).dup
variable.gsub!('\\', '')
if ALLOWED_SETTINGS.include?(variable)
@@ -72,7 +76,7 @@ module OpenProject::TextFormatting
##
# Faster inclusion check before the regex is being applied
def applicable?
- html.include?('{{opSetting:')
+ html.include?('{{opSetting:') || html.include?('%7B%7BopSetting:')
end
end
end
diff --git a/spec/features/homescreen/index_spec.rb b/spec/features/homescreen/index_spec.rb
index 4dbf15f2972..4fd76337a21 100644
--- a/spec/features/homescreen/index_spec.rb
+++ b/spec/features/homescreen/index_spec.rb
@@ -29,25 +29,45 @@
require 'spec_helper'
describe 'Homescreen index' do
- let!(:user) { build_stubbed(:user) }
+ let(:admin) { create(:admin) }
+ let(:user) { build_stubbed(:user) }
let!(:project) { create(:public_project, identifier: 'public-project') }
+ let(:general_settings_page) { Pages::Admin::SystemSettings::General.new }
- before do
- login_as user
- visit root_url
- end
+ describe 'with a dynamic URL in the welcome text' do
+ before do
+ Setting.welcome_text = "With [a link to the public project]({{opSetting:base_url}}/projects/public-project)"
+ Setting.welcome_on_homescreen = true
+ end
- describe 'with a dynamic URL in the welcome text',
- with_settings: {
- welcome_text: "With [a link to the public project]({{opSetting:base_url}}/projects/public-project)",
- welcome_on_homescreen?: true
- } do
it 'renders the correct link' do
+ login_as user
+ visit root_url
expect(page)
.to have_selector("a[href=\"#{OpenProject::Application.root_url}/projects/public-project\"]")
click_link "a link to the public project"
expect(page).to have_current_path project_path(project)
end
+
+ it 'can change the welcome text and still have a valid link', js: true do
+ login_as admin
+
+ general_settings_page.visit!
+
+ welcome_text_editor = general_settings_page.welcome_text_editor
+ scroll_to_element(welcome_text_editor.container)
+ welcome_text_editor.click_and_type_slowly('Hello! ')
+
+ general_settings_page.press_save_button
+ general_settings_page.expect_and_dismiss_toaster
+
+ visit root_url
+ expect(page)
+ .to have_selector("a[href=\"#{OpenProject::Application.root_url}/projects/public-project\"]")
+
+ click_link "a link to the public project"
+ expect(page).to have_current_path "#{project_path(project)}/"
+ end
end
end
diff --git a/spec/lib/open_project/text_formatting/markdown/setting_variable_spec.rb b/spec/lib/open_project/text_formatting/markdown/setting_variable_spec.rb
index e68f492b91c..c2155f7460b 100644
--- a/spec/lib/open_project/text_formatting/markdown/setting_variable_spec.rb
+++ b/spec/lib/open_project/text_formatting/markdown/setting_variable_spec.rb
@@ -43,6 +43,8 @@ describe OpenProject::TextFormatting,
[Link with setting]({{opSetting:base_url}}/foo/bar)
+ [Saved and transformed link with setting](http://localhost:3000/prefix/%7B%7BopSetting:base_url%7D%7D/foo/bar)
+
Inline reference to invalid variable: {{opSetting:smtp_password}}
Inline reference to missing variable: {{opSetting:does_not_exist}}
@@ -61,6 +63,10 @@ describe OpenProject::TextFormatting,
<a href="#{OpenProject::Application.root_url}/foo/bar" rel="noopener noreferrer"
class="op-uc-link">Link with setting</a>
</p>
+ <p class="op-uc-p">
+ <a href="#{OpenProject::Application.root_url}/foo/bar" rel="noopener noreferrer"
+ class="op-uc-link">Saved and transformed link with setting</a>
+ </p>
<p class="op-uc-p">
Inline reference to invalid variable: {{opSetting:smtp_password}}
</p>
diff --git a/spec/support/pages/admin/system_settings/general.rb b/spec/support/pages/admin/system_settings/general.rb
new file mode 100644
index 00000000000..a5c95462ebd
--- /dev/null
+++ b/spec/support/pages/admin/system_settings/general.rb
@@ -0,0 +1,54 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 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 'support/pages/page'
+
+module Pages::Admin::SystemSettings
+ class General < ::Pages::Page
+ def path
+ "/admin/settings/general"
+ end
+
+ def toast_type
+ :rails
+ end
+
+ def welcome_text_editor
+ Components::WysiwygEditor.new welcome_text_selector
+ end
+
+ def welcome_text_selector
+ 'ckeditor-augmented-textarea[textarea-selector="#settings_welcome_text"]'
+ end
+
+ def press_save_button
+ scroll_to(:bottom)
+ click_button('Save')
+ end
+ end
+end