alchemy-json_api 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8800ea751939b672e2361001cffe2d0da220a6ee61b25c6728c0e0a8db3ca9b
4
- data.tar.gz: b9a7baa74ef2e0336aa91ad20f03ef26cb8f85c258caa1faf0b8a0c03d665a6f
3
+ metadata.gz: 00a9cfebbdb1f42b95a9b199bb23b5690ba65ff21b14a95e260beff9dafe1d1e
4
+ data.tar.gz: 0ce06ce3e137b56e40f5c8c08d895eb5f2eca7cc0936ed07c07cc2d6352530e5
5
5
  SHA512:
6
- metadata.gz: 3bbefcf52e8b02cad76158b312945bc1a818df8427b658898073bd7cdb8ef09a8d594bb33db0b0d5bcd2a4a9a7b4bd532d2d14a5c5c59f65cd8bbb880394232b
7
- data.tar.gz: e4a795e0ac64b11930b10d1f582339326f79b9695863930aa69856e93c8ff41f76341710e13dad70074b85fc4a99453605d2725585525c1816fcda19f877c3af
6
+ metadata.gz: 87723e7055f3968a0a1d75b6d133e2fc0a3a8efeb5b61e222771e91c673e9313052a3e154280a01c2beaa9f49144c90da9ecb6d05282987943ea2e9d06b0de7b
7
+ data.tar.gz: c2694da5d297f1acbbb16ed9a59858e5c84504091d430e82019e77aaae14549cb9b6e4d59ceee0a38b03e37f98162ea4881d2518e387b074cdd02e3c38bf8a1b
@@ -2,11 +2,11 @@
2
2
  module Alchemy
3
3
  module JsonApi
4
4
  module Admin
5
- class LayoutPagesController < PagesController
5
+ class LayoutPagesController < JsonApi::Admin::PagesController
6
6
  private
7
7
 
8
8
  def page_scope
9
- page_scope_with_includes(page_version: :draft_version).layoutpages
9
+ page_scope_with_includes.layoutpages
10
10
  end
11
11
  end
12
12
  end
@@ -5,14 +5,10 @@ module Alchemy
5
5
  class PagesController < JsonApi::PagesController
6
6
  prepend_before_action { authorize! :edit_content, Alchemy::Page }
7
7
 
8
- def show
9
- render jsonapi: Alchemy::JsonApi::Page.new(@page, page_version: :draft_version)
10
- end
11
-
12
8
  private
13
9
 
14
- def page_scope
15
- page_scope_with_includes(page_version: :draft_version).contentpages
10
+ def page_version_type
11
+ :draft_version
16
12
  end
17
13
  end
18
14
  end
@@ -10,7 +10,7 @@ module Alchemy
10
10
 
11
11
  jsonapi_filter(page_scope, allowed) do |filtered|
12
12
  # decorate with our page model that has a eager loaded elements collection
13
- pages = filtered.result.map { |p| Alchemy::JsonApi::Page.new(p) }
13
+ pages = filtered.result.map { |page| api_page(page) }
14
14
  jsonapi_paginate(pages) do |paginated|
15
15
  render jsonapi: paginated
16
16
  end
@@ -18,7 +18,7 @@ module Alchemy
18
18
  end
19
19
 
20
20
  def show
21
- render jsonapi: Alchemy::JsonApi::Page.new(@page)
21
+ render jsonapi: api_page(@page)
22
22
  end
23
23
 
24
24
  private
@@ -49,7 +49,7 @@ module Alchemy
49
49
  page_scope_with_includes.contentpages
50
50
  end
51
51
 
52
- def page_scope_with_includes(page_version: :public_version)
52
+ def page_scope_with_includes
53
53
  base_page_scope.
54
54
  where(language: Language.current).
