def error(self, obj, error):
     request = getattr(self.context, 'REQUEST', None)
     if request is not None:
         groupid = self.element.groupid
         message = _(u'Unable to remove user group with id '
                     u'${groupid}: ${error}',
                     mapping={'groupid': groupid, 'error': error})
         IStatusMessage(request).addStatusMessage(message, type='error')
    def __call__(self):
        obj = self.event.object
        gt = getToolByName(self.context, 'portal_groups', None)
        interpolator = IStringInterpolator(obj)
        if gt is None:
            return False

        groupid = self.element.groupid
        # User interpolator to process principal information
        # This way it's possible to set Group_${title}
        # and receive a Group_ContentTitle
        groupid = interpolator(groupid).strip()
        if not gt.getGroupById(groupid):
            self.error(obj,
                       _(u'There is no user group with id ${groupid}',
                         mapping=dict(groupid=groupid)))
            return False

        try:
            gt.removeGroup(groupid)
        except ConflictError, e:
            raise e
    def __call__(self):
        obj = self.event.object
        gt = getToolByName(self.context, 'portal_groups', None)
        interpolator = IStringInterpolator(obj)
        if gt is None:
            return False

        roles = list(self.element.roles)
        groupid = self.element.groupid
        # User interpolator to process principal information
        # This way it's possible to set Group_${title}
        # and receive a Group_ContentTitle
        groupid = interpolator(groupid).strip()
        if gt.getGroupById(groupid):
            self.error(obj,
                       _(u'An user group with the same id already exists.'))
            return False
        grouptitle = self.element.grouptitle
        grouptitle = interpolator(grouptitle).strip()

        try:
            gt.addGroup(groupid, title=grouptitle, roles=roles)
        except ConflictError, e:
            raise e
 def summary(self):
     return _(u'Remove an user group with id ${groupid}',
              mapping=dict(groupid=self.groupid))
 def summary(self):
     roles = ', '.join(self.roles)
     return _(u'Create an user group ${groupid} with roles ${roles}',
              mapping=dict(roles=roles, groupid=self.groupid))