Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose public_on date #73

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
6 changes: 4 additions & 2 deletions app/controllers/alchemy/json_api/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ class PagesController < JsonApi::BaseController

before_action :load_page_for_cache_key, only: :show

ALLOWED_PUBLIC_VERSION_RANSACK_ATTRIBUTES = %w[public_on].map { |a| "public_version_#{a}" }.freeze

def index
allowed = Alchemy::Page.ransackable_attributes

jsonapi_filter(page_scope, allowed) do |filtered_pages|
@pages = filtered_pages.result

if [email protected]?(&:cache_page?)
render_pages_json(allowed) && return
render_pages_json(allowed | ALLOWED_PUBLIC_VERSION_RANSACK_ATTRIBUTES) && return
elsif stale?(etag: etag(@pages))
render_pages_json(allowed)
render_pages_json(allowed | ALLOWED_PUBLIC_VERSION_RANSACK_ATTRIBUTES)
end
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/alchemy/json_api/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ def Page.ransackable_attributes(_auth_object = nil)
super | %w[page_layout]
end

def Page.ransackable_associations(_auth_object = nil)
super | %w[public_version]
end

module JsonApi
class Page < SimpleDelegator
attr_reader :page_version_type, :page_version
Expand Down
1 change: 1 addition & 0 deletions app/serializers/alchemy/json_api/page_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PageSerializer < BaseSerializer
:language_code,
:meta_keywords,
:meta_description,
:public_on,
:created_at,
:updated_at,
:restricted
Expand Down
1 change: 1 addition & 0 deletions lib/alchemy/json_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "fast_jsonapi"
require "alchemy_cms"
require "alchemy/json_api/engine"
require "alchemy/json_api/page_class_methods_extension"

module Alchemy
module JsonApi
Expand Down
14 changes: 14 additions & 0 deletions lib/alchemy/json_api/page_class_methods_extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true
module Alchemy
module JsonApi
module PageClassMethodsExtension
def ransackable_attributes(_auth_object = nil)
super | %w[page_layout]
end

def ransackable_associations(_auth_object = nil)
super | %w[public_version]
end
end
end
end
1 change: 1 addition & 0 deletions spec/serializers/alchemy/json_api/page_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
expect(attributes[:language_code]).to eq("en")
expect(attributes[:meta_keywords]).to eq("Meta Keywords")
expect(attributes[:meta_description]).to eq("Meta Description")
expect(attributes[:public_on]).to eq(page.public_on)
expect(attributes[:created_at]).to eq(page.created_at)
expect(attributes[:updated_at]).to eq(page.updated_at)
expect(attributes[:legacy_urls]).to eq(["/other"])
Expand Down
Loading