forest_admin_agent 1.0.0.pre.beta.75 → 1.0.0.pre.beta.77
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/lib/forest_admin_agent/http/router.rb +1 -0
- data/lib/forest_admin_agent/routes/capabilities/collections.rb +45 -0
- data/lib/forest_admin_agent/routes/resources/list.rb +5 -0
- data/lib/forest_admin_agent/utils/context_variables.rb +2 -2
- data/lib/forest_admin_agent/utils/query_string_parser.rb +4 -1
- data/lib/forest_admin_agent/utils/schema/frontend_filterable.rb +2 -64
- data/lib/forest_admin_agent/utils/schema/generator_field.rb +2 -2
- data/lib/forest_admin_agent/utils/schema/schema_emitter.rb +1 -1
- data/lib/forest_admin_agent/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acb44dc3e46d11e1cf6ff2cc910f8c337bf499df84a12e508f641af9b6a07188
|
4
|
+
data.tar.gz: 65f2a20cebb62e62b9ed67de3ef692b71765eaf61b46eb0ff603606577efde9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5086df998e3f22f9d04772f29375c33f13469aa98849045a6db9c96d1569286258f7c97fb75bb24a0d4a3dfbe61c7193d17932c625e66ee323541a37d9f676db
|
7
|
+
data.tar.gz: 957247e377111b6b48c5e69fdf375bbf7c3890043a254a16af7cfe2a5ce366d7011222dffd60438413cd3c59444399a5d8eec0371787112370773d4a0f5e94c9
|
@@ -11,6 +11,7 @@ module ForestAdminAgent
|
|
11
11
|
Security::Authentication.new.routes,
|
12
12
|
Security::ScopeInvalidation.new.routes,
|
13
13
|
Charts::Charts.new.routes,
|
14
|
+
Capabilities::Collections.new.routes,
|
14
15
|
Resources::Count.new.routes,
|
15
16
|
Resources::Delete.new.routes,
|
16
17
|
Resources::Csv.new.routes,
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'json'
|
2
|
+
module ForestAdminAgent
|
3
|
+
module Routes
|
4
|
+
module Capabilities
|
5
|
+
class Collections < AbstractAuthenticatedRoute
|
6
|
+
include ForestAdminDatasourceToolkit::Schema
|
7
|
+
|
8
|
+
def setup_routes
|
9
|
+
add_route('forest_capabilities_collections',
|
10
|
+
'post',
|
11
|
+
'/_internal/capabilities',
|
12
|
+
->(args) { handle_request(args) })
|
13
|
+
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def handle_request(args = {})
|
18
|
+
@datasource = ForestAdminAgent::Facades::Container.datasource
|
19
|
+
collections = args[:params]['collectionNames'] || []
|
20
|
+
|
21
|
+
result = collections.map do |collection_name|
|
22
|
+
collection = @datasource.get_collection(collection_name)
|
23
|
+
{
|
24
|
+
name: collection.name,
|
25
|
+
fields: collection.schema[:fields].select { |_, field| field.is_a?(ColumnSchema) }.map do |name, field|
|
26
|
+
{
|
27
|
+
name: name,
|
28
|
+
type: field.column_type,
|
29
|
+
operators: field.filter_operators.map { |operator| operator }
|
30
|
+
}
|
31
|
+
end
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
{
|
36
|
+
content: {
|
37
|
+
collections: result
|
38
|
+
},
|
39
|
+
status: 200
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -5,6 +5,8 @@ module ForestAdminAgent
|
|
5
5
|
module Resources
|
6
6
|
class List < AbstractAuthenticatedRoute
|
7
7
|
include ForestAdminDatasourceToolkit::Components::Query::ConditionTree
|
8
|
+
include ForestAdminDatasourceToolkit::Validations
|
9
|
+
|
8
10
|
def setup_routes
|
9
11
|
add_route('forest_list', 'get', '/:collection_name', ->(args) { handle_request(args) })
|
10
12
|
|
@@ -14,6 +16,7 @@ module ForestAdminAgent
|
|
14
16
|
def handle_request(args = {})
|
15
17
|
build(args)
|
16
18
|
@permissions.can?(:browse, @collection)
|
19
|
+
|
17
20
|
filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new(
|
18
21
|
condition_tree: ConditionTreeFactory.intersect([
|
19
22
|
@permissions.get_scope(@collection),
|
@@ -28,6 +31,8 @@ module ForestAdminAgent
|
|
28
31
|
segment: ForestAdminAgent::Utils::QueryStringParser.parse_segment(@collection, args)
|
29
32
|
)
|
30
33
|
|
34
|
+
ConditionTreeValidator.validate(filter.condition_tree, @collection) if filter.condition_tree
|
35
|
+
|
31
36
|
projection = ForestAdminAgent::Utils::QueryStringParser.parse_projection_with_pks(@collection, args)
|
32
37
|
records = @collection.list(@caller, filter, projection)
|
33
38
|
|
@@ -29,9 +29,9 @@ module ForestAdminAgent
|
|
29
29
|
end
|
30
30
|
|
31
31
|
if context_variable_key.start_with?(USER_VALUE_TAG_PREFIX)
|
32
|
+
tag_key = context_variable_key[USER_VALUE_TAG_PREFIX.length..]
|
32
33
|
user[:tags].each do |tag|
|
33
|
-
|
34
|
-
return tag[match_key] if tag.key?(match_key)
|
34
|
+
return tag['value'] if tag['key'] == tag_key
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -8,6 +8,7 @@ module ForestAdminAgent
|
|
8
8
|
include ForestAdminDatasourceToolkit::Exceptions
|
9
9
|
include ForestAdminDatasourceToolkit::Components
|
10
10
|
include ForestAdminDatasourceToolkit::Components::Query
|
11
|
+
include ForestAdminDatasourceToolkit::Validations
|
11
12
|
|
12
13
|
DEFAULT_ITEMS_PER_PAGE = '15'.freeze
|
13
14
|
DEFAULT_PAGE_TO_SKIP = '1'.freeze
|
@@ -23,8 +24,10 @@ module ForestAdminAgent
|
|
23
24
|
return if filters.nil?
|
24
25
|
|
25
26
|
filters = JSON.parse(filters, symbolize_names: true) if filters.is_a? String
|
27
|
+
condition_tree = ConditionTreeParser.from_plain_object(collection, filters)
|
28
|
+
ConditionTreeValidator.validate(condition_tree, collection)
|
26
29
|
|
27
|
-
|
30
|
+
condition_tree
|
28
31
|
end
|
29
32
|
|
30
33
|
def self.parse_caller(args)
|
@@ -1,71 +1,9 @@
|
|
1
|
-
require 'digest/sha1'
|
2
|
-
require 'json'
|
3
|
-
|
4
1
|
module ForestAdminAgent
|
5
2
|
module Utils
|
6
3
|
module Schema
|
7
4
|
class FrontendFilterable
|
8
|
-
|
9
|
-
|
10
|
-
BASE_OPERATORS = [
|
11
|
-
Operators::EQUAL, Operators::NOT_EQUAL, Operators::PRESENT, Operators::BLANK
|
12
|
-
].freeze
|
13
|
-
|
14
|
-
BASE_DATEONLY_OPERATORS = [
|
15
|
-
Operators::TODAY,
|
16
|
-
Operators::YESTERDAY,
|
17
|
-
Operators::PREVIOUS_X_DAYS,
|
18
|
-
Operators::PREVIOUS_WEEK,
|
19
|
-
Operators::PREVIOUS_MONTH,
|
20
|
-
Operators::PREVIOUS_QUARTER,
|
21
|
-
Operators::PREVIOUS_YEAR,
|
22
|
-
Operators::PREVIOUS_X_DAYS_TO_DATE,
|
23
|
-
Operators::PREVIOUS_WEEK_TO_DATE,
|
24
|
-
Operators::PREVIOUS_MONTH_TO_DATE,
|
25
|
-
Operators::PREVIOUS_QUARTER_TO_DATE,
|
26
|
-
Operators::PREVIOUS_YEAR_TO_DATE,
|
27
|
-
Operators::PAST,
|
28
|
-
Operators::FUTURE,
|
29
|
-
Operators::BEFORE_X_HOURS_AGO,
|
30
|
-
Operators::AFTER_X_HOURS_AGO,
|
31
|
-
Operators::BEFORE,
|
32
|
-
Operators::AFTER
|
33
|
-
].freeze
|
34
|
-
|
35
|
-
DATE_OPERATORS = BASE_OPERATORS + BASE_DATEONLY_OPERATORS
|
36
|
-
|
37
|
-
OPERATOR_BY_TYPE = {
|
38
|
-
'Binary' => BASE_OPERATORS,
|
39
|
-
'Boolean' => BASE_OPERATORS,
|
40
|
-
'Date' => DATE_OPERATORS,
|
41
|
-
'Dateonly' => DATE_OPERATORS,
|
42
|
-
'Uuid' => BASE_OPERATORS,
|
43
|
-
'Enum' => BASE_OPERATORS + [Operators::IN],
|
44
|
-
'Number' => BASE_OPERATORS + [Operators::IN, Operators::GREATER_THAN, Operators::LESS_THAN],
|
45
|
-
'Timeonly' => BASE_OPERATORS + [Operators::GREATER_THAN, Operators::LESS_THAN],
|
46
|
-
'String' => BASE_OPERATORS +
|
47
|
-
[
|
48
|
-
Operators::IN,
|
49
|
-
Operators::STARTS_WITH,
|
50
|
-
Operators::ENDS_WITH,
|
51
|
-
Operators::CONTAINS,
|
52
|
-
Operators::NOT_CONTAINS
|
53
|
-
],
|
54
|
-
'Json' => []
|
55
|
-
}.freeze
|
56
|
-
|
57
|
-
def self.filterable?(type, supported_operators = [])
|
58
|
-
needed_operators = get_required_operators(type)
|
59
|
-
|
60
|
-
!needed_operators.empty? && needed_operators.all? { |operator| supported_operators.include?(operator) }
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.get_required_operators(type)
|
64
|
-
return OPERATOR_BY_TYPE[type] if type.is_a?(String) && OPERATOR_BY_TYPE.key?(type)
|
65
|
-
|
66
|
-
return [Operators::INCLUDES_ALL] if type.is_a? Array
|
67
|
-
|
68
|
-
[]
|
5
|
+
def self.filterable?(operator)
|
6
|
+
operator && !operator.empty?
|
69
7
|
end
|
70
8
|
end
|
71
9
|
end
|
@@ -37,7 +37,7 @@ module ForestAdminAgent
|
|
37
37
|
field: name,
|
38
38
|
integration: nil,
|
39
39
|
inverseOf: nil,
|
40
|
-
isFilterable: FrontendFilterable.filterable?(column.
|
40
|
+
isFilterable: FrontendFilterable.filterable?(column.filter_operators),
|
41
41
|
isPrimaryKey: column.is_primary_key,
|
42
42
|
|
43
43
|
# When a column is a foreign key, it is readonly.
|
@@ -70,7 +70,7 @@ module ForestAdminAgent
|
|
70
70
|
|
71
71
|
def foreign_collection_filterable?(foreign_collection)
|
72
72
|
foreign_collection.schema[:fields].values.any? do |field|
|
73
|
-
field.type == 'Column' && FrontendFilterable.filterable?(field.
|
73
|
+
field.type == 'Column' && FrontendFilterable.filterable?(field.filter_operators)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forest_admin_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.beta.
|
4
|
+
version: 1.0.0.pre.beta.77
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-10-
|
12
|
+
date: 2024-10-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -245,6 +245,7 @@ files:
|
|
245
245
|
- lib/forest_admin_agent/routes/abstract_related_route.rb
|
246
246
|
- lib/forest_admin_agent/routes/abstract_route.rb
|
247
247
|
- lib/forest_admin_agent/routes/action/actions.rb
|
248
|
+
- lib/forest_admin_agent/routes/capabilities/collections.rb
|
248
249
|
- lib/forest_admin_agent/routes/charts/api_chart_collection.rb
|
249
250
|
- lib/forest_admin_agent/routes/charts/api_chart_datasource.rb
|
250
251
|
- lib/forest_admin_agent/routes/charts/charts.rb
|