'Set a specific permission on a dataset, leaving all other current permissions on the dataset alone.
Permission looks like: { Action.action : [ Role, Role ] }'

def set_dataset_permission(self, dataset, permission={}):

    flush_needed = False
    for (action, roles) in permission.items():
        if isinstance(action, Action):
            action = action.action
        for dp in dataset.actions:
            if (dp.action == action):
                self.sa_session.delete(dp)
                flush_needed = True
        for dp in [self.model.DatasetPermissions(action, dataset, role) for role in roles]:
            self.sa_session.add(dp)
            flush_needed = True
    if flush_needed:
        self.sa_session.flush()
