Skip to content

Commit

Permalink
move _createObjectByType as unrestricted_construct_instance to here
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Apr 27, 2022
1 parent d22ddbd commit c84d32a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions news/8.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Move `Products.CMFPlone.utils._createObjectByType to here as `utils.unrestricted_construct_instance`.
[jensens]
20 changes: 20 additions & 0 deletions src/plone/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,23 @@ def get_user_friendly_types(types_list=None):
types = {t for t in types_list if t in types}
friendly_types = types - set(search_settings.types_not_searched)
return list(friendly_types)


def unrestricted_construct_instance(type_name, container, id, *args, **kw):
"""Create an object without performing security checks
invokeFactory and fti.constructInstance perform some security checks
before creating the object. Use this function instead if you need to
skip these checks.
This method uses
CMFCore.TypesTool.FactoryTypeInformation._constructInstance
to create the object without security checks.
"""
id = str(id)
typesTool = getToolByName(container, 'portal_types')
fti = typesTool.getTypeInfo(type_name)
if not fti:
raise ValueError('Invalid type %s' % type_name)

return fti._constructInstance(container, id, *args, **kw)

0 comments on commit c84d32a

Please sign in to comment.