alchemy-json_api 0.7.1 → 0.9.1

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: 280355f5754df05ef965218bd9a35fb6f83b654dc534b2fce7cc903c47422fc2
4
- data.tar.gz: 8ad2aa010faba09069bddb9d466d602d1dbc5c34ce052d82e96187c7bb2daa7b
3
+ metadata.gz: edb472c33e158bda23963966813783a459044d61d268a5ba57a45591584f7f2a
4
+ data.tar.gz: 73ebfd2b1fd491c217cfb577bc422fa558cad73f1c39c987aaac694766de6fee
5
5
  SHA512:
6
- metadata.gz: 80bd161a6f0b2ff1a9f5d393aad8f2d628a6177cf41443d23f0fa8638a66189600a9f43f71e3b7205ca94a9af00b937a0ecf7645e29ea512132a714fe1a4a6bb
7
- data.tar.gz: a71c19f108eff5b51468687ad628173aa32e2e08e0b471c939582f289cea7009690451a7eff0e1a3c2e94724fbd5c52bcd0f4f70a449a80b4d6b3b10ba0a21c3
6
+ metadata.gz: 8393412853b2a72ee6d997cd57d208cfaeab3b9c351aa6c7a4374f7bafd322cbfa9d45d4fb1c9326e7908f1799d741d2f8365e8a85e37412f2efb8b39d040dbb
7
+ data.tar.gz: 692729353563f43124fafc2d239d4fcf204f897509953211598e6e15f8a5c6d85b8468be874dc52570bb72c80cb7f4b595fc451cca399e3e8c26893ef645e720
data/Rakefile CHANGED
@@ -21,6 +21,7 @@ task :test_setup do
21
21
  export RAILS_ENV=test && \
22
22
  bin/rake db:environment:set db:drop && \
23
23
  bin/rake railties:install:migrations && \
24
+ bin/rails g alchemy:devise:install --force && \
24
25
  bin/rake db:migrate
25
26
  SETUP
26
27
  exit($?.exitstatus) unless $?.success?
@@ -3,6 +3,7 @@ module Alchemy
3
3
  module JsonApi
4
4
  class BaseController < ::ApplicationController
5
5
  include Alchemy::ControllerActions
6
+ include Alchemy::AbilityHelper
6
7
  include JSONAPI::Fetching
7
8
  include JSONAPI::Errors
8
9
  include JSONAPI::Filtering
@@ -4,8 +4,12 @@ module Alchemy
4
4
  class LayoutPagesController < JsonApi::PagesController
5
5
  private
6
6
 
7
+ def base_page_scope
8
+ Page.all
9
+ end
10
+
7
11
  def page_scope
8
- base_page_scope.layoutpages
12
+ page_scope_with_includes.layoutpages
9
13
  end
10
14
  end
11
15
  end
@@ -42,16 +42,24 @@ module Alchemy
42
42
  end
43
43
 
44
44
  def page_scope
45
- base_page_scope.contentpages
45
+ page_scope_with_includes.contentpages
46
46
  end
47
47
 
48
- def base_page_scope
49
- ::Alchemy::Page.
48
+ def page_scope_with_includes
49
+ base_page_scope.
50
50
  with_language(Language.current).
51
- published.
52
51
  preload(language: {nodes: [:parent, :page]}, all_elements: [:parent_element, :nested_elements, { contents: { essence: :ingredient_association } }])
53
52
  end
54
53
 
54
+ def base_page_scope
55
+ # cancancan is not able to merge our complex AR scopes for logged in users
56
+ if can?(:edit_content, Page)
57
+ Page.all
58
+ else
59
+ Page.published
60
+ end
61
+ end
62
+
55
63
  def jsonapi_serializer_class(_resource, _is_collection)
56
64
  ::Alchemy::JsonApi::PageSerializer
57
65
  end
@@ -2,7 +2,8 @@
2
2
  module Alchemy
3
3
  module JsonApi
4
4
  class ElementSerializer
5
- include FastJsonapi::ObjectSerializer
5
+ include JSONAPI::Serializer
6
+
6
7
  attributes(
7
8
  :name,
8
9
  :fixed,
@@ -12,7 +13,7 @@ module Alchemy
12
13
  )
13
14
  belongs_to :parent_element, record_type: :element, serializer: self
14
15
 
15
- belongs_to :page, record_type: :page, serializer: PageSerializer
16
+ belongs_to :page, record_type: :page, serializer: ::Alchemy::JsonApi::PageSerializer
16
17
 
17
18
  has_many :essences, polymorphic: true do |element|
18
19
  element.contents.map(&:essence)
@@ -10,7 +10,7 @@ module Alchemy
10
10
  essence&.node&.name
11
11
  end
12
12
 
13
- belongs_to :node, record_type: :node, serializer: NodeSerializer
13
+ belongs_to :node, record_type: :node, serializer: ::Alchemy::JsonApi::NodeSerializer
14
14
 
15
15
  with_options if: proc { |essence| essence.node.present? } do
