From 8ebda550d394c033faf525d064e88611b0c9920c Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 5 Feb 2021 17:03:27 +0100 Subject: [PATCH] Respect Language public status for Page public status A page is only considered public if the language is also public. This is always the case for the default language, because there cannot be at least one public default language (assurred in the language validations). --- app/models/alchemy/page/page_natures.rb | 2 +- app/models/alchemy/page/page_scopes.rb | 1 + spec/models/alchemy/page_spec.rb | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/models/alchemy/page/page_natures.rb b/app/models/alchemy/page/page_natures.rb index f5a8e06f61..7242d8a812 100644 --- a/app/models/alchemy/page/page_natures.rb +++ b/app/models/alchemy/page/page_natures.rb @@ -6,7 +6,7 @@ module Page::PageNatures def public? current_time = Time.current - already_public_for?(current_time) && still_public_for?(current_time) + language.public? && already_public_for?(current_time) && still_public_for?(current_time) end def expiration_time diff --git a/app/models/alchemy/page/page_scopes.rb b/app/models/alchemy/page/page_scopes.rb index 8f6255750b..0b55cca544 100644 --- a/app/models/alchemy/page/page_scopes.rb +++ b/app/models/alchemy/page/page_scopes.rb @@ -96,6 +96,7 @@ module ClassMethods # All public pages # def published + joins(:language).merge(Language.published). where("#{table_name}.public_on <= :time AND " \ "(#{table_name}.public_until IS NULL " \ "OR #{table_name}.public_until >= :time)", time: Time.current) diff --git a/spec/models/alchemy/page_spec.rb b/spec/models/alchemy/page_spec.rb index 92d0b771a2..698d59e588 100644 --- a/spec/models/alchemy/page_spec.rb +++ b/spec/models/alchemy/page_spec.rb @@ -558,11 +558,14 @@ class AnotherUrlPathClass; end let!(:public_one) { create(:alchemy_page, :public) } let!(:public_two) { create(:alchemy_page, :public) } let!(:non_public_page) { create(:alchemy_page) } + let!(:page_with_non_public_language) { create(:alchemy_page, :public, language: non_public_language) } + let(:non_public_language) { create(:alchemy_language, :german, public: false) } it "returns public available pages" do expect(published).to include(public_one) expect(published).to include(public_two) expect(published).to_not include(non_public_page) + expect(published).to_not include(page_with_non_public_language) end end @@ -1314,6 +1317,13 @@ class AnotherUrlPathClass; end it { is_expected.to be(false) } end + + context "when language is not public" do + let(:language) { create(:alchemy_language, public: false, default: false) } + let(:page) { create(:alchemy_page, :public, language: language) } + + it { is_expected.to be(false) } + end end describe "#publish!" do