def massage_permissions(document):
 read_perms = document.list_permissions(perm='read')
 write_perms = document.list_permissions(perm='write')
 return {'perms': {'read': {'users': [{'id': perm_user.id, 'username': perm_user.username} for perm_user in read_perms.users.all()], 'groups': [{'id': perm_group.id, 'name': perm_group.name} for perm_group in read_perms.groups.all()]}, 'write': {'users': [{'id': perm_user.id, 'username': perm_user.username} for perm_user in write_perms.users.all()], 'groups': [{'id': perm_group.id, 'name': perm_group.name} for perm_group in write_perms.groups.all()]}}}

def massage_permissions ( document ) : read_perms = document . list_permissions ( perm = 'read' ) write_perms = document . list_permissions ( perm = 'write' ) return { 'perms' : { 'read' : { 'users' : [ { 'id' : perm_user . id , 'username' : perm_user . username } for perm_user in read_perms . users . all ( ) ] , 'groups' : [ { 'id' : perm_group . id , 'name' : perm_group . name } for perm_group in read_perms . groups . all ( ) ] } , 'write' : { 'users' : [ { 'id' : perm_user . id , 'username' : perm_user . username } for perm_user in write_perms . users . all ( ) ] , 'groups' : [ { 'id' : perm_group . id , 'name' : perm_group . name } for perm_group in write_perms . groups . all ( ) ] } } }
returns the permissions for a given document as a dictionary .