forest_admin_datasource_toolkit 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: f8326b38422a350c825c0285cff2d498ebeb44afa940f3ea351ce62cbb55c367
4
- data.tar.gz: 4d8c43cdcedadb7253171e67d5b4c516df7f1d2379d566102db967ca2fb85fc1
3
+ metadata.gz: 10f5f2fa8864db325ce151f569c2e438775ae5c18738fa2bc3de7f54119f1b1a
4
+ data.tar.gz: 72c8a79a285a7457c3d8757d6ba4f99079076f8002c59ec64d0f41ac0411269c
5
5
  SHA512:
6
- metadata.gz: 8b0048d34fee5deb83a2eb0a151e9c4837586e3309f846d4b8ad90a43857628f3488fc44342b58e0a822fa8e2618b01e6267fff458ef208a30558721fd2349b6
7
- data.tar.gz: 285fd1c47c785df4a92c3ec61eba58605e34c569d1ff84af139de25617842d10322c576fd8639baa07d51edb913b961f24d146b3844703a604a08684fc8ec557
6
+ metadata.gz: 75acf62baf319e7cc728897a42fc4d1edbece85d5a64bedb6a4720a6387c7b78ae5c84ac3b4c93027d0410215f7cf45de3b4b28766e7ff28d1d41def788ea2ec
7
+ data.tar.gz: 81af933d91fbdc333e2f2c9249d79bee037e436becfd8fd1046b4d6b3afbfd65ceb701e860769b50b2598c047193d130f798d161fe30373841ed88885fc0d2a5
@@ -2,10 +2,11 @@ module ForestAdminDatasourceToolkit
2
2
  module Schema
3
3
  module Relations
4
4
  class ManyToOneSchema < RelationSchema
5
- attr_accessor :foreign_key, :foreign_key_target
5
+ attr_accessor :foreign_key, :foreign_key_target, :is_filterable
6
6
 
7
- def initialize(foreign_key:, foreign_key_target:, foreign_collection:, is_read_only: false)
7
+ def initialize(foreign_key:, foreign_key_target:, foreign_collection:, is_read_only: false, is_filterable: true)
8
8
  super(foreign_collection, 'ManyToOne', is_read_only: is_read_only)
9
+ @is_filterable = is_filterable
9
10
  @foreign_key = foreign_key
10
11
  @foreign_key_target = foreign_key_target
11
12
  end
@@ -2,10 +2,11 @@ module ForestAdminDatasourceToolkit
2
2
  module Schema
3
3
  module Relations
4
4
  class OneToOneSchema < RelationSchema
5
- attr_accessor :origin_key, :origin_key_target
5
+ attr_accessor :origin_key, :origin_key_target, :is_filterable
6
6
 
7
- def initialize(origin_key:, origin_key_target:, foreign_collection:, is_read_only: false)
7
+ def initialize(origin_key:, origin_key_target:, foreign_collection:, is_read_only: false, is_filterable: true)
8
8
  super(foreign_collection, 'OneToOne', is_read_only: is_read_only)
9
+ @is_filterable = is_filterable
9
10
  @origin_key = origin_key
10
11
  @origin_key_target = origin_key_target
11
12
  end
@@ -32,6 +32,7 @@ module ForestAdminDatasourceToolkit
32
32
  def self.validate_leaf(leaf, collection)
33
33
  field_schema = Utils::Collection.get_field_schema(collection, leaf.field)
34
34
 
35
+ throw_if_relation_not_filterable(leaf, collection)
35
36
  throw_if_operator_not_allowed_with_column(leaf, field_schema)
36
37
  throw_if_value_not_allowed_with_operator(leaf, field_schema)
37
38
  throw_if_operator_not_allowed_with_column_type(leaf, field_schema)
@@ -40,13 +41,27 @@ module ForestAdminDatasourceToolkit
40
41
  nil
41
42
  end
42
43
 
44
+ def self.throw_if_relation_not_filterable(leaf, collection)
45
+ current = collection
46
+
47
+ leaf.field.split(':')[0...-1].each do |relation_name|
48
+ relation = current.schema[:fields][relation_name]
49
+
50
+ if relation.respond_to?(:is_filterable) && relation.is_filterable == false
51
+ raise Exceptions::ValidationError, "The relation '#{current.name}.#{relation_name}' is not filterable"
52
+ end
53
+
54
+ current = current.datasource.get_collection(relation.foreign_collection)
55
+ end
56
+ end
57
+
43
58
  def self.throw_if_operator_not_allowed_with_column(leaf, column_schema)
44
59
  operators = column_schema.filter_operators
45
60
  return if operators.include?(leaf.operator)
46
61
 
47
62
  raise Exceptions::ValidationError,
48
63
  "The given operator '#{leaf.operator}' is not supported by the column: '#{leaf.field}'." \
49
- "#{operators.empty? ? " The allowed types are: #{operators.join(",")}" : " The column is not filterable"}"
64
+ "#{operators.empty? ? " The column is not filterable" : " The allowed types are: #{operators.join(",")}"}"
50
65
  end
51
66
 
52
67
  def self.throw_if_value_not_allowed_with_operator(leaf, column_schema)
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceToolkit
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_toolkit
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