Hello everyone, do you know a way (on a Plone 5.1) to send a notification email to the owner of a container (it can be a folder or an other folderish dexterity type built ttw) each time a new content is created in this container? (most often by an other user than the owner of the initial container)?
No matter how much I looked in the contentrule, it seems to be missing something that would be equivalent to $ {parent_owner_email} ... Do you see a possible solution for this use case?
"As the owner of an object that can contain other objects, I receive an email each time someone adds an object in the object that i am the owner"
If you have some experience writing a Plone addon (and there's trainings for that), you can create a custom content rules variable, it's relatively easy to do so. Basically, you'd need to register an adapter, something like plone.stringinterp/adapters.py at master · plone/plone.stringinterp · GitHub but instead of self.context.listCreators you'd do self.context.aq_parent.listCreators().
PS: Could I, if I don't manage to create everything from the base package, copy and paste the package from plone.stringinterp and use it as a functional add-on (then try to adapt its content) or does it cause licensing issues?
There's no licensing issue. But it will create a lot more problems if you try to duplicate the plone.stringinterp, rather then just creating your own addon.
Heard, thanks @tiberiuichim , so for now I just modified the adapters.py code this way to test ...
@adapter(IDublinCore)
class CreatorSubstitution(BaseSubstitution):
category = _(u'Dublin Core')
description = _(u'Creator Id')
def safe_call(self):
for creator in self.context.aq_parent.listCreators():
return creator
return ''
@adapter(IDublinCore)
class CreatorEmailSubstitution(CreatorSubstitution):
category = _(u'Dublin Core')
description = _(u'Creator E-Mail')
def safe_call(self):
creator = super(CreatorEmailSubstitution, self).safe_call()
if not creator:
return ''
pm = getToolByName(self.context, "portal_membership")
member = pm.getMemberById(creator)
if not member:
return ''
email = member.getProperty('email', '')
if not email:
return ''
return email
@adapter(IDublinCore)
class CreatorsSubstitution(BaseSubstitution):
category = _(u'Dublin Core')
description = _(u'Creators Ids')
def safe_call(self):
return ', '.join(self.context.aq_parent.listCreators())
@adapter(IDublinCore)
class CreatorsEmailsSubstitution(BaseSubstitution):
category = _(u'Dublin Core')
description = _(u'Creators E-Mails')
def safe_call(self):
creators = self.context.listCreators()
pm = getToolByName(self.context, "portal_membership")
emails = []
for creator in creators:
member = pm.getMemberById(creator)
if not member:
continue
email = member.getProperty('email', None)
if not email:
continue
emails.append(email)
return ', '.join(emails)
... and it works perfectly (thanks to your first post). It therefore remains for me to see how to create the smallest possible addon that allows it to be done correctly without creating conflicts with the existing ones.
Could it be limited to having the following in the package?
an _ init_.py file
an adapters.py file (with the above code preceded by some imports)
a configure.zcml file (with 4 new adapter rigistrations to populate the substitutionList () which is called in a browser of the contentrules product)
I haven't merged it but I think this plugin with my PR would get you what want.
A Splitter Condition to execute the rest of the rules conditions and actions
on all elements that match the query, such as all children of a given type.
So you can combine it with an email action to email the parents owner I'm pretty sure.