Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choose valid id if id is provided for content creation #1614

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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