forest_liana 4.2.0 → 5.0.0.pre.beta.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/resources_controller.rb +21 -9
- data/app/controllers/forest_liana/router.rb +5 -1
- data/app/services/forest_liana/has_many_dissociator.rb +13 -8
- data/app/services/forest_liana/has_many_getter.rb +7 -5
- data/app/services/forest_liana/resources_getter.rb +45 -0
- data/config/routes.rb +1 -0
- data/lib/forest_liana/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 919b3681f70c2a7265839b6f26375c066cc04657
|
4
|
+
data.tar.gz: 670e5dcb4227b380f1547262d0dda5715dc7ffae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 399a95797f3649fe6f926f76b75241c58ad88f4705e1abfede85e391b08f398fe2c1c909d6451d977c5341d5070c776f81b049383fc8d812775cc20443edb2e7
|
7
|
+
data.tar.gz: 65432f209cc2d54976e7227aca68742093385db4bcc4d0de569c6ef9b4c93757c8cb253393afdb18c8752f3b7e00ff602e768128b76bf4d1d99bfdbc7e65b9b0
|
@@ -137,16 +137,28 @@ module ForestLiana
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def destroy
|
140
|
-
|
141
|
-
|
142
|
-
return head :forbidden unless checker.is_authorized?
|
140
|
+
checker = ForestLiana::PermissionsChecker.new(@resource, 'delete', @rendering_id)
|
141
|
+
return head :forbidden unless checker.is_authorized?
|
143
142
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
143
|
+
@resource.destroy(params[:id]) if @resource.exists?(params[:id])
|
144
|
+
|
145
|
+
head :no_content
|
146
|
+
rescue => error
|
147
|
+
FOREST_LOGGER.error "Record Destroy error: #{error}\n#{format_stacktrace(error)}"
|
148
|
+
internal_server_error
|
149
|
+
end
|
150
|
+
|
151
|
+
def destroy_bulk
|
152
|
+
checker = ForestLiana::PermissionsChecker.new(@resource, 'delete', @rendering_id)
|
153
|
+
return head :forbidden unless checker.is_authorized?
|
154
|
+
|
155
|
+
ids = ForestLiana::ResourcesGetter.get_ids_from_request(params)
|
156
|
+
@resource.destroy(ids) if ids&.any?
|
157
|
+
|
158
|
+
head :no_content
|
159
|
+
rescue => error
|
160
|
+
FOREST_LOGGER.error "Records Destroy error: #{error}\n#{format_stacktrace(error)}"
|
161
|
+
internal_server_error
|
150
162
|
end
|
151
163
|
|
152
164
|
private
|
@@ -14,17 +14,22 @@ module ForestLiana
|
|
14
14
|
|
15
15
|
remove_association = !@with_deletion || @association.macro == :has_and_belongs_to_many
|
16
16
|
|
17
|
-
if
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
if @data.is_a?(Array)
|
18
|
+
record_ids = @data.map { |record| record[:id] }
|
19
|
+
elsif @data.dig('attributes').present?
|
20
|
+
record_ids = ForestLiana::ResourcesGetter.get_ids_from_request(@params)
|
21
|
+
else
|
22
|
+
record_ids = Array.new
|
23
|
+
end
|
24
|
+
|
25
|
+
if !record_ids.nil? && record_ids.any?
|
26
|
+
if remove_association
|
27
|
+
record_ids.each do |id|
|
28
|
+
associated_records.delete(@association.klass.find(id))
|
21
29
|
end
|
22
30
|
end
|
23
|
-
end
|
24
31
|
|
25
|
-
|
26
|
-
if @data.is_a?(Array)
|
27
|
-
record_ids = @data.map { |record| record[:id] }
|
32
|
+
if @with_deletion
|
28
33
|
record_ids = record_ids.select { |record_id| @association.klass.exists?(record_id) }
|
29
34
|
@association.klass.destroy(record_ids)
|
30
35
|
end
|
@@ -19,7 +19,7 @@ module ForestLiana
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def perform
|
22
|
-
@records
|
22
|
+
@records
|
23
23
|
end
|
24
24
|
|
25
25
|
def count
|
@@ -64,10 +64,12 @@ module ForestLiana
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def prepare_query
|
67
|
-
@records =
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
@records = @search_query_builder.perform(
|
68
|
+
get_resource()
|
69
|
+
.find(@params[:id])
|
70
|
+
.send(@params[:association_name])
|
71
|
+
.eager_load(@includes)
|
72
|
+
)
|
71
73
|
end
|
72
74
|
|
73
75
|
def offset
|
@@ -19,6 +19,51 @@ module ForestLiana
|
|
19
19
|
prepare_query()
|
20
20
|
end
|
21
21
|
|
22
|
+
def self.get_ids_from_request(params)
|
23
|
+
attributes = params.dig('data', 'attributes')
|
24
|
+
has_body_attributes = attributes != nil
|
25
|
+
is_select_all_records_query = has_body_attributes && attributes[:all_records] == true
|
26
|
+
|
27
|
+
# NOTICE: If it is not a "select all records" query and it receives a list of ID, return list of ID.
|
28
|
+
return attributes[:ids] if (!is_select_all_records_query && attributes[:ids])
|
29
|
+
|
30
|
+
# NOTICE: If it is a "select all records" we have to perform query to build ID list.
|
31
|
+
ids = Array.new
|
32
|
+
|
33
|
+
# NOTICE: Merging all_records_subset_query into attributes preserves filters in HasManyGetter and ResourcesGetter.
|
34
|
+
attributes = attributes.merge(attributes[:all_records_subset_query].dup.to_unsafe_h)
|
35
|
+
|
36
|
+
# NOTICE: Initialize actual resources getter (could either a HasManyGetter or a ResourcesGetter).
|
37
|
+
is_related_data = attributes[:parent_collection_id] &&
|
38
|
+
attributes[:parent_collection_name] &&
|
39
|
+
attributes[:parent_association_name]
|
40
|
+
if is_related_data
|
41
|
+
parent_collection_name = attributes[:parent_collection_name]
|
42
|
+
parent_model = ForestLiana::SchemaUtils.find_model_from_collection_name(parent_collection_name)
|
43
|
+
model = parent_model.reflect_on_association(attributes[:parent_association_name].try(:to_sym))
|
44
|
+
resources_getter = ForestLiana::HasManyGetter.new(parent_model, model, attributes.merge({
|
45
|
+
collection: parent_collection_name,
|
46
|
+
id: attributes[:parent_collection_id],
|
47
|
+
association_name: attributes[:parent_association_name],
|
48
|
+
}))
|
49
|
+
else
|
50
|
+
collection_name = attributes[:collection_name]
|
51
|
+
model = ForestLiana::SchemaUtils.find_model_from_collection_name(collection_name)
|
52
|
+
resources_getter = ForestLiana::ResourcesGetter.new(model, attributes)
|
53
|
+
end
|
54
|
+
|
55
|
+
# NOTICE: build IDs list.
|
56
|
+
resources_getter.query_for_batch.find_in_batches() do |records|
|
57
|
+
ids += records.map { |record| record.id }
|
58
|
+
end
|
59
|
+
|
60
|
+
# NOTICE: remove excluded IDs.
|
61
|
+
ids_excluded = (attributes[:all_records_ids_excluded]).map { |id_excluded| id_excluded.to_s }
|
62
|
+
return ids.select { |id| !ids_excluded.include? id.to_s } if (ids_excluded && ids_excluded.any?)
|
63
|
+
|
64
|
+
return ids
|
65
|
+
end
|
66
|
+
|
22
67
|
def perform
|
23
68
|
@records = @records.eager_load(@includes)
|
24
69
|
end
|
data/config/routes.rb
CHANGED
@@ -53,6 +53,7 @@ ForestLiana::Engine.routes.draw do
|
|
53
53
|
post ':collection', to: router
|
54
54
|
put ':collection/:id', to: router
|
55
55
|
delete ':collection/:id', to: router
|
56
|
+
delete ':collection', to: router
|
56
57
|
|
57
58
|
# Smart Actions forms value
|
58
59
|
post 'actions/:action_name/values' => 'actions#values'
|
data/lib/forest_liana/version.rb
CHANGED
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:
|
4
|
+
version: 5.0.0.pre.beta.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: 2020-
|
11
|
+
date: 2020-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -453,9 +453,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
453
453
|
version: '0'
|
454
454
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
455
455
|
requirements:
|
456
|
-
- - "
|
456
|
+
- - ">"
|
457
457
|
- !ruby/object:Gem::Version
|
458
|
-
version:
|
458
|
+
version: 1.3.1
|
459
459
|
requirements: []
|
460
460
|
rubyforge_project:
|
461
461
|
rubygems_version: 2.6.14
|