Skip to content

Commit

Permalink
Choose valid id if id is provided for content creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ksuess committed Mar 31, 2023
1 parent b15ddc0 commit 696edbc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions news/1613.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Choose valid id if id is provided for content creation.
@ksuess
6 changes: 4 additions & 2 deletions src/plone/restapi/services/content/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def add(container, obj, rename=True):
obj._renameAfterCreation(check_auto_id=True)
return obj
else:
chooser = INameChooser(container)
if rename:
chooser = INameChooser(container)
# INameFromTitle adaptable objects should not get a name
# suggestion. NameChooser would prefer the given name instead of
# the one provided by the INameFromTitle adapter.
Expand All @@ -91,7 +91,9 @@ def add(container, obj, rename=True):
if name_from_title is None:
suggestion = obj.Title()
id_ = chooser.chooseName(suggestion, obj)
obj.id = id_
else:
id_ = chooser.chooseName(id_, obj)
obj.id = id_
new_id = container._setObject(id_, obj)
# _setObject triggers ObjectAddedEvent which can end up triggering a
# content rule to move the item to a different container. In this case
Expand Down

0 comments on commit 696edbc

Please sign in to comment.