forest_admin_agent 1.0.0.pre.beta.75 → 1.0.0.pre.beta.76
Sign up to get free protection for your applications and to get access to all the features.
- 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 +2 -0
- 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: c8512cd53690bf9d4dfe5ad0ee894fa308390e22683ff411726f6e6892763215
|
4
|
+
data.tar.gz: e96548c4909f79841112435af1bb62065e7dfcad7f740df2f440cd9205159129
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77678a218ecb0df323f22e5ac63472114f0e3f8bd3cbec43de66ae4401fddb67d177e0e7b41122f9d11b9bc9728700dd0692f404a18f3088b41605085d027f45
|
7
|
+
data.tar.gz: df00ead64c5c4fa35f5a71439b026e386a447d2c318724f8940bd5d6ca2bc9de7dd249ca9f4ca879afcd47d97e508df01eb34b501ecfdc31fa53e912ec72c766
|
@@ -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,7 @@ module ForestAdminAgent
|
|
5
5
|
module Resources
|
6
6
|
class List < AbstractAuthenticatedRoute
|
7
7
|
include ForestAdminDatasourceToolkit::Components::Query::ConditionTree
|
8
|
+
|
8
9
|
def setup_routes
|
9
10
|
add_route('forest_list', 'get', '/:collection_name', ->(args) { handle_request(args) })
|
10
11
|
|
@@ -14,6 +15,7 @@ module ForestAdminAgent
|
|
14
15
|
def handle_request(args = {})
|
15
16
|
build(args)
|
16
17
|
@permissions.can?(:browse, @collection)
|
18
|
+
|
17
19
|
filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new(
|
18
20
|
condition_tree: ConditionTreeFactory.intersect([
|
19
21
|
@permissions.get_scope(@collection),
|
@@ -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.76
|
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
|