## Script (Python) "prefs_group_modify"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=Modify groups
##
REQUEST=context.REQUEST
groupstool=context.portal_groups
portal_status_message = 'No changes done.'

groups=[group[len('group_'):]
        for group in REQUEST.keys()
        if group.startswith('group_')]

for group in groups:
    roles=[r for r in REQUEST['group_' + group] if r]
    groupstool.editGroup(group, roles=roles, groups=())
    portal_status_message = 'Changes saved.'

delete=REQUEST.get('delete',[])

if delete:
    groupstool.removeGroups(delete)
    portal_status_message=context.translate('Group(s) deleted.')

return state.set(portal_status_message=portal_status_message)