55
55
  includes(
@@ -57,7 +57,7 @@ module Alchemy
57
57
  :legacy_urls,
58
58
  { language: { nodes: [:parent, :children, { page: { language: { site: :languages } } }] } },
59
59
  {
60
- page_version => {
60
+ page_version_type => {
61
61
  elements: [
62
62
  :nested_elements,
63
63
  { contents: { essence: :ingredient_association } },
@@ -68,12 +68,20 @@ module Alchemy
68
68
  )
69
69
  end
70
70
 
71
+ def page_version_type
72
+ :public_version
73
+ end
74
+
75
+ def api_page(page)
76
+ Alchemy::JsonApi::Page.new(page, page_version_type: page_version_type)
77
+ end
78
+
71
79
  def base_page_scope
72
80
  # cancancan is not able to merge our complex AR scopes for logged in users
73
81
  if can?(:edit_content, ::Alchemy::Page)
74
- Alchemy::Page.all
82
+ Alchemy::Page.all.joins(page_version_type)
75
83
  else
76
- Alchemy::Page.published
84
+ Alchemy::Page.published.joins(page_version_type)
77
85
  end
78
86
  end
79
87
 
@@ -1,8 +1,11 @@
1
1
  module Alchemy
2
2
  module JsonApi
3
3
  class Page < SimpleDelegator
4
- def initialize(page, page_version: :public_version)
5
- @page_version = page.public_send(page_version)
4
+ attr_reader :page_version_type, :page_version
5
+
6
+ def initialize(page, page_version_type: :public_version)
7
+ @page_version_type = page_version_type
8
+ @page_version = page.public_send(page_version_type)
6
9
  super(page)
7
10
  end
8
11
 
@@ -33,13 +36,17 @@ module Alchemy
33
36
  @_fixed_element_ids ||= fixed_elements.map(&:id)
34
37
  end
35
38
 
39
+ def ancestor_ids
40
+ @_ancestor_ids ||= ancestors.map(&:id)
41
+ end
42
+
36
43
  private
37
44
 
38
45
  def element_repository
39
- return Alchemy::ElementsRepository.none unless @page_version
46
+ return Alchemy::ElementsRepository.none unless page_version
40
47
 
41
48
  # Need to use select here, otherwise rails would not eager load the elements correctly
42
- Alchemy::ElementsRepository.new(@page_version.elements.select(&:public))
49
+ Alchemy::ElementsRepository.new(page_version.elements.select(&:public))
43
50
  end
44
51
  end
45
52
  end
@@ -7,6 +7,7 @@ module Alchemy
7
7
  include EssenceSerializer
8
8
  attributes(
9
9
  :body,
10
+ :sanitized_body,
10
11
  :stripped_body,
11
12
  )
12
13
  end
@@ -24,6 +24,12 @@ module Alchemy
24
24
 
25
25
  belongs_to :language, record_type: :language, serializer: ::Alchemy::JsonApi::LanguageSerializer
26
26
 
27
+ has_many :ancestors, record_type: :page, serializer: self do |page|
28
+ page.ancestors.map do |ancestor|
29
+ Alchemy::JsonApi::Page.new(ancestor, page_version_type: page.page_version_type)
30
+ end
31
+ end
32
+
27
33
  # All public elements of this page regardless of if they are fixed or nested.
28
34
  # Used for eager loading and should be used as the +include+ parameter of your query
29
35
  has_many :all_elements, record_type: :element, serializer: ELEMENT_SERIALIZER
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Alchemy
3
3
  module JsonApi
4
- VERSION = "0.13.0"
4
+ VERSION = "0.14.0"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemy-json_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-05 00:00:00.000000000 Z
11
+ date: 2021-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alchemy_cms
@@ -156,7 +156,7 @@ homepage: https://github.com/AlchemyCMS/alchemy-json_api
156
156
  licenses:
157
157
  - MIT
158
158
  metadata: {}
159
- post_install_message:
159
+ post_install_message:
160
160
  rdoc_options: []
161
161
  require_paths:
162
162
  - lib
@@ -171,8 +171,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  requirements: []
174
- rubygems_version: 3.1.4
175
- signing_key:
174
+ rubygems_version: 3.1.6
175
+ signing_key:
176
176
  specification_version: 4
177
177
  summary: A JSONAPI compliant API for AlchemyCMS
178
178
  test_files: []