forest_liana 8.0.0.beta.3 → 8.0.0.beta.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82036a005a4c2e31b6e1e48c7f9d5befacb5b72ba71046bd5bcfa83d43c19797
4
- data.tar.gz: c825c64871dd4737961a589c3869c07126ddf8023265822cb73a2019aa82ed2e
3
+ metadata.gz: 83e541b62689b763990ff3d940c44bcfd339ffa1b0447e023664b99dda8f54da
4
+ data.tar.gz: eea162587eafe0cc4cdd2f3f843418b3d71ac4adcab9c96deddd9b6c389de4a8
5
5
  SHA512:
6
- metadata.gz: c519f23a7c267b77cd83a42859e9aac9996955d2ec918c1d562c5d3ceda2c15638840fae765b2241b12a2f5dba38be8de898923879cd2b8c82902a77c583192c
7
- data.tar.gz: f3e06eabdee80eab3b8991c355a1af15e1601d2e8ba35adb7160f9d367958f7473f236cbb011f0907be5073cc111efc17138b67c88c727827def72ab8261d0c1
6
+ metadata.gz: 299125cff69b0900bee3bf03bc47cf081cd0c8ef2e1490a8e3dd3391c52beac2434f3282d9958d10beeb4929fcc47628e40a4dbc5237203a6371ff51898da809
7
+ data.tar.gz: 5a260f17aeb453ba495de4f02c21b6fef1b18dd05fd073e2969d2cdca2fc2eb8dc11dfef161b382e38c46285efb8185429522ddeef8ff157e814fca740d4daad
@@ -5,20 +5,19 @@ module ForestLiana
5
5
  rescue_from ForestLiana::Ability::Exceptions::ActionConditionError, with: :render_error
6
6
  include ForestLiana::Ability
7
7
  if Rails::VERSION::MAJOR < 4
8
- before_filter :smart_action_pre_perform_checks
8
+ before_filter :get_smart_action_request
9
+ before_filter :find_resource
10
+ before_filter :check_permission_for_smart_route
11
+ before_filter :ensure_record_ids_in_scope
9
12
  else
10
- before_action :smart_action_pre_perform_checks
13
+ before_action :get_smart_action_request
14
+ before_action :find_resource
15
+ before_action :check_permission_for_smart_route
16
+ before_action :ensure_record_ids_in_scope
11
17
  end
12
18
 
13
19
  private
14
20
 
15
- def smart_action_pre_perform_checks
16
- get_smart_action_request
17
- find_resource
18
- check_permission_for_smart_route
19
- ensure_record_ids_in_scope
20
- end
21
-
22
21
  def get_smart_action_request
23
22
  begin
24
23
  params[:data][:attributes]
@@ -31,18 +30,11 @@ module ForestLiana
31
30
  end
32
31
 
33
32
  def find_resource
34
- begin
35
33
  @resource = SchemaUtils.find_model_from_collection_name(@parameters[:data][:attributes][:collection_name])
36
- if @resource.nil? || !SchemaUtils.model_included?(@resource) ||
37
- !@resource.ancestors.include?(ActiveRecord::Base)
38
- render serializer: nil, json: { status: 404 }, status: :not_found
34
+ if @resource.nil? || !SchemaUtils.model_included?(@resource) || !@resource.ancestors.include?(ActiveRecord::Base)
35
+ raise ForestLiana::Errors::HTTP422Error.new('The conditional smart actions are not supported with Smart Collection. Please contact an administrator.')
39
36
  end
40
37
  @resource
41
- rescue => error
42
- FOREST_REPORTER.report error
43
- FOREST_LOGGER.error "Find Collection error: #{error}\n#{format_stacktrace(error)}"
44
- render serializer: nil, json: { status: 404 }, status: :not_found
45
- end
46
38
  end
47
39
 
48
40
  def check_permission_for_smart_route
@@ -7,18 +7,27 @@ module ForestLiana
7
7
  def forest_authorize!(action, user, collection, args = {})
8
8
  case action
9
9
  when 'browse', 'read', 'edit', 'add', 'delete', 'export'
10
- raise ForestLiana::Ability::Exceptions::AccessDenied.new unless is_crud_authorized?(action, user, collection)
10
+ raise ForestLiana::Ability::Exceptions::AccessDenied.new unless is_crud_authorized?(action, user, collection)
11
11
  when 'chart'
12
- if ALLOWED_PERMISSION_LEVELS.exclude?(user['permission_level'])
13
- raise ForestLiana::Errors::HTTP422Error.new('The argument parameters is missing') if args[:parameters].nil?
14
- raise ForestLiana::Ability::Exceptions::AccessDenied.new unless is_chart_authorized?(user, args[:parameters])
15
- end
12
+ if ALLOWED_PERMISSION_LEVELS.exclude?(user['permission_level'])
13
+ raise ForestLiana::Errors::HTTP422Error.new('The argument parameters is missing') if args[:parameters].nil?
14
+ raise ForestLiana::Ability::Exceptions::AccessDenied.new unless is_chart_authorized?(user, args[:parameters])
15
+ end
16
16
  when 'action'
17
- raise ForestLiana::Errors::HTTP422Error.new('You must implement the arguments : parameters, endpoint & http_method') if args[:parameters].nil? || args[:endpoint].nil? || args[:http_method].nil?
18
- is_smart_action_authorized?(user, collection, args[:parameters], args[:endpoint], args[:http_method])
17
+ validate_collection collection
18
+ raise ForestLiana::Errors::HTTP422Error.new('You must implement the arguments : parameters, endpoint & http_method') if args[:parameters].nil? || args[:endpoint].nil? || args[:http_method].nil?
19
+ is_smart_action_authorized?(user, collection, args[:parameters], args[:endpoint], args[:http_method])
19
20
  else
20
21
  raise ForestLiana::Ability::Exceptions::AccessDenied.new
21
22
  end
22
23
  end
24
+
25
+ private
26
+
27
+ def validate_collection(collection)
28
+ if collection.nil? || !SchemaUtils.model_included?(collection)
29
+ raise ForestLiana::Errors::HTTP422Error.new('The conditional smart actions are not supported with Smart Collection. Please contact an administrator.')
30
+ end
31
+ end
23
32
  end
24
33
  end
@@ -32,7 +32,6 @@ module ForestLiana
32
32
 
33
33
  def self.find_model_from_collection_name(collection_name, logs = false)
34
34
  model_found = nil
35
-
36
35
  ForestLiana.models.each do |model|
37
36
  if model.abstract_class?
38
37
  model_found = self.find_model_from_abstract_class(model, collection_name)
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "8.0.0.beta.3"
2
+ VERSION = "8.0.0.beta.4"
3
3
  end
@@ -42,6 +42,14 @@ module ForestLiana
42
42
  user['permission_level'] = 'admin'
43
43
  expect(dummy_class.forest_authorize!('chart', user, Island.first, {parameters: []})).to equal nil
44
44
  end
45
+
46
+ it 'should raise error 422 when the collection is nil on action ability' do
47
+ expect { dummy_class.forest_authorize!('action', :user, nil) }.to raise_error(ForestLiana::Errors::HTTP422Error, "The conditional smart actions are not supported with Smart Collection. Please contact an administrator.")
48
+ end
49
+
50
+ it 'should raise error 422 when the collection is not a ActiveRecord children on action ability' do
51
+ expect { dummy_class.forest_authorize!('action', :user, class Example; end ) }.to raise_error(ForestLiana::Errors::HTTP422Error, "The conditional smart actions are not supported with Smart Collection. Please contact an administrator.")
52
+ end
45
53
  end
46
54
  end
47
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.0.beta.3
4
+ version: 8.0.0.beta.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-22 00:00:00.000000000 Z
11
+ date: 2023-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails