Package: collective.contentgroup
OverviewThis package is a Plone add-on that allows to associate users groups with
content objects. It works this way: the content type class implementIObjectWithGroup, normally inheriting fromObjectWithGroupMixin,
and this package takes care of creating a correspondent users group for each new
content object.CompatibilityTested with Plone 3.2.3,probablyworks with 3.x and 4.x.Example usageUse case: We want to create aCompanycontent type. EachCompanymust
have a correspondent users group.First we create the content type class. It could be a common Archetype class,
but here we’ll create a simpler one, without the AT base classes. We’ll useObjectWithGroupMixinfrom thebasemodule in order to get associated
group support:>>> from zope.event import notify
>>> from zope.app.container.contained import ObjectRemovedEvent
>>> from Products.Archetypes.event import (ObjectInitializedEvent,
...     ObjectEditedEvent)
>>> from collective.contentgroup.base import ObjectWithGroupMixin
>>> class Company(ObjectWithGroupMixin):
...     __parent__ = None
...
...     def __init__(self, id, title):
...         self.id = self.__name__ = id
...         self.title = title
...         notify(ObjectInitializedEvent(self))
...
...     def getId(self):
...         return self.id
...
...     def Title(self):
...         return self.title
...
...     def setTitle(self, title):
...         self.title = title
...         notify(ObjectEditedEvent(self))
...
...     def delete_me(self):
...         notify(ObjectRemovedEvent(self))
...         self.id = self.title = NoneNow we can create aCompanyinstance and see if we get a correspondent
group created:>>> from Products.CMFCore.utils import getToolByName
>>> c = Company('acme', 'The ACME Corporation')
>>> gtool = getToolByName(portal, 'portal_groups')
>>> group = gtool.getGroupById(c.get_group_name())
>>> group.getProperty('title') == c.get_group_title()
TrueLet’s check if the group’s name and title were generated as expected by theContentWithGroupMixinclass:>>> c.getId() in c.get_group_name()
True
>>> c.Title() in c.get_group_title()
TrueLet’s change the company title and see if the group’s title also changes:>>> c.setTitle('ACME co.')
>>> group = gtool.getGroupById(c.get_group_name())
>>> group.getProperty('title') == c.get_group_title()
TrueLet’s delete the company and see if the group is also removed:>>> group_name = c.get_group_name() # Save the group name before it's
>>>                                 # deleted.
>>> c.delete_me()
>>> gtool.getGroupById(group_name) is None
TrueCustomizing aspects of group creation, removal and editionThe group managing is done through theIGroupManagerinterface. An instance
of this interface is acquired via adaptaion every time a group operation has
to be done. One can customize the group managing operations by registering an
adapter for an specific content type, providingIGroupManager.The default adapter is registered in ZCML like this:<adapter
    for="*"
    provides=".interfaces.IGroupManager"
    factory=".groupmanager.PortalGroupsGroupManager"
/>In thegroupmanagermodule there’s also theDGPGroupsGroupManagerwhich
uses the DynamicGroupsPlugin.
It allows for creation of dynamic groups, i.e, the members of the group are
dynamically calculated.CreditsRafael Oliveira <rafaelbco@gmail.com>: Author.Changelog0.1b3 - 18mai2010Removed buggy cache in DynamicGroupsPlugin method.0.1b2 - 18mai2010Added support to DynamicGroupsPlugin, i.e, an IGroupManager which uses this
plugin was created.Added @@fix-content-groups view.0.1b1 - 15feb2010First release.