alchemy-json_api 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -0
  3. data/app/controllers/alchemy/json_api/admin/layout_pages_controller.rb +1 -0
  4. data/app/controllers/alchemy/json_api/admin/pages_controller.rb +7 -2
  5. data/app/controllers/alchemy/json_api/base_controller.rb +3 -2
  6. data/app/controllers/alchemy/json_api/layout_pages_controller.rb +1 -0
  7. data/app/controllers/alchemy/json_api/nodes_controller.rb +3 -3
  8. data/app/controllers/alchemy/json_api/pages_controller.rb +27 -19
  9. data/app/serializers/alchemy/json_api/element_serializer.rb +2 -1
  10. data/app/serializers/alchemy/json_api/ingredient_audio_serializer.rb +1 -1
  11. data/app/serializers/alchemy/json_api/ingredient_picture_serializer.rb +4 -4
  12. data/app/serializers/alchemy/json_api/ingredient_richtext_serializer.rb +1 -1
  13. data/app/serializers/alchemy/json_api/ingredient_text_serializer.rb +1 -1
  14. data/app/serializers/alchemy/json_api/ingredient_video_serializer.rb +1 -1
  15. data/app/serializers/alchemy/json_api/language_serializer.rb +2 -1
  16. data/app/serializers/alchemy/json_api/node_serializer.rb +2 -1
  17. data/app/serializers/alchemy/json_api/page_serializer.rb +2 -1
  18. data/config/routes.rb +5 -4
  19. data/lib/alchemy/json_api/engine.rb +1 -0
  20. data/lib/alchemy/json_api/essence_serializer.rb +1 -0
  21. data/lib/alchemy/json_api/test_support/essence_serializer_behaviour.rb +3 -2
  22. data/lib/alchemy/json_api/test_support/ingredient_serializer_behaviour.rb +1 -1
  23. data/lib/alchemy/json_api/version.rb +2 -1
  24. data/lib/tasks/alchemy/json_api_tasks.rake +1 -0
  25. metadata +13 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4da501de3e83d19a9226ed5cba95c5ee4026c0931997070daaa55aabc4357c3
4
- data.tar.gz: 7a4c15a0d2186d2a3b62badf8817ccc2f16ffc4bd8fcea8dc2b88adfc2099b16
3
+ metadata.gz: 89edfe1ba595351698467e746b9451be8483071b6e4878fd9ef30c6cd062011a
4
+ data.tar.gz: 5cdbc986b5eeae3dadfb7dd8f5beb6fc2632a5766131ac7b12e50b2595062e11
5
5
  SHA512:
6
- metadata.gz: 19a29387ac8c5e087bb1ad8f04e162af62c4f0c05f6481d3579fa0b415dca569517c7a3e5a763c17aff0d3f6fe0cb1bda913156b7be3b51900724af3f713516a
7
- data.tar.gz: 7800110a1df4d98a6e96184420316be08ba8c43a25690ce6f6a29f29191505055f344cf0f80523e06221796a344f4b58bd4a1da169fc1dc2da4a384ef3085817
6
+ metadata.gz: 0cc256eb440f91369407d301410674cd7703a84bc28704e4ae220c32ee69d6cc6984f84bf53b6ec9d45c29b203381f30173292ef384b200aed95ab89aff96b12
7
+ data.tar.gz: e67fb531194df5b8b457f5cbdeadedd78e04cf5f2adfdb86ded3ec4a0eb8081e858bdff63a59b9f1a71ea81d87cae99e81526affcbb234985108d9b9d207b62b
data/Rakefile CHANGED
@@ -12,6 +12,7 @@ RSpec::Core::RakeTask.new(:spec)
12
12
 
13
13
  task default: [:test_setup, :spec]
14
14
 
15
+ require "active_support"
15
16
  require "active_support/core_ext/string"
16
17
 
17
18
  desc "Setup test app"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Alchemy
3
4
  module JsonApi
4
5
  module Admin
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Alchemy
3
4
  module JsonApi
4
5
  module Admin
@@ -13,11 +14,15 @@ module Alchemy
13
14
  end
14
15
 
15
16
  def caching_options
16
- { public: false, must_revalidate: true }
17
+ {public: false, must_revalidate: true}
17
18
  end
18
19
 
19
20
  def set_current_preview
20
- Alchemy::Page.current_preview = @page
21
+ if Alchemy.const_defined?(:Current)
22
+ Alchemy::Current.preview_page = @page
23
+ else
24
+ Alchemy::Page.current_preview = @page
25
+ end
21
26
  end
22
27
 
23
28
  def last_modified_for(page)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Alchemy
3
4
  module JsonApi
4
5
  class BaseController < ::ApplicationController
@@ -11,7 +12,7 @@ module Alchemy
11
12
 
