跳转到主要内容

Plone插件,允许将用户组与内容对象关联

项目描述

概述

此包是Plone插件,允许将用户组与内容对象关联。它的工作方式如下:内容类型类实现IObjectWithGroup,通常从ObjectWithGroupMixin继承,此包负责为每个新的内容对象创建相应的用户组。

兼容性

与Plone 3.2.3进行测试,可能 与3.x和4.x兼容。

示例用法

用例:我们想创建一个公司内容类型。每个公司都必须有一个相应的用户组。

首先我们创建内容类型类。它可以是通用的Archetype类,但在这里我们将创建一个更简单的类,不使用AT基类。我们将使用来自base模块的ObjectWithGroupMixin,以便获得关联组支持

>>> 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 = None

现在我们可以创建一个公司实例,并查看是否创建了相应的组

>>> 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()
True

让我们检查组的名称和标题是否由ContentWithGroupMixin类按预期生成

>>> c.getId() in c.get_group_name()
True
>>> c.Title() in c.get_group_title()
True

让我们更改公司标题,看看组的标题是否也更改

>>> c.setTitle('ACME co.')
>>> group = gtool.getGroupById(c.get_group_name())
>>> group.getProperty('title') == c.get_group_title()
True

让我们删除公司,看看组是否也被删除

>>> group_name = c.get_group_name() # Save the group name before it's
>>>                                 # deleted.
>>> c.delete_me()
>>> gtool.getGroupById(group_name) is None
True

自定义组创建、删除和编辑方面的功能

组管理通过 IGroupManager 接口完成。每次进行组操作时,都会通过适配器获取该接口的一个实例。可以通过为特定内容类型注册适配器并提供 IGroupManager 来自定义组管理操作。

默认适配器在 ZCML 中注册如下所示

<adapter
    for="*"
    provides=".interfaces.IGroupManager"
    factory=".groupmanager.PortalGroupsGroupManager"
/>

groupmanager 模块中还有一个 DGPGroupsGroupManager,它使用 DynamicGroupsPlugin。它允许创建动态组,即组成员是动态计算的。

致谢

变更日志

0.1b3 - 2010年5月18日

  • 移除了 DynamicGroupsPlugin 方法中的错误缓存。

0.1b2 - 2010年5月18日

  • 添加了对 DynamicGroupsPlugin 的支持,即创建了一个使用此插件的 IGroupManager。

  • 添加了 @@fix-content-groups 视图。

0.1b1 - 2010年2月15日

  • 第一个版本。

项目详情


下载文件

下载适合您平台文件的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源代码发行版

collective.contentgroup-0.1b3.zip (17.9 kB 查看哈希值)

上传时间 源代码

由以下机构支持