@subscriber(ResourceChanged, for_resources=('group',), for_actions=(ACTIONS.CREATE, ACTIONS.UPDATE))
def on_groups_changed(event):
 permission_backend = event.request.registry.permission
 for change in event.impacted_records:
  if ('old' in change):
   existing_record_members = set(change['old'].get('members', []))
  else:
   existing_record_members = set()
  group = change['new']
  group_uri = '/buckets/{bucket_id}/groups/{id}'.format(id=group['id'], **event.payload)
  new_record_members = set(group.get('members', []))
  new_members = (new_record_members - existing_record_members)
  removed_members = (existing_record_members - new_record_members)
  for member in new_members:
   permission_backend.add_user_principal(member, group_uri)
  for member in removed_members:
   permission_backend.remove_user_principal(member, group_uri)

@ subscriber ( ResourceChanged , for_resources = ( 'group' , ) , for_actions = ( ACTIONS . CREATE , ACTIONS . UPDATE ) ) def on_groups_changed ( event ) : permission_backend = event . request . registry . permission for change in event . impacted_records : if ( 'old' in change ) : existing_record_members = set ( change [ 'old' ] . get ( 'members' , [ ] ) ) else : existing_record_members = set ( ) group = change [ 'new' ] group_uri = '/buckets/{bucket_id}/groups/{id}' . format ( id = group [ 'id' ] , ** event . payload ) new_record_members = set ( group . get ( 'members' , [ ] ) ) new_members = ( new_record_members - existing_record_members ) removed_members = ( existing_record_members - new_record_members ) for member in new_members : permission_backend . add_user_principal ( member , group_uri ) for member in removed_members : permission_backend . remove_user_principal ( member , group_uri )
some groups were changed .