16
16
  attribute :name do |essence|
@@ -18,7 +18,7 @@ module Alchemy
18
18
  essence.page&.url_path
19
19
  end
20
20
 
21
- has_one :page, record_type: :page, serializer: PageSerializer
21
+ has_one :page, record_type: :page, serializer: ::Alchemy::JsonApi::PageSerializer
22
22
  end
23
23
  end
24
24
  end
@@ -2,7 +2,8 @@
2
2
  module Alchemy
3
3
  module JsonApi
4
4
  class LanguageSerializer
5
- include FastJsonapi::ObjectSerializer
5
+ include JSONAPI::Serializer
6
+
6
7
  attributes(
7
8
  :name,
8
9
  :language_code,
@@ -10,13 +11,13 @@ module Alchemy
10
11
  :locale,
11
12
  )
12
13
 
13
- has_many :menu_items, record_type: :node, serializer: NodeSerializer, object_method_name: :nodes, id_method_name: :node_ids
14
+ has_many :menu_items, record_type: :node, serializer: ::Alchemy::JsonApi::NodeSerializer, object_method_name: :nodes, id_method_name: :node_ids
14
15
 
15
- has_many :menus, record_type: :node, serializer: NodeSerializer do |language|
16
+ has_many :menus, record_type: :node, serializer: ::Alchemy::JsonApi::NodeSerializer do |language|
16
17
  language.nodes.select { |n| n.parent.nil? }
17
18
  end
18
19
  has_many :pages
19
- has_one :root_page, record_type: :page, serializer: PageSerializer
20
+ has_one :root_page, record_type: :page, serializer: ::Alchemy::JsonApi::PageSerializer
20
21
 
21
22
  with_options if: ->(_, params) { params[:admin] == true } do
22
23
  attribute :created_at
@@ -2,7 +2,7 @@
2
2
  module Alchemy
3
3
  module JsonApi
4
4
  class NodeSerializer
5
- include FastJsonapi::ObjectSerializer
5
+ include JSONAPI::Serializer
6
6
 
7
7
  attributes :name
8
8
  attribute :link_url, &:url
@@ -2,7 +2,8 @@
2
2
  module Alchemy
3
3
  module JsonApi
4
4
  class PageSerializer
5
- include FastJsonapi::ObjectSerializer
5
+ include JSONAPI::Serializer
6
+
6
7
  attributes(
7
8
  :name,
8
9
  :urlname,
@@ -15,12 +16,12 @@ module Alchemy
15
16
  :updated_at,
16
17
  )
17
18
 
18
- belongs_to :language, record_type: :language, serializer: LanguageSerializer
19
+ belongs_to :language, record_type: :language, serializer: ::Alchemy::JsonApi::LanguageSerializer
19
20
 
20
- has_many :elements, record_type: :element, serializer: ElementSerializer
21
- has_many :fixed_elements, record_type: :element, serializer: ElementSerializer
21
+ has_many :elements, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer
22
+ has_many :fixed_elements, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer
22
23
 
23
- has_many :all_elements, record_type: :element, serializer: ElementSerializer do |page|
24
+ has_many :all_elements, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer do |page|
24
25
  page.all_elements.select { |e| e.public? && !e.trashed? }
25
26
  end
26
27
 
@@ -3,8 +3,8 @@ module Alchemy
3
3
  module JsonApi
4
4
  module EssenceSerializer
5
5
  def self.included(klass)
6
- klass.include FastJsonapi::ObjectSerializer
7
- klass.has_one :element, record_type: :element, serializer: ElementSerializer do |essence|
6
+ klass.include JSONAPI::Serializer
7
+ klass.has_one :element, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer do |essence|
8
8
  essence.content.element
9
9
  end
10
10
  klass.attributes :ingredient
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Alchemy
3
3
  module JsonApi
4
- VERSION = "0.7.1"
4
+ VERSION = "0.9.1"
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.7.1
4
+ version: 0.9.1
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: 2020-11-16 00:00:00.000000000 Z
11
+ date: 2020-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alchemy_cms
@@ -25,33 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: fast_jsonapi
28
+ name: jsonapi.rb
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.5'
33
+ version: '1.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.5'
41
- - !ruby/object:Gem::Dependency
42
- name: jsonapi.rb
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: '1.6'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: factory_bot
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -147,7 +133,7 @@ homepage: https://github.com/AlchemyCMS/alchemy-json_api
147
133
  licenses:
148
134
  - MIT
149
135
  metadata: {}
150
- post_install_message:
136
+ post_install_message:
151
137
  rdoc_options: []
152
138
  require_paths:
153
139
  - lib
@@ -162,8 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
148
  - !ruby/object:Gem::Version
163
149
  version: '0'
164
150
  requirements: []
165
- rubygems_version: 3.0.3
166
- signing_key:
151
+ rubygems_version: 3.1.4
152
+ signing_key:
167
153
  specification_version: 4
168
154
  summary: A JSONAPI compliant API for AlchemyCMS
169
155
  test_files: []