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
@@ -69,7 +70,7 @@ def create(
6970 # For dexterity objects we want to not use the invokeFactory
7071 # method because we want to have the id generated by the name chooser
7172 if not fti .isConstructionAllowed (container ):
72- raise ValueError (f"Cannot create { type } " )
73+ raise Unauthorized (f"Cannot create { type } " )
7374
7475 container_fti = container .getTypeInfo ()
7576 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,17 @@ 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+ logout ()
394+ with self .assertRaises (Unauthorized ):
395+ obj = api .content .create (
396+ container = self .portal ,
397+ type = "Dexterity Item" ,
398+ id = "foo" ,
399+ )
400+
390401 def test_create_raises_unicodedecodeerror (self ):
391402 """Test that the create method raises UnicodeDecodeErrors correctly."""
392403 site = getGlobalSiteManager ()
You can’t perform that action at this time.
0 commit comments