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 +4 -4
- data/app/controllers/forest_liana/smart_actions_controller.rb +10 -18
- data/app/services/forest_liana/ability.rb +16 -7
- data/app/services/forest_liana/schema_utils.rb +0 -1
- data/lib/forest_liana/version.rb +1 -1
- data/spec/services/forest_liana/ability/ability_spec.rb +8 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fc8eadd1a9e180f660f4bae33391b3611ccd3f6ef5a7c693113f596ae0aa218
|
4
|
+
data.tar.gz: 2068a675f2b03530e0a46abc8257d21f0cb54c4e626a4b4bed2b2e05b50aa4d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 :
|
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 :
|
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
|
-
|
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
|
-
|
10
|
+
raise ForestLiana::Ability::Exceptions::AccessDenied.new unless is_crud_authorized?(action, user, collection)
|
11
11
|
when 'chart'
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
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)
|
data/lib/forest_liana/version.rb
CHANGED
@@ -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
|
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-
|
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:
|
544
|
+
version: '0'
|
545
545
|
requirements: []
|
546
546
|
rubygems_version: 3.3.5
|
547
547
|
signing_key:
|