forest_liana 8.0.0.beta.3 → 8.0.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: 82036a005a4c2e31b6e1e48c7f9d5befacb5b72ba71046bd5bcfa83d43c19797
4
- data.tar.gz: c825c64871dd4737961a589c3869c07126ddf8023265822cb73a2019aa82ed2e
3
+ metadata.gz: 6fc8eadd1a9e180f660f4bae33391b3611ccd3f6ef5a7c693113f596ae0aa218
4
+ data.tar.gz: 2068a675f2b03530e0a46abc8257d21f0cb54c4e626a4b4bed2b2e05b50aa4d2
5
5
  SHA512:
6
- metadata.gz: c519f23a7c267b77cd83a42859e9aac9996955d2ec918c1d562c5d3ceda2c15638840fae765b2241b12a2f5dba38be8de898923879cd2b8c82902a77c583192c
7
- data.tar.gz: f3e06eabdee80eab3b8991c355a1af15e1601d2e8ba35adb7160f9d367958f7473f236cbb011f0907be5073cc111efc17138b67c88c727827def72ab8261d0c1
6
+ metadata.gz: 2a0c1623151fc945db4039617ba7fa16f5add68b582ae77c970024274b7c0b9598ebbd32e39f8a35206bf03f85761d7e353770cd5db4faa7f7e2d1167ef9a080
7
+ data.tar.gz: 217296111175fced8245f76b687fb313079b265da3f30a8b4ca4d83d3fa4acdba4f9aa808d54a2f555f494e729643f7aa13d879f011d7ced469d43456119b943
@@ -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"
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
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-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -539,9 +539,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
539
539
  version: '0'
540
540
  required_rubygems_version: !ruby/object:Gem::Requirement
541
541
  requirements:
542
- - - ">"
542
+ - - ">="
543
543
  - !ruby/object:Gem::Version
544
- version: 1.3.1
544
+ version: '0'
545
545
  requirements: []
546
546
  rubygems_version: 3.3.5
547
547
  signing_key: