@Node.subscribe('before_save')
def validate_permissions(schema, instance):
 node = instance
 contributor_ids = set([user._id for user in node.contributors])
 permission_ids = set(node.permissions.keys())
 mismatched_contributors = contributor_ids.difference(permission_ids)
 if mismatched_contributors:
  raise ValidationValueError('Contributors {0} missing from `permissions` on node {1}'.format(', '.join(mismatched_contributors), node._id))
 mismatched_permissions = permission_ids.difference(contributor_ids)
 if mismatched_permissions:
  raise ValidationValueError('Permission keys {0} missing from `contributors` on node {1}'.format(', '.join(mismatched_contributors), node._id))

@ Node . subscribe ( 'before_save' ) def validate_permissions ( schema , instance ) : node = instance contributor_ids = set ( [ user . _id for user in node . contributors ] ) permission_ids = set ( node . permissions . keys ( ) ) mismatched_contributors = contributor_ids . difference ( permission_ids ) if mismatched_contributors : raise ValidationValueError ( 'Contributors {0} missing from `permissions` on node {1}' . format ( ', ' . join ( mismatched_contributors ) , node . _id ) ) mismatched_permissions = permission_ids . difference ( contributor_ids ) if mismatched_permissions : raise ValidationValueError ( 'Permission keys {0} missing from `contributors` on node {1}' . format ( ', ' . join ( mismatched_contributors ) , node . _id ) )
ensure that user ids in contributors and permissions match .