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: 6eec919aa7f8d1257183fb9f37f13084731f8a9be31e72410130e604bdc5b16a
4
- data.tar.gz: d11e3551840b6281843962c60956ed0879bef98fd31bbf37ea926b6e171b86a2
3
+ metadata.gz: 91c98f72bfd1a496e5b96bb8ea6cb15797fada18484dcd9004fbc3e06252fb75
4
+ data.tar.gz: 33f453083d6b9e7e52d487aa84d6cc1f552752dd955b39020516d64659cc837a
5
5
  SHA512:
6
- metadata.gz: 229871cb6431d184ebcc45ef5be7084647e1bff94e39aa323e596a46ad5eada77c7ffcb748589c0ef18b645ad968538985cac11785af7283121c751939e27d93
7
- data.tar.gz: fb5cf0af05d8ca83b1f35d022c524f8f83d9a014b1b4783275d28c5d2be15f7ce3588f5db002a5df11ca54742a0cf05e5e3198182ef418af31ab80d85730fa20
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)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceCustomizer
2
- VERSION = "1.44.5"
2
+ VERSION = "1.45.0"
3
3
  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.44.5
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-06 00:00:00.000000000 Z
12
+ date: 2026-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport