Skip to content

Commit

Permalink
Respect Language public status for Page public status
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
tvdeyen committed Feb 5, 2021
1 parent b104a21 commit 8ebda55
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/alchemy/page/page_natures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/models/alchemy/page/page_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8ebda55

Please sign in to comment.