9
9
from plone .app .linkintegrity .exceptions import LinkIntegrityNotificationException
10
10
from plone .app .uuid .utils import uuidToObject
11
11
from plone .dexterity .fti import DexterityFTI
12
- from plone .dexterity .utils import addContentToContainer
13
12
from plone .dexterity .utils import createContent
14
13
from plone .uuid .interfaces import IUUID
15
14
from Products .CMFCore .DynamicType import DynamicType
@@ -76,6 +75,12 @@ def create(
76
75
if isinstance (fti , DexterityFTI ):
77
76
# For dexterity objects we want to not use the invokeFactory
78
77
# method because we want to have the id generated by the name chooser
78
+ if not fti .isConstructionAllowed (container ):
79
+ raise ValueError (f"Cannot create { type } " )
80
+
81
+ container_fti = container .getTypeInfo ()
82
+ if container_fti is not None and not container_fti .allowType (type ):
83
+ raise ValueError (f"Disallowed subobject type: { type } " )
79
84
constraints = IConstrainTypes (container , None )
80
85
if constraints and fti not in constraints .allowedContentTypes ():
81
86
raise ValueError (
@@ -85,18 +90,23 @@ def create(
85
90
kwargs ["id" ] = id
86
91
content = createContent (type , ** kwargs )
87
92
88
- if not content .id :
89
- content .id = INameChooser (container ).chooseName (title , content )
90
- if not safe_id :
91
- content .id = INameChooser (container ).chooseName (
92
- content .id or title , content
93
- )
94
- if id and id != content .id :
95
- raise BadRequest (
96
- "The id you provided conflicts with an existing object or it is reserved"
97
- )
98
- addContentToContainer (container , content )
99
- content_id = content .id
93
+ name_chooser = INameChooser (container )
94
+ if content .id :
95
+ # Check that the id we picked is valid
96
+ if not name_chooser .checkName (content .id , content ):
97
+ if safe_id :
98
+ content .id = INameChooser (container ).chooseName (
99
+ content .id , content
100
+ )
101
+ else :
102
+ raise BadRequest (
103
+ "The id you provided conflicts with "
104
+ "an existing object or it is reserved"
105
+ )
106
+ else :
107
+ content .id = name_chooser .chooseName (title , content )
108
+
109
+ content_id = container ._setObject (content .id , content )
100
110
else :
101
111
content_id = not safe_id and id or str (random .randint (0 , 99999999 ))
102
112
container .invokeFactory (type , content_id , ** kwargs )
0 commit comments