This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Overview

This package provide a simple API to create automatic groups in Plone. Automatic groups are users groups that have its member set automaticaly calculated. The AuthenticatedMembers group is an example automatic group, created by Plone.

Creating an automatic group is simple:

  1. Create a class implementing IMembershipCriteria. This class define a criteria to decied whether an user belongs or not to the group.
  2. Call utils.create_auto_group passing an instance of IMembershipCriteria and other info about the group.

Inside the utils module there are other useful functions.

Example usage

Use case: we want to create an automatic group containing all users whose ID begins with an ‘r’ letter.

First we create a class implementing IMembershipCriteria:

>>> from collective.autogroup.interfaces import IMembershipCriteria
>>> from zope.interface import implements
>>> class MembershipCriteria(object):
...     implements(IMembershipCriteria)
...     def __call__(self, principal):
...         return principal.getId()[0] == 'r'

Now we create the auto group using this criteria:

>>> from Products.CMFCore.utils import getToolByName
>>> from collective.autogroup.utils import create_auto_group
>>> group_name = 'r_users'
>>> group_title = 'Members of r_users'
>>> create_auto_group(
...     acl_users=self.portal.acl_users,
...     criteria=MembershipCriteria(),
...     group_name=group_name,
...     title=group_title,
... )
>>> gtool = getToolByName(self.portal, 'portal_groups')
>>> group = gtool.getGroupById(group_name)
>>> group is not None
True

The group should be empty for now, since we don’t have any users matching the criteria:

>>> len(group.getAllGroupMemberIds())
0

Create some users and see what happens:

>>> user1 = self.add_user('ronaldo')
>>> user2 = self.add_user('romario')
>>> user3 = self.add_user('tostao')
>>> sorted(group.getGroupMemberIds())
['romario', 'ronaldo']
>>> group_name in user1.getGroups()
True
>>> group_name in user2.getGroups()
True
>>> group_name in user3.getGroups()
False

About the group title

Check this out:

>>> not group.getProperty('title')
True

It seems the title of the group is empty, even though we set the title to group_title when we called create_auto_group. It turns out prefs_groups_overview and other Plone templates do not call group.getProperty to get the group title. Even the AuthenticatedUsers group (created by Plone) does not have the title property set:

>>> not gtool.getGroupById('AuthenticatedUsers').getProperty('title')
True

The prefs_groups_overview template uses the following method to get the group title:

>>> search_results = self.portal.acl_users.searchGroups(id=group_name)
>>> search_results[0]['title'] == group_title
True

To change the title of an automatic group we should not call group.setProperty, it will not work. The correct way is change the description property of the correspondent PAS plugin (yes, it’s the description property, not title). Fortunately this package provides a function that makes this job easier:

>>> from collective.autogroup.utils import (set_auto_group_title,
...     get_auto_group_title)
>>> new_title = group_title + '_new'
>>> set_auto_group_title(self.acl_users, group_name, new_title)
>>> search_results = self.portal.acl_users.searchGroups(id=group_name)
>>> search_results[0]['title'] == new_title
True
>>> get_auto_group_title(self.acl_users, group_name) == new_title
True

It can also be done through ZMI.

Credits

Changelog

0.1b1 - 15feb2010

  • First release.
Release History

Release History

0.1b1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1b1dev-r110975

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
collective.autogroup-0.1b1.zip (12.4 kB) Copy SHA256 Checksum SHA256 Source Feb 15, 2010

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting