File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"""Module that provides functionality for content manipulation."""
22
3+ from AccessControl import Unauthorized
34from copy import copy as _copy
45from plone .api import portal
56from plone .api .exc import InvalidParameterError
@@ -76,7 +77,7 @@ def create(
7677 # For dexterity objects we want to not use the invokeFactory
7778 # method because we want to have the id generated by the name chooser
7879 if not fti .isConstructionAllowed (container ):
79- raise ValueError (f"Cannot create { type } " )
80+ raise Unauthorized (f"Cannot create { type } " )
8081
8182 container_fti = container .getTypeInfo ()
8283 if container_fti is not None and not container_fti .allowType (type ):
Original file line number Diff line number Diff line change @@ -387,6 +387,18 @@ def test_create_with_not_lowercase_id(self):
387387 )
388388 self .assertEqual (obj .id , "Doc1" )
389389
390+ def test_create_anonymous_unauthorized (self ):
391+ from AccessControl import Unauthorized
392+ from plone .app .testing import logout
393+
394+ logout ()
395+ with self .assertRaises (Unauthorized ):
396+ api .content .create (
397+ container = self .portal ,
398+ type = "Dexterity Item" ,
399+ id = "foo" ,
400+ )
401+
390402 def test_create_raises_unicodedecodeerror (self ):
391403 """Test that the create method raises UnicodeDecodeErrors correctly."""
392404 site = getGlobalSiteManager ()
You can’t perform that action at this time.
0 commit comments