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
[38606] Ensure we always use the english slug
Oliver Günther265e26a054c0
diff --git a/app/models/wiki.rb b/app/models/wiki.rbindex fec05dd7f09..f7d75c4815b 100644--- a/app/models/wiki.rb+++ b/app/models/wiki.rb@@ -67,7 +67,8 @@ class Wiki < ApplicationRecorddef find_page(title, options = {})title = start_page if title.blank?- page = pages.find_by(slug: WikiPage.slug(title))+ page = find_matching_slug(title)+if !page && !(options[:with_redirect] == false)# search for a redirectredirect = matching_redirect(title)@@ -76,6 +77,17 @@ class Wiki < ApplicationRecordpageend+ ##+ # Find a page by its slug+ # first trying the english slug, and then the slug for the default language+ # as that was previous behavior (cf., Bug OP#38606)+ def find_matching_slug(title)+ pages+ .where(slug: WikiPage.slug(title))+ .or(pages.where(slug: title.to_localized_slug(locale: Setting.default_language)))+ .first+ end+# Finds a page by title# The given string can be of one of the forms: "title" or "project:title"# Examples:diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rbindex b1c2787bf99..fc8f8ecacd3 100644--- a/app/models/wiki_page.rb+++ b/app/models/wiki_page.rb@@ -40,6 +40,7 @@ class WikiPage < ApplicationRecordurl_attribute: :slug,scope: :wiki_id, # Unique slugs per WIKIsync_url: true, # Keep slug updated on #rename+ locale: :en,adapter: OpenProject::ActsAsUrl::Adapter::OpActiveRecord # use a custom adapter able to handle edge casesacts_as_watchablediff --git a/lib/open_project/acts_as_url/adapter/op_active_record.rb b/lib/open_project/acts_as_url/adapter/op_active_record.rbindex fe775753582..c64a8842ccb 100644--- a/lib/open_project/acts_as_url/adapter/op_active_record.rb+++ b/lib/open_project/acts_as_url/adapter/op_active_record.rb@@ -56,7 +56,9 @@ module OpenProjectprivatedef modify_base_url- super+ root = instance.send(settings.attribute_to_urlify).to_s+ locale = configuration.settings.locale || :en+ self.base_url = root.to_localized_slug(locale: locale, **configuration.string_extensions_settings)modify_base_url_custom_rules if base_url.empty?enddiff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rbindex 73757814368..21f5b17be06 100644--- a/spec/models/wiki_page_spec.rb+++ b/spec/models/wiki_page_spec.rb@@ -85,6 +85,25 @@ describe WikiPage, type: :model do.to raise_error(ActiveRecord::RecordInvalid)endend++ context 'with another default language', with_settings: { default_language: 'de' } do+ let(:wiki_page) { FactoryBot.build(:wiki_page, wiki: wiki, title: 'Übersicht') }++ it 'will still use english slug methods' do+ expect(wiki_page.save).to eq true+ expect(wiki_page.slug).to eq 'ubersicht'+ end+ end++ context 'with another I18n.locale set', with_settings: { default_language: 'de' } do+ let(:wiki_page) { FactoryBot.build(:wiki_page, wiki: wiki, title: 'Übersicht') }++ it 'will still use english slug methods' do+ I18n.locale = :de+ expect(wiki_page.save).to eq true+ expect(wiki_page.slug).to eq 'ubersicht'+ end+ endenddescribe '#nearest_main_item' dodiff --git a/spec/models/wiki_spec.rb b/spec/models/wiki_spec.rbindex ca0dce4378c..837bb5a8bf8 100644--- a/spec/models/wiki_spec.rb+++ b/spec/models/wiki_spec.rb@@ -50,5 +50,28 @@ describe Wiki, type: :model doexpect(wiki.wiki_menu_items.first.title).to eq(start_page)endend++ describe '#find_page' do+ let(:wiki) { project.create_wiki start_page: start_page }+ let(:wiki_page) { FactoryBot.build(:wiki_page, wiki: wiki, title: 'Übersicht') }++ subject { wiki.find_page('Übersicht') }++ it 'will find the page using the title' do+ wiki_page.save!+ expect(wiki_page.slug).to eq 'ubersicht'+ expect(subject).to eq wiki_page+ end++ context 'with german default_language', with_settings: { default_language: 'de' } do+ it 'will find the page with the default_language slug title (Regression #38606)' do+ wiki_page.save!+ wiki_page.update_column(:slug, 'uebersicht')++ expect(wiki_page.reload.slug).to eq 'uebersicht'+ expect(subject).to eq wiki_page+ end+ end+ endendend