'Returns a dict of { action : [ role, role, ... ] } for the output dataset based upon provided datasets'

def guess_derived_permissions_for_datasets(self, datasets=[]):

    perms = {}
    for dataset in datasets:
        if (not isinstance(dataset, self.model.Dataset)):
            dataset = dataset.dataset
        these_perms = {}
        for action in self.get_actions():
            these_perms[action] = []
        these_perms = self.get_permissions(dataset)
        for (action, roles) in these_perms.items():
            if (action not in perms.keys()):
                perms[action] = roles
            elif (action.model == 'grant'):
                perms[action] = [_ for _ in roles if (_ in perms[action])]
            elif (action.model == 'restrict'):
                perms[action].extend([_ for _ in roles if (_ not in perms[action])])
    return perms
