alchemy-json_api 0.5.0 → 0.8.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: 75009d101abaf01259e6cedae35acc22f02168d0714e6a3eda87e280361d3b91
4
- data.tar.gz: f40dd94a84033d62409e3c4fffd261ec03ed1193017f8b6baf90bb2d2aec9ae8
3
+ metadata.gz: d820e87bf877fa770b6145ca3e2e50b907bb673d917a416723ad13b3edb72158
4
+ data.tar.gz: 907f95e93d6bbe7bcd57e64b768d86ad459dd7fb5fd957692e16eaf251369be0
5
5
  SHA512:
6
- metadata.gz: 9b326f105a93d6752282112615888ee3e86bf72c5486a3ad77547fb9dae664bcbf3325ee902b04d192b96dacc5bd60935ed37bc827874f72bc2522a48a890e0f
7
- data.tar.gz: 55149b58ba90ef71688029b1f13ca2789ae00ae5b230989e670ae05a41c2b58df17ce2210429dbef3393f6304c663730f20bf9fc69440a90871c06dabe39a425
6
+ metadata.gz: c1119df682cb6a9cb82447da59a3f24afc59c7dad9fb44c65dd8a16dbfdc74826ebab74d65e2b697e2fc7117519d71d8dafc149b71f035f32b7da4be02edce03
7
+ data.tar.gz: 0d83f06aa5aeeaf44712096197324bab31be452196d795504ee2ec0b3d34006de68b41ce20c3ad6a2fff84251d13184a953d165b7cf06b32b9c9df7849f5d24d
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,12 +3,28 @@ 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
- if Rails.env.production?
8
- include JSONAPI::Errors
9
- end
8
+ include JSONAPI::Errors
10
9
  include JSONAPI::Filtering
11
10
  include JSONAPI::Pagination
11
+
12
+ private
13
+
14
+ def render_jsonapi_internal_server_error(exception)
15
+ log_error(exception)
16
+ super
17
+ end
18
+
19
+ def log_error(exception)
20
+ logger = Rails.logger
21
+ return unless logger
22
+
23
+ message = +"\n#{exception.class} (#{exception.message}):\n"
24
+ message << exception.annotated_source_code.to_s if exception.respond_to?(:annotated_source_code)
25
+ message << " " << exception.backtrace.join("\n ")
26
+ logger.fatal("#{message}\n\n")
27
+ end
12
28
  end
13
29
  end
14
30
  end
@@ -46,9 +46,14 @@ module Alchemy
46
46
  end
47
47
 
48
48
  def base_page_scope
49
- ::Alchemy::Page.
49
+ # cancancan is not able to merge our complex AR scopes for logged in users
50
+ if can?(:edit_content, Page)
51
+ pages = Page.all
52
+ else
53
+ pages = Page.accessible_by(current_ability, :index)
54
+ end
55
+ pages.
50
56
  with_language(Language.current).
51
- published.
52
57
  preload(language: {nodes: [:parent, :page]}, all_elements: [:parent_element, :nested_elements, { contents: { essence: :ingredient_association } }])
53
58
  end
54
59
 
@@ -12,7 +12,8 @@ module Alchemy
12
12
  )
13
13
  belongs_to :parent_element, record_type: :element, serializer: self
14
14
 
15
- belongs_to :page
15
+ belongs_to :page, record_type: :page, serializer: ::Alchemy::JsonApi::PageSerializer
16
+
16
17
  has_many :essences, polymorphic: true do |element|
17
18
  element.contents.map(&:essence)
18
19
  end
@@ -10,7 +10,7 @@ module Alchemy
10
10
  essence&.node&.name
11
11
  end
12
12
 
13
- belongs_to :node
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
@@ -10,13 +10,13 @@ module Alchemy
10
10
  :locale,
11
11
  )
12
12
 
13
- has_many :menu_items, record_type: :node, serializer: NodeSerializer, object_method_name: :nodes, id_method_name: :node_ids
13
+ has_many :menu_items, record_type: :node, serializer: ::Alchemy::JsonApi::NodeSerializer, object_method_name: :nodes, id_method_name: :node_ids
14
14
 
15
- has_many :menus, record_type: :node, serializer: NodeSerializer do |language|
15
+ has_many :menus, record_type: :node, serializer: ::Alchemy::JsonApi::NodeSerializer do |language|
16
16
  language.nodes.select { |n| n.parent.nil? }
17
17
  end
18
18
  has_many :pages
19
- has_one :root_page, record_type: :page, serializer: PageSerializer
19
+ has_one :root_page, record_type: :page, serializer: ::Alchemy::JsonApi::PageSerializer
20
20
 
21
21
  with_options if: ->(_, params) { params[:admin] == true } do
22
22
  attribute :created_at
@@ -15,12 +15,12 @@ module Alchemy
15
15
  :updated_at,
16
16
  )
17
17
 
18
- belongs_to :language
18
+ belongs_to :language, record_type: :language, serializer: ::Alchemy::JsonApi::LanguageSerializer
19
19
 
20
- has_many :elements
21
- has_many :fixed_elements, record_type: :element, serializer: ElementSerializer
20
+ has_many :elements, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer
21
+ has_many :fixed_elements, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer
22
22
 
23
- has_many :all_elements, record_type: :element, serializer: ElementSerializer do |page|
23
+ has_many :all_elements, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer do |page|
24
24
  page.all_elements.select { |e| e.public? && !e.trashed? }
25
25
  end
26
26
 
@@ -4,7 +4,7 @@ module Alchemy
4
4
  module EssenceSerializer
5
5
  def self.included(klass)
6
6
  klass.include FastJsonapi::ObjectSerializer
7
- klass.has_one :element, record_type: :element, serializer: ElementSerializer do |essence|
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.5.0"
4
+ VERSION = "0.8.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.5.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-06 00:00:00.000000000 Z
11
+ date: 2020-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alchemy_cms
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  - !ruby/object:Gem::Version
163
163
  version: '0'
164
164
  requirements: []
165
- rubygems_version: 3.0.3
165
+ rubygems_version: 3.1.4
166
166
  signing_key:
167
167
  specification_version: 4
168
168
  summary: A JSONAPI compliant API for AlchemyCMS