forest_liana 8.3.3 → 9.0.0.beta.1
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 +4 -4
- data/app/controllers/forest_liana/associations_controller.rb +0 -2
- data/app/services/forest_liana/ability/permission.rb +1 -1
- data/app/services/forest_liana/belongs_to_updater.rb +1 -1
- data/app/services/forest_liana/has_many_dissociator.rb +1 -6
- data/app/services/forest_liana/schema_adapter.rb +0 -2
- data/app/services/forest_liana/schema_utils.rb +1 -6
- data/app/services/forest_liana/search_query_builder.rb +10 -5
- data/lib/forest_liana/version.rb +1 -1
- data/spec/requests/stats_spec.rb +26 -52
- data/spec/services/forest_liana/schema_adapter_spec.rb +0 -17
- data/spec/spec_helper.rb +0 -1
- 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: 0a157aee784201e7da6a7330fc813ce01540107f3c319a6ac294120de809a823
|
|
4
|
+
data.tar.gz: f8343a2641fa23b7eb2934d35a0de7f5e8198e44c961380a0c07a9049671f2ab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6057484cb179b3ae0203f935df4638cd080c4777807cfcc4758a4dd2bbfc9ca4627cd1a7b85b487a469f2e9a66f31a9ce9f58e7fdd474e5de552516780c57be2
|
|
7
|
+
data.tar.gz: 6bb712c6471e7cbe7016582b3a10fe34159cf46b12b8c1626ca706fb95f2d91e585ee4dd8592a1efcf8afd91e287def131777f35c2d028903fa502a4007cd546
|
|
@@ -76,8 +76,6 @@ module ForestLiana
|
|
|
76
76
|
dissociator.perform
|
|
77
77
|
|
|
78
78
|
head :no_content
|
|
79
|
-
rescue ActiveRecord::RecordNotDestroyed => error
|
|
80
|
-
render json: { errors: [{ status: :bad_request, detail: error.message }] }, status: :bad_request
|
|
81
79
|
rescue => error
|
|
82
80
|
FOREST_REPORTER.report error
|
|
83
81
|
FOREST_LOGGER.error "Association Dissociate error: #{error}\n#{format_stacktrace(error)}"
|
|
@@ -97,7 +97,7 @@ module ForestLiana
|
|
|
97
97
|
Rails.cache.fetch('forest.stats', expires_in: TTL) do
|
|
98
98
|
stat_hash = []
|
|
99
99
|
get_permissions('/liana/v4/permissions/renderings/' + rendering_id)['stats'].each do |stat|
|
|
100
|
-
stat_hash << "#{stat['type']}:#{Digest::SHA1.hexdigest(stat.
|
|
100
|
+
stat_hash << "#{stat['type']}:#{Digest::SHA1.hexdigest(stat.sort.to_h.to_s)}"
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
stat_hash
|
|
@@ -17,7 +17,7 @@ module ForestLiana
|
|
|
17
17
|
if @data.nil?
|
|
18
18
|
new_value = nil
|
|
19
19
|
else
|
|
20
|
-
association_klass = SchemaUtils.polymorphic_models(@association).select { |a| a.name == @data[:type] }.first
|
|
20
|
+
association_klass = SchemaUtils.polymorphic_models(@association).select { |a| a.name.downcase == @data[:type] }.first
|
|
21
21
|
new_value = association_klass.find(@data[:id]) if @data && @data[:id]
|
|
22
22
|
end
|
|
23
23
|
else
|
|
@@ -31,12 +31,7 @@ module ForestLiana
|
|
|
31
31
|
|
|
32
32
|
if @with_deletion
|
|
33
33
|
record_ids = record_ids.select { |record_id| @association.klass.exists?(record_id) }
|
|
34
|
-
@
|
|
35
|
-
record_ids.each do |id|
|
|
36
|
-
record = @association.klass.find(id)
|
|
37
|
-
record.destroy!
|
|
38
|
-
end
|
|
39
|
-
end
|
|
34
|
+
@association.klass.destroy(record_ids)
|
|
40
35
|
end
|
|
41
36
|
end
|
|
42
37
|
end
|
|
@@ -242,8 +242,6 @@ module ForestLiana
|
|
|
242
242
|
SchemaUtils.associations(@model).each do |association|
|
|
243
243
|
begin
|
|
244
244
|
if SchemaUtils.polymorphic?(association) &&
|
|
245
|
-
(ENV['ENABLE_SUPPORT_POLYMORPHISM'].present? && ENV['ENABLE_SUPPORT_POLYMORPHISM'].downcase == 'true')
|
|
246
|
-
|
|
247
245
|
collection.fields << {
|
|
248
246
|
field: association.name.to_s,
|
|
249
247
|
type: get_type_for_association(association),
|
|
@@ -4,12 +4,7 @@ module ForestLiana
|
|
|
4
4
|
def self.associations(active_record_class)
|
|
5
5
|
active_record_class.reflect_on_all_associations.select do |association|
|
|
6
6
|
begin
|
|
7
|
-
|
|
8
|
-
polymorphic?(association) ? true : !is_active_type?(association.klass)
|
|
9
|
-
else
|
|
10
|
-
!polymorphic?(association) && !is_active_type?(association.klass)
|
|
11
|
-
end
|
|
12
|
-
|
|
7
|
+
polymorphic?(association) ? true : !is_active_type?(association.klass)
|
|
13
8
|
rescue
|
|
14
9
|
FOREST_LOGGER.warn "Unknown association #{association.name} on class #{active_record_class.name}"
|
|
15
10
|
false
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module ForestLiana
|
|
2
2
|
class SearchQueryBuilder
|
|
3
|
-
REGEX_UUID = /\A[0-9a-f]{8}-[0-9a-f]{4}-[1-
|
|
3
|
+
REGEX_UUID = /\A[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\z/i
|
|
4
4
|
|
|
5
5
|
attr_reader :fields_searched
|
|
6
6
|
|
|
@@ -160,9 +160,12 @@ module ForestLiana
|
|
|
160
160
|
end
|
|
161
161
|
|
|
162
162
|
def sort_query
|
|
163
|
+
column = nil
|
|
164
|
+
order = 'DESC'
|
|
165
|
+
|
|
163
166
|
if @params[:sort]
|
|
164
167
|
@params[:sort].split(',').each do |field|
|
|
165
|
-
order_detected = detect_sort_order(
|
|
168
|
+
order_detected = detect_sort_order(@params[:sort])
|
|
166
169
|
order = order_detected.upcase
|
|
167
170
|
field.slice!(0) if order_detected == :desc
|
|
168
171
|
|
|
@@ -172,12 +175,14 @@ module ForestLiana
|
|
|
172
175
|
else
|
|
173
176
|
column = field
|
|
174
177
|
end
|
|
175
|
-
|
|
176
|
-
@records = @records.order(Arel.sql("#{column} #{order}"))
|
|
177
178
|
end
|
|
178
179
|
end
|
|
179
180
|
|
|
180
|
-
|
|
181
|
+
if column
|
|
182
|
+
@records = @records.order(Arel.sql("#{column} #{order}"))
|
|
183
|
+
else
|
|
184
|
+
@records
|
|
185
|
+
end
|
|
181
186
|
end
|
|
182
187
|
|
|
183
188
|
def detect_reference(param)
|
data/lib/forest_liana/version.rb
CHANGED
data/spec/requests/stats_spec.rb
CHANGED
|
@@ -2,8 +2,24 @@ require 'rails_helper'
|
|
|
2
2
|
require 'json'
|
|
3
3
|
|
|
4
4
|
describe "Stats", type: :request do
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
|
|
6
|
+
token = JWT.encode({
|
|
7
|
+
id: 1,
|
|
8
|
+
email: 'michael.kelso@that70.show',
|
|
9
|
+
first_name: 'Michael',
|
|
10
|
+
last_name: 'Kelso',
|
|
11
|
+
team: 'Operations',
|
|
12
|
+
rendering_id: '1',
|
|
13
|
+
exp: Time.now.to_i + 2.weeks.to_i,
|
|
14
|
+
permission_level: 'admin'
|
|
15
|
+
}, ForestLiana.auth_secret, 'HS256')
|
|
16
|
+
|
|
17
|
+
headers = {
|
|
18
|
+
'Accept' => 'application/json',
|
|
19
|
+
'Content-Type' => 'application/json',
|
|
20
|
+
'Authorization' => "Bearer #{token}"
|
|
21
|
+
}
|
|
22
|
+
|
|
7
23
|
let(:schema) {
|
|
8
24
|
[
|
|
9
25
|
ForestLiana::Model::Collection.new({
|
|
@@ -14,31 +30,10 @@ describe "Stats", type: :request do
|
|
|
14
30
|
]
|
|
15
31
|
}
|
|
16
32
|
|
|
17
|
-
let(:token) {
|
|
18
|
-
JWT.encode({
|
|
19
|
-
id: 1,
|
|
20
|
-
email: 'michael.kelso@that70.show',
|
|
21
|
-
first_name: 'Michael',
|
|
22
|
-
last_name: 'Kelso',
|
|
23
|
-
team: 'Operations',
|
|
24
|
-
rendering_id: rendering_id,
|
|
25
|
-
exp: Time.now.to_i + 2.weeks.to_i,
|
|
26
|
-
permission_level: 'user'
|
|
27
|
-
}, ForestLiana.auth_secret, 'HS256')
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
let(:headers) {
|
|
31
|
-
{
|
|
32
|
-
'Accept' => 'application/json',
|
|
33
|
-
'Content-Type' => 'application/json',
|
|
34
|
-
'Authorization' => "Bearer #{token}"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
33
|
before do
|
|
39
34
|
Rails.cache.write('forest.users', {'1' => { 'id' => 1, 'roleId' => 1, 'rendering_id' => '1' }})
|
|
40
35
|
Rails.cache.write('forest.has_permission', true)
|
|
41
|
-
allow_any_instance_of(ForestLiana::Ability::
|
|
36
|
+
allow_any_instance_of(ForestLiana::Ability::Fetch)
|
|
42
37
|
.to receive(:get_permissions)
|
|
43
38
|
.and_return(
|
|
44
39
|
{
|
|
@@ -50,31 +45,6 @@ describe "Stats", type: :request do
|
|
|
50
45
|
"aggregateFieldName" => nil,
|
|
51
46
|
"sourceCollectionName" => "Owner"
|
|
52
47
|
},
|
|
53
|
-
{
|
|
54
|
-
"type" => "Objective",
|
|
55
|
-
"sourceCollectionName" => "Owner",
|
|
56
|
-
"aggregateFieldName" => nil,
|
|
57
|
-
"aggregator" => "Count",
|
|
58
|
-
"objective" => 200,
|
|
59
|
-
"filter" => nil,
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
"type" => "Pie",
|
|
63
|
-
"sourceCollectionName" => "Owner",
|
|
64
|
-
"aggregateFieldName" => nil,
|
|
65
|
-
"groupByFieldName" => "id",
|
|
66
|
-
"aggregator" => "Count",
|
|
67
|
-
"filter" => nil,
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
"type" => "Line",
|
|
71
|
-
"sourceCollectionName" => "Owner",
|
|
72
|
-
"aggregateFieldName" => nil,
|
|
73
|
-
"groupByFieldName" => "hired_at",
|
|
74
|
-
"aggregator" => "Count",
|
|
75
|
-
"timeRange" => "Week",
|
|
76
|
-
"filter" => nil,
|
|
77
|
-
},
|
|
78
48
|
{
|
|
79
49
|
"type" => "Value",
|
|
80
50
|
"query" => "SELECT COUNT(*) AS value FROM products;"
|
|
@@ -83,9 +53,13 @@ describe "Stats", type: :request do
|
|
|
83
53
|
}
|
|
84
54
|
)
|
|
85
55
|
|
|
86
|
-
ForestLiana::ScopeManager.
|
|
87
|
-
|
|
88
|
-
|
|
56
|
+
ForestLiana::ScopeManager.class_variable_set(:@@scopes_cache, {
|
|
57
|
+
'1' => {
|
|
58
|
+
:fetched_at => Time.now,
|
|
59
|
+
:scopes => {}
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
|
|
89
63
|
allow(ForestLiana).to receive(:apimap).and_return(schema)
|
|
90
64
|
allow(ForestLiana::IpWhitelist).to receive(:retrieve) { true }
|
|
91
65
|
allow(ForestLiana::IpWhitelist).to receive(:is_ip_whitelist_retrieved) { true }
|
|
@@ -40,23 +40,6 @@ module ForestLiana
|
|
|
40
40
|
|
|
41
41
|
expect(removed_fields).to be_empty
|
|
42
42
|
end
|
|
43
|
-
|
|
44
|
-
context 'when the polymorphic support was disabled' do
|
|
45
|
-
it 'should not define the association' do
|
|
46
|
-
ENV['ENABLE_SUPPORT_POLYMORPHISM'] = 'false'
|
|
47
|
-
Bootstrapper.new(true)
|
|
48
|
-
collection = ForestLiana.apimap.find do |object|
|
|
49
|
-
object.name.to_s == ForestLiana.name_for(Address)
|
|
50
|
-
end
|
|
51
|
-
association = collection.fields.find { |field| field[:field] == 'addressable' }
|
|
52
|
-
fields = collection.fields.select do |field|
|
|
53
|
-
field[:field] == 'addressable_id' || field[:field] == 'addressable_type'
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
expect(association).to be_nil
|
|
57
|
-
expect(fields.size).to eq(2)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
43
|
end
|
|
61
44
|
|
|
62
45
|
context 'with an "unhandled" column types (binary, postgis geography, ...)' do
|
data/spec/spec_helper.rb
CHANGED
|
@@ -19,7 +19,6 @@ SimpleCov.add_filter ['app/services/forest_liana/ability/fetch.rb', 'lib/forest_
|
|
|
19
19
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
20
20
|
RSpec.configure do |config|
|
|
21
21
|
ENV['RAILS_ENV'] = 'test'
|
|
22
|
-
ENV['ENABLE_SUPPORT_POLYMORPHISM'] = 'true'
|
|
23
22
|
|
|
24
23
|
require File.expand_path('../dummy/config/environment', __FILE__)
|
|
25
24
|
|
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: 9.0.0.beta.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sandro Munda
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-
|
|
11
|
+
date: 2024-01-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -542,9 +542,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
542
542
|
version: '0'
|
|
543
543
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
544
544
|
requirements:
|
|
545
|
-
- - "
|
|
545
|
+
- - ">"
|
|
546
546
|
- !ruby/object:Gem::Version
|
|
547
|
-
version:
|
|
547
|
+
version: 1.3.1
|
|
548
548
|
requirements: []
|
|
549
549
|
rubygems_version: 3.3.5
|
|
550
550
|
signing_key:
|