12
13
  rescue_from(
13
14
  CanCan::AccessDenied,
14
- with: :render_jsonapi_unauthorized,
15
+ with: :render_jsonapi_unauthorized
15
16
  )
16
17
 
17
18
  private
@@ -32,7 +33,7 @@ module Alchemy
32
33
  end
33
34
 
34
35
  def render_jsonapi_unauthorized(exception)
35
- error = { status: "401", title: Rack::Utils::HTTP_STATUS_CODES[401] }
36
+ error = {status: "401", title: Rack::Utils::HTTP_STATUS_CODES[401]}
36
37
  render jsonapi_errors: [error], status: :unauthorized
37
38
  end
38
39
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Alchemy
3
4
  module JsonApi
4
5
  class LayoutPagesController < JsonApi::PagesController
@@ -11,7 +11,7 @@ module Alchemy
11
11
  end
12
12
  end
13
13
 
14
- expires_in cache_duration, { public: true, must_revalidate: true }
14
+ expires_in cache_duration, {public: true, must_revalidate: true}
15
15
  end
16
16
 
17
17
  private
@@ -25,7 +25,7 @@ module Alchemy
25
25
 
26
26
  {
27
27
  pagination: pagination.presence,
28
- total: node_scope.count,
28
+ total: node_scope.count
29
29
  }.compact
30
30
  end
31
31
 
@@ -37,7 +37,7 @@ module Alchemy
37
37
  if params[:include].present?
38
38
  includes = params[:include].split(",").map do |association|
39
39
  association.split(".").reverse.inject({}) do |value, key|
40
- { key.to_sym => value }
40
+ {key.to_sym => value}
41
41
  end
42
42
  end
43
43
  node_scope.includes(includes)
@@ -12,12 +12,12 @@ module Alchemy
12
12
  @pages = filtered_pages.result
13
13
  if !@pages.all?(&:cache_page?)
14
14
  render_pages_json(allowed) && return
15
- elsif stale?(last_modified: @pages.maximum(:published_at), etag: @pages.max_by(&:cache_key)&.cache_key)
15
+ elsif stale?(last_modified: @pages.maximum(:published_at), etag: @pages.max_by(&:cache_key_with_version)&.cache_key_with_version)
16
16
  render_pages_json(allowed)
17
17
  end
18
18
  end
19
19
 
20
- expires_in cache_duration, { public: @pages.none?(&:restricted?) }.merge(caching_options)
20
+ expires_in cache_duration, {public: @pages.none?(&:restricted?)}.merge(caching_options)
21
21
  end
22
22
 
23
23
  def show
@@ -25,12 +25,12 @@ module Alchemy
25
25
  render(jsonapi: api_page(load_page)) && return
26
26
  end
27
27
 
28
- if stale?(last_modified: last_modified_for(@page), etag: @page.cache_key)
28
+ if stale?(last_modified: last_modified_for(@page), etag: @page.cache_key_with_version)
29
29
  # Only load page with all includes when browser cache is stale
30
30
  render jsonapi: api_page(load_page)
31
31
  end
32
32
 
33
- expires_in cache_duration, { public: !@page.restricted? }.merge(caching_options)
33
+ expires_in cache_duration, {public: !@page.restricted?}.merge(caching_options)
34
34
  end
35
35
 
36
36
  private
@@ -51,13 +51,13 @@ module Alchemy
51
51
  end
52
52
 
53
53
  def caching_options
54
- { must_revalidate: true }
54
+ {must_revalidate: true}
55
55
  end
56
56
 
57
57
  # Get page w/o includes to get cache key
58
58
  def load_page_for_cache_key
59
- @page = page_scope.where(id: params[:path]).
60
- or(page_scope.where(urlname: params[:path])).first!
59
+ @page = page_scope.where(id: params[:path])
60
+ .or(page_scope.where(urlname: params[:path])).first!
61
61
  end
62
62
 
63
63
  def last_modified_for(page)
@@ -69,7 +69,7 @@ module Alchemy
69
69
 
70
70
  {
71
71
  pagination: pagination.presence,
72
- total: page_scope.count,
72
+ total: page_scope.count
73
73
  }.compact
74
74
  end
75
75
 
@@ -78,7 +78,7 @@ module Alchemy
78
78
  end
79
79
 
80
80
  def load_page_by_id
81
- return unless params[:path] =~ /\A\d+\z/
81
+ return unless /\A\d+\z/.match?(params[:path])
82
82
 
83
83
  page_scope_with_includes.find_by(id: params[:path])
84
84
  end
@@ -92,20 +92,20 @@ module Alchemy
92
92
  end
93
93
 
94
94
  def page_scope_with_includes
95
- page_scope.
96
- includes(
95
+ page_scope
96
+ .includes(
97
97
  [
98
98
  :legacy_urls,
99
- { language: { nodes: [:parent, :children, { page: { language: { site: :languages } } }] } },
99
+ {language: {nodes: [:parent, :children, {page: {language: {site: :languages}}}]}},
100
100
  {
101
101
  page_version_type => {
102
102
  elements: [
103
103
  :nested_elements,
104
- { ingredients: :related_object },
105
- ],
106
- },
107
- },
108
- ],
104
+ {ingredients: :related_object}
105
+ ]
106
+ }
107
+ }
108
+ ]
109
109
  )
110
110
  end
111
111
 
@@ -120,9 +120,17 @@ module Alchemy
120
120
  def base_page_scope
121
121
  # cancancan is not able to merge our complex AR scopes for logged in users
122
122
  if can?(:edit_content, ::Alchemy::Page)
123
- Alchemy::Language.current.pages.joins(page_version_type)
123
+ current_language.pages.joins(page_version_type)
124
124
  else
125
- Alchemy::Language.current.pages.published.joins(page_version_type)
125
+ current_language.pages.published.joins(page_version_type)
126
+ end
127
+ end
128
+
129
+ def current_language
130
+ if Alchemy.const_defined?(:Current)
131
+ Alchemy::Current.language
132
+ else
133
+ Alchemy::Language.current
126
134
  end
127
135
  end
128
136
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Alchemy
3
4
  module JsonApi
4
5
  class ElementSerializer < BaseSerializer
@@ -7,7 +8,7 @@ module Alchemy
7
8
  :fixed,
8
9
  :position,
9
10
  :created_at,
10
- :updated_at,
11
+ :updated_at
11
12
  )
12
13
 
13
14
  cache_options store: Rails.cache, namespace: "alchemy-jsonapi"
@@ -11,7 +11,7 @@ module Alchemy
11
11
  :autoplay,
12
12
  :controls,
13
13
  :muted,
14
- :loop,
14
+ :loop
15
15
  )
16
16
 
17
17
  attribute :value do |ingredient|
@@ -12,7 +12,7 @@ module Alchemy
12
12
  :caption,
13
13
  :link_class_name,
14
14
  :link_title,
15
- :link_target,
15
+ :link_target
16
16
  )
17
17
 
18
18
  attribute :value do |ingredient|
@@ -26,7 +26,7 @@ module Alchemy
26
26
  attribute :image_dimensions do |ingredient|
27
27
  sizes = ingredient.settings[:size]&.split("x", 2)&.map(&:to_i) || [
28
28
  ingredient.image_file_width,
29
- ingredient.image_file_height,
29
+ ingredient.image_file_height
30
30
  ]
31
31
 
32
32
  ratio = ingredient.image_file_width.to_f / ingredient.image_file_height
@@ -35,7 +35,7 @@ module Alchemy
35
35
 
36
36
  {
37
37
  width: width,
38
- height: height,
38
+ height: height
39
39
  }
40
40
  end
41
41
 
@@ -58,7 +58,7 @@ module Alchemy
58
58
  desc: "#{width}w",
59
59
  width: width,
60
60
  height: height,
61
- type: type.to_s,
61
+ type: type.to_s
62
62
  }
63
63
  end
64
64
  end
@@ -9,7 +9,7 @@ module Alchemy
9
9
 
10
10
  attributes(
11
11
  :sanitized_body,
12
- :stripped_body,
12
+ :stripped_body
13
13
  )
14
14
 
15
15
  attribute :body, &:value
@@ -11,7 +11,7 @@ module Alchemy
11
11
  :link,
12
12
  :link_class_name,
13
13
  :link_target,
14
- :link_title,
14
+ :link_title
15
15
  )
16
16
 
17
17
  # maintain compatibility with EssenceText
@@ -13,7 +13,7 @@ module Alchemy
13
13
  :allow_fullscreen,
14
14
  :autoplay,
15
15
  :controls,
16
- :preload,
16
+ :preload
17
17
  )
18
18
 
19
19
  attribute :value do |ingredient|
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Alchemy
3
4
  module JsonApi
4
5
  class LanguageSerializer < BaseSerializer
@@ -6,7 +7,7 @@ module Alchemy
6
7
  :name,
7
8
  :language_code,
8
9
  :country_code,
9
- :locale,
10
+ :locale
10
11
  )
11
12
 
12
13
  has_many :menu_items, record_type: :node, serializer: ::Alchemy::JsonApi::NodeSerializer, object_method_name: :nodes, id_method_name: :node_ids
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Alchemy
3
4
  module JsonApi
4
5
  class NodeSerializer < BaseSerializer
@@ -13,7 +14,7 @@ module Alchemy
13
14
  :page,
14
15
  record_type: :page,
15
16
  if: ->(node) { node.page },
16
- serializer: ::Alchemy::JsonApi::PageSerializer,
17
+ serializer: ::Alchemy::JsonApi::PageSerializer
17
18
  ) do |node|
18
19
  ::Alchemy::JsonApi::Page.new(node.page)
19
20
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Alchemy
3
4
  module JsonApi
4
5
  class PageSerializer < BaseSerializer
@@ -14,7 +15,7 @@ module Alchemy
14
15
  :meta_keywords,
15
16
  :meta_description,
16
17
  :created_at,
17
- :updated_at,
18
+ :updated_at
18
19
  )
19
20
 
20
21
  cache_options store: Rails.cache, namespace: "alchemy-jsonapi"
data/config/routes.rb CHANGED
@@ -1,14 +1,15 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Alchemy::JsonApi::Engine.routes.draw do
3
4
  resources :pages, only: [:index]
4
- get "pages/*path" => "pages#show", as: :page
5
+ get "pages/*path" => "pages#show", :as => :page
5
6
  resources :layout_pages, only: [:index]
6
- get "layout_pages/*path" => "layout_pages#show", as: :layout_page
7
+ get "layout_pages/*path" => "layout_pages#show", :as => :layout_page
7
8
  resources :nodes, only: [:index]
8
9
 
9
10
  namespace :admin do
10
- get "pages/*path" => "pages#show", as: :page
11
+ get "pages/*path" => "pages#show", :as => :page
11
12
  resources :layout_pages, only: [:index]
12
- get "layout_pages/*path" => "layout_pages#show", as: :layout_page
13
+ get "layout_pages/*path" => "layout_pages#show", :as => :layout_page
13
14
  end
14
15
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "jsonapi"
3
4
 
4
5
  module Alchemy
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Alchemy
3
4
  module JsonApi
4
5
  module EssenceSerializer
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  RSpec.shared_examples "an essence serializer" do
3
4
  describe "attributes" do
4
5
  subject { serializer.serializable_hash[:data][:attributes] }
@@ -15,7 +16,7 @@ RSpec.shared_examples "an essence serializer" do
15
16
  expect(content).to receive(:definition).at_least(:once) do
16
17
  {
17
18
  name: "intro",
18
- deprecated: true,
19
+ deprecated: true
19
20
  }
20
21
  end
21
22
  end
@@ -30,7 +31,7 @@ RSpec.shared_examples "an essence serializer" do
30
31
  subject { serializer.serializable_hash[:data][:relationships] }
31
32
 
32
33
  it "has the right keys and values" do
33
- expect(subject[:element]).to eq(data: { id: essence.element.id.to_s, type: :element })
34
+ expect(subject[:element]).to eq(data: {id: essence.element.id.to_s, type: :element})
34
35
  end
35
36
  end
36
37
  end
@@ -31,7 +31,7 @@ RSpec.shared_examples "an ingredient serializer" do
31
31
  subject { serializer.serializable_hash[:data][:relationships] }
32
32
 
33
33
  it "has one element" do
34
- expect(subject[:element]).to eq(data: { id: ingredient.element_id.to_s, type: :element })
34
+ expect(subject[:element]).to eq(data: {id: ingredient.element_id.to_s, type: :element})
35
35
  end
36
36
  end
37
37
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Alchemy
3
4
  module JsonApi
4
- VERSION = "2.0.1"
5
+ VERSION = "2.1.0"
5
6
  end
6
7
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # desc "Explaining what the task does"
3
4
  # task :alchemy_json_api do
4
5
  # # Task goes here
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemy-json_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-07-18 00:00:00.000000000 Z
12
+ date: 2024-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: alchemy_cms
@@ -35,16 +35,22 @@ dependencies:
35
35
  name: jsonapi.rb
36
36
  requirement: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.0
41
+ - - "<"
39
42
  - !ruby/object:Gem::Version
40
- version: '1.6'
43
+ version: '2.1'
41
44
  type: :runtime
42
45
  prerelease: false
43
46
  version_requirements: !ruby/object:Gem::Requirement
44
47
  requirements:
45
- - - "~>"
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.6.0
51
+ - - "<"
46
52
  - !ruby/object:Gem::Version
47
- version: '1.6'
53
+ version: '2.1'
48
54
  - !ruby/object:Gem::Dependency
49
55
  name: factory_bot
50
56
  requirement: !ruby/object:Gem::Requirement
@@ -179,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
185
  - !ruby/object:Gem::Version
180
186
  version: '0'
181
187
  requirements: []
182
- rubygems_version: 3.4.15
188
+ rubygems_version: 3.5.9
183
189
  signing_key:
184
190
  specification_version: 4
185
191
  summary: A JSONAPI compliant API for AlchemyCMS