forest_admin_datasource_customizer 1.44.5 → 1.45.0
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 91c98f72bfd1a496e5b96bb8ea6cb15797fada18484dcd9004fbc3e06252fb75
|
|
4
|
+
data.tar.gz: 33f453083d6b9e7e52d487aa84d6cc1f552752dd955b39020516d64659cc837a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a155664f5332580681978b0a65061e363e7f3512773c75e35cfefa155614089cf48a783ab6bc01481d1db32499450ba907849c3effae601267b99bc1e96b6cde
|
|
7
|
+
data.tar.gz: c58138c71a687533cbf7abf4841e4d5f33c861b37a0f45076bbec6bb1d28c148c8c9c2b057e8a3db211f943147d072bf121a486081654943b98ab62dd530727e
|
|
@@ -67,6 +67,17 @@ module ForestAdminDatasourceCustomizer
|
|
|
67
67
|
push_customization { @stack.search.get_collection(@name).disable_search }
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
+
# Disable filtering on a column, or on a many to one / one to one relation, for the end-user.
|
|
71
|
+
# Filters coming from the UI or the API (including UI segments and saved views) are rejected.
|
|
72
|
+
# Customizations still filter on it: a column can be the key of a custom relation, and a
|
|
73
|
+
# relation can be used by code segments and search.
|
|
74
|
+
# Example:
|
|
75
|
+
# collection.disable_field_filtering('reference_code')
|
|
76
|
+
# collection.disable_field_filtering('author')
|
|
77
|
+
def disable_field_filtering(name)
|
|
78
|
+
push_customization { @stack.schema.get_collection(@name).disable_field_filtering(name) }
|
|
79
|
+
end
|
|
80
|
+
|
|
70
81
|
def add_field(name, definition)
|
|
71
82
|
push_customization do
|
|
72
83
|
collection_before_relations = @stack.early_computed.get_collection(@name)
|
data/lib/forest_admin_datasource_customizer/decorators/schema/schema_collection_decorator.rb
CHANGED
|
@@ -2,9 +2,14 @@ module ForestAdminDatasourceCustomizer
|
|
|
2
2
|
module Decorators
|
|
3
3
|
module Schema
|
|
4
4
|
class SchemaCollectionDecorator < ForestAdminDatasourceToolkit::Decorators::CollectionDecorator
|
|
5
|
+
include ForestAdminDatasourceToolkit::Exceptions
|
|
6
|
+
|
|
7
|
+
FILTER_DISABLEABLE_TYPES = %w[Column ManyToOne OneToOne].freeze
|
|
8
|
+
|
|
5
9
|
def initialize(child_collection, datasource)
|
|
6
10
|
super
|
|
7
11
|
@schema_override = {}
|
|
12
|
+
@unfilterable_fields = Set.new
|
|
8
13
|
end
|
|
9
14
|
|
|
10
15
|
def override_schema(value)
|
|
@@ -12,8 +17,48 @@ module ForestAdminDatasourceCustomizer
|
|
|
12
17
|
mark_schema_as_dirty
|
|
13
18
|
end
|
|
14
19
|
|
|
20
|
+
def disable_field_filtering(name)
|
|
21
|
+
field = child_collection.schema[:fields][name]
|
|
22
|
+
|
|
23
|
+
raise ValidationError, "Field not found: '#{self.name}.#{name}'" if field.nil?
|
|
24
|
+
|
|
25
|
+
unless FILTER_DISABLEABLE_TYPES.include?(field.type)
|
|
26
|
+
raise ValidationError,
|
|
27
|
+
"Unexpected field type: '#{self.name}.#{name}' " \
|
|
28
|
+
"(found '#{field.type}' expected 'Column', 'ManyToOne' or 'OneToOne')"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
if field.type == 'Column' && field.is_primary_key
|
|
32
|
+
raise ValidationError, "Cannot disable filtering on primary key '#{self.name}.#{name}'"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
@unfilterable_fields.add(name)
|
|
36
|
+
mark_schema_as_dirty
|
|
37
|
+
end
|
|
38
|
+
|
|
15
39
|
def refine_schema(sub_schema)
|
|
16
|
-
sub_schema.merge(@schema_override)
|
|
40
|
+
schema = sub_schema.merge(@schema_override)
|
|
41
|
+
return schema if @unfilterable_fields.empty?
|
|
42
|
+
|
|
43
|
+
schema[:fields] = schema[:fields].dup
|
|
44
|
+
@unfilterable_fields.each { |name| schema[:fields][name] = unfilterable_copy(schema[:fields][name]) }
|
|
45
|
+
|
|
46
|
+
schema
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
# Field schemas are shared with the decorators below, which must keep filtering on this field.
|
|
52
|
+
def unfilterable_copy(field)
|
|
53
|
+
copy = field.dup
|
|
54
|
+
|
|
55
|
+
if field.type == 'Column'
|
|
56
|
+
copy.filter_operators = []
|
|
57
|
+
else
|
|
58
|
+
copy.is_filterable = false
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
copy
|
|
17
62
|
end
|
|
18
63
|
end
|
|
19
64
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: forest_admin_datasource_customizer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.45.0
|
|
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: 2026-10-
|
|
12
|
+
date: 2026-10-07 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|