forest_admin_datasource_toolkit 1.40.0 → 1.40.1
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_datasource_toolkit/schema/relation_schema.rb +3 -2
- data/lib/forest_admin_datasource_toolkit/schema/relations/many_to_many_schema.rb +3 -2
- data/lib/forest_admin_datasource_toolkit/schema/relations/many_to_one_schema.rb +2 -2
- data/lib/forest_admin_datasource_toolkit/schema/relations/one_to_many_schema.rb +2 -2
- data/lib/forest_admin_datasource_toolkit/schema/relations/one_to_one_schema.rb +2 -2
- data/lib/forest_admin_datasource_toolkit/schema/relations/polymorphic_one_to_many_schema.rb +2 -2
- data/lib/forest_admin_datasource_toolkit/schema/relations/polymorphic_one_to_one_schema.rb +2 -2
- data/lib/forest_admin_datasource_toolkit/utils/collection.rb +16 -0
- data/lib/forest_admin_datasource_toolkit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 190a558c8d3e6a33c4a10749196acd2d6c10e2c20cc58061d0c863f6d7c4ab14
|
|
4
|
+
data.tar.gz: 65b56b7ff4f9560b5779727ea89f6aeb17e9c0c990ffa86cc88c6b6724fbe82b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1a57468ace6221245624375b9f64d3098e05314de614b9886d544f5e295f68495cfd3d8ae97bc1bdc77e393cd620d23b59c9986d234aeea44f5dffb8df1b5426
|
|
7
|
+
data.tar.gz: 225e7ff48cfd5ec3cde4d313114ec2490b5badb64e88b929f838240409eb59d544a02e2a1bfe16d953ef4225acf523d55ba3b4c91011f72c85e456137dae4443
|
|
@@ -2,11 +2,12 @@ module ForestAdminDatasourceToolkit
|
|
|
2
2
|
module Schema
|
|
3
3
|
class RelationSchema
|
|
4
4
|
attr_accessor :foreign_collection
|
|
5
|
-
attr_reader :type
|
|
5
|
+
attr_reader :type, :is_read_only
|
|
6
6
|
|
|
7
|
-
def initialize(foreign_collection, type)
|
|
7
|
+
def initialize(foreign_collection, type, is_read_only: false)
|
|
8
8
|
@foreign_collection = foreign_collection
|
|
9
9
|
@type = type
|
|
10
|
+
@is_read_only = is_read_only
|
|
10
11
|
end
|
|
11
12
|
end
|
|
12
13
|
end
|
|
@@ -15,9 +15,10 @@ module ForestAdminDatasourceToolkit
|
|
|
15
15
|
origin_type_field: nil,
|
|
16
16
|
origin_type_value: nil,
|
|
17
17
|
foreign_type_field: nil,
|
|
18
|
-
foreign_type_value: nil
|
|
18
|
+
foreign_type_value: nil,
|
|
19
|
+
is_read_only: false
|
|
19
20
|
)
|
|
20
|
-
super(foreign_collection, 'ManyToMany')
|
|
21
|
+
super(foreign_collection, 'ManyToMany', is_read_only: is_read_only)
|
|
21
22
|
@origin_key = origin_key
|
|
22
23
|
@origin_key_target = origin_key_target
|
|
23
24
|
@through_collection = through_collection
|
|
@@ -4,8 +4,8 @@ module ForestAdminDatasourceToolkit
|
|
|
4
4
|
class ManyToOneSchema < RelationSchema
|
|
5
5
|
attr_accessor :foreign_key, :foreign_key_target
|
|
6
6
|
|
|
7
|
-
def initialize(foreign_key:, foreign_key_target:, foreign_collection:)
|
|
8
|
-
super(foreign_collection, 'ManyToOne')
|
|
7
|
+
def initialize(foreign_key:, foreign_key_target:, foreign_collection:, is_read_only: false)
|
|
8
|
+
super(foreign_collection, 'ManyToOne', is_read_only: is_read_only)
|
|
9
9
|
@foreign_key = foreign_key
|
|
10
10
|
@foreign_key_target = foreign_key_target
|
|
11
11
|
end
|
|
@@ -4,8 +4,8 @@ module ForestAdminDatasourceToolkit
|
|
|
4
4
|
class OneToManySchema < RelationSchema
|
|
5
5
|
attr_accessor :origin_key, :origin_key_target
|
|
6
6
|
|
|
7
|
-
def initialize(origin_key:, origin_key_target:, foreign_collection:)
|
|
8
|
-
super(foreign_collection, 'OneToMany')
|
|
7
|
+
def initialize(origin_key:, origin_key_target:, foreign_collection:, is_read_only: false)
|
|
8
|
+
super(foreign_collection, 'OneToMany', is_read_only: is_read_only)
|
|
9
9
|
@origin_key = origin_key
|
|
10
10
|
@origin_key_target = origin_key_target
|
|
11
11
|
end
|
|
@@ -4,8 +4,8 @@ module ForestAdminDatasourceToolkit
|
|
|
4
4
|
class OneToOneSchema < RelationSchema
|
|
5
5
|
attr_accessor :origin_key, :origin_key_target
|
|
6
6
|
|
|
7
|
-
def initialize(origin_key:, origin_key_target:, foreign_collection:)
|
|
8
|
-
super(foreign_collection, 'OneToOne')
|
|
7
|
+
def initialize(origin_key:, origin_key_target:, foreign_collection:, is_read_only: false)
|
|
8
|
+
super(foreign_collection, 'OneToOne', is_read_only: is_read_only)
|
|
9
9
|
@origin_key = origin_key
|
|
10
10
|
@origin_key_target = origin_key_target
|
|
11
11
|
end
|
|
@@ -6,8 +6,8 @@ module ForestAdminDatasourceToolkit
|
|
|
6
6
|
attr_reader :origin_key_target, :origin_type_field, :cascade_on_delete
|
|
7
7
|
|
|
8
8
|
def initialize(origin_key:, origin_key_target:, foreign_collection:, origin_type_field:, origin_type_value:,
|
|
9
|
-
cascade_on_delete: false)
|
|
10
|
-
super(foreign_collection, 'PolymorphicOneToMany')
|
|
9
|
+
cascade_on_delete: false, is_read_only: false)
|
|
10
|
+
super(foreign_collection, 'PolymorphicOneToMany', is_read_only: is_read_only)
|
|
11
11
|
@origin_key = origin_key
|
|
12
12
|
@origin_key_target = origin_key_target
|
|
13
13
|
@origin_type_field = origin_type_field
|
|
@@ -6,8 +6,8 @@ module ForestAdminDatasourceToolkit
|
|
|
6
6
|
attr_reader :origin_key_target, :origin_type_field, :cascade_on_delete
|
|
7
7
|
|
|
8
8
|
def initialize(origin_key:, origin_key_target:, foreign_collection:, origin_type_field:, origin_type_value:,
|
|
9
|
-
cascade_on_delete: false)
|
|
10
|
-
super(foreign_collection, 'PolymorphicOneToOne')
|
|
9
|
+
cascade_on_delete: false, is_read_only: false)
|
|
10
|
+
super(foreign_collection, 'PolymorphicOneToOne', is_read_only: is_read_only)
|
|
11
11
|
@origin_key = origin_key
|
|
12
12
|
@origin_key_target = origin_key_target
|
|
13
13
|
@origin_type_field = origin_type_field
|
|
@@ -78,6 +78,22 @@ module ForestAdminDatasourceToolkit
|
|
|
78
78
|
)
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
+
# A read-only relation (e.g. #379's has_one :through identity join, which has no real
|
|
82
|
+
# join column and would corrupt the foreign collection's own primary key if written to)
|
|
83
|
+
# only hides its edit control in the UI via isReadOnly -- a direct write still has to be
|
|
84
|
+
# blocked here, at every route that can write to a relation's origin_key/through_collection.
|
|
85
|
+
# ValidationError (not a bare ForestException) so this maps to a 400, not a 500 -- rejecting
|
|
86
|
+
# a write to a non-editable field is a client error, not a server failure.
|
|
87
|
+
#
|
|
88
|
+
# respond_to? guards PolymorphicManyToOneSchema specifically: it doesn't inherit
|
|
89
|
+
# RelationSchema (unlike every other relation type), so it has no is_read_only at all --
|
|
90
|
+
# not a versioning gap, a genuinely different type with no such concept yet.
|
|
91
|
+
def self.assert_writable_relation!(field_name, relation)
|
|
92
|
+
return unless relation.respond_to?(:is_read_only) && relation.is_read_only
|
|
93
|
+
|
|
94
|
+
raise ValidationError, "Field #{field_name} is not editable"
|
|
95
|
+
end
|
|
96
|
+
|
|
81
97
|
def self.get_value(collection, caller, primary_key_values, field)
|
|
82
98
|
if primary_key_values.is_a? Array
|
|
83
99
|
index = Schema.primary_keys(collection).index(field)
|
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.40.
|
|
4
|
+
version: 1.40.1
|
|
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-08-
|
|
12
|
+
date: 2026-08-28 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|