diff --git a/app/views/components/pageflow/admin/entry_translations_tab.rb b/app/views/components/pageflow/admin/entry_translations_tab.rb index 47858e380..6455ddbdb 100644 --- a/app/views/components/pageflow/admin/entry_translations_tab.rb +++ b/app/views/components/pageflow/admin/entry_translations_tab.rb @@ -29,6 +29,7 @@ def build(entry) end add_link(entry) + generate_link(entry) end private @@ -84,6 +85,17 @@ def add_link(entry) new_admin_entry_translation_path(entry), class: 'button')) end + + def generate_link(entry) + return unless authorized?(:manage_translations, entry) + entry_translator_url = Pageflow.config_for(entry).entry_translator_url + return if entry_translator_url.blank? + + text_node(link_to(t('pageflow.admin.entry_translations.generate'), + entry_translator_url.call(entry), + class: 'button', + style: "margin-left: 8px")) + end end end end diff --git a/config/locales/new/entry_translations.de.yml b/config/locales/new/entry_translations.de.yml index 994ffc6e4..9e204a105 100644 --- a/config/locales/new/entry_translations.de.yml +++ b/config/locales/new/entry_translations.de.yml @@ -5,6 +5,7 @@ de: translations: Übersetzungen entry_translations: add: Übersetzung zuordnen + generate: Übersetzung generieren entry_id: Beitrag id: Übersetzung(en) new_hint_html: |- diff --git a/config/locales/new/entry_translations.en.yml b/config/locales/new/entry_translations.en.yml index d4092bf77..de6dd32c7 100644 --- a/config/locales/new/entry_translations.en.yml +++ b/config/locales/new/entry_translations.en.yml @@ -5,6 +5,7 @@ en: translations: Translations entry_translations: add: Link translation + generate: Generate translation entry_id: Entry id: Translation(s) new_hint_html: |- diff --git a/lib/pageflow/configuration.rb b/lib/pageflow/configuration.rb index 851730bfb..05af75a8b 100644 --- a/lib/pageflow/configuration.rb +++ b/lib/pageflow/configuration.rb @@ -425,6 +425,8 @@ class Configuration # @since 12.2 attr_accessor :news + attr_accessor :entry_translator_url + def initialize(target_type_name = nil) @target_type_name = target_type_name @@ -618,6 +620,7 @@ def enable_all_features delegate :public_entry_cache_control_header=, to: :config delegate :additional_public_entry_headers, to: :config delegate :cutoff_modes, to: :config + delegate :entry_translator_url=, to: :config delegate :for_entry_type, to: :config end diff --git a/spec/views/components/pageflow/admin/entry_translations_tab_spec.rb b/spec/views/components/pageflow/admin/entry_translations_tab_spec.rb index 905abff91..d146096c5 100644 --- a/spec/views/components/pageflow/admin/entry_translations_tab_spec.rb +++ b/spec/views/components/pageflow/admin/entry_translations_tab_spec.rb @@ -25,6 +25,23 @@ module Pageflow expect(rendered).to have_selector('a', text: 'Mark as default') end + it 'renders a link to entry translator url' do + pageflow_configure do |config| + config.entry_translator_url = lambda do |entry| + "http://example.com?entry_id=#{entry.id}" + end + end + + de_entry = create(:entry, draft_attributes: {locale: 'de'}) + + allow(helper).to receive(:authorized?).and_return(true) + + render(de_entry) + + expect(rendered).to have_selector('a', text: 'Generate translation') + expect(rendered).to have_selector("a[href='http://example.com?entry_id=#{de_entry.id}']") + end + it 'includes self in table without link' do de_entry = create(:entry, title: 'My story DE', draft_attributes: {locale: 'de'}) en_entry = create(:entry, title: 'My story EN', draft_attributes: {locale: 'en'}) @@ -67,6 +84,28 @@ module Pageflow expect(rendered).to have_selector('a', text: 'Mark as default') end + it 'hides generate link by default' do + de_entry = create(:entry, draft_attributes: {locale: 'de'}) + + allow(helper).to receive(:authorized?).and_return(true) + + render(de_entry) + + expect(rendered).not_to have_selector('a', text: 'Generate translation') + end + + it 'hides generate link if user cannot manage translations' do + de_entry = create(:entry, draft_attributes: {locale: 'de'}) + + allow(helper).to receive(:authorized?).and_return(true) + allow(helper) + .to receive(:authorized?).with(:manage_translations, de_entry).and_return(false) + + render(de_entry) + + expect(rendered).not_to have_selector('a', text: 'Generate translation') + end + it 'hides remove and add links if user cannot manage translations' do de_entry = create(:entry, draft_attributes: {locale: 'de'}) en_entry = create(:entry, title: 'My story EN', draft_attributes: {locale: 'en'})