diff --git a/app/controllers/alchemy/json_api/pages_controller.rb b/app/controllers/alchemy/json_api/pages_controller.rb index 0e7a72b..d97bf6d 100644 --- a/app/controllers/alchemy/json_api/pages_controller.rb +++ b/app/controllers/alchemy/json_api/pages_controller.rb @@ -8,6 +8,8 @@ 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 @@ -15,9 +17,9 @@ def index @pages = filtered_pages.result if !@pages.all?(&: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 diff --git a/app/models/alchemy/json_api/page.rb b/app/models/alchemy/json_api/page.rb index 4e68668..1a960d3 100644 --- a/app/models/alchemy/json_api/page.rb +++ b/app/models/alchemy/json_api/page.rb @@ -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 diff --git a/app/serializers/alchemy/json_api/page_serializer.rb b/app/serializers/alchemy/json_api/page_serializer.rb index 7015f54..d39c72e 100644 --- a/app/serializers/alchemy/json_api/page_serializer.rb +++ b/app/serializers/alchemy/json_api/page_serializer.rb @@ -14,6 +14,7 @@ class PageSerializer < BaseSerializer :language_code, :meta_keywords, :meta_description, + :public_on, :created_at, :updated_at, :restricted diff --git a/lib/alchemy/json_api.rb b/lib/alchemy/json_api.rb index b951893..c76fb9a 100644 --- a/lib/alchemy/json_api.rb +++ b/lib/alchemy/json_api.rb @@ -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 diff --git a/lib/alchemy/json_api/page_class_methods_extension.rb b/lib/alchemy/json_api/page_class_methods_extension.rb new file mode 100644 index 0000000..581358d --- /dev/null +++ b/lib/alchemy/json_api/page_class_methods_extension.rb @@ -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 diff --git a/spec/serializers/alchemy/json_api/page_serializer_spec.rb b/spec/serializers/alchemy/json_api/page_serializer_spec.rb index bf6eef6..7675758 100644 --- a/spec/serializers/alchemy/json_api/page_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/page_serializer_spec.rb @@ -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"])