'This should be the equivalent of allow_action defined on multiple items.
It is meant to specifically replace allow_action for multiple
LibraryDatasets, but it could be reproduced or modified for
allow_action\'s permitted classes - Dataset, Library, LibraryFolder, and
LDDAs.'

def allow_action_on_libitems(self, trans, user_roles, action, items):

    all_items_actions = self.get_actions_for_items(trans, action, items)
    ret_allow_action = {}
    for item in items:
        if (item.id in all_items_actions):
            item_actions = all_items_actions[item.id]
            if (self.permitted_actions.DATASET_ACCESS == action):
                ret_allow_action[item.id] = True
                for item_action in item_actions:
                    if (item_action.role not in user_roles):
                        ret_allow_action[item.id] = False
                        break
            else:
                ret_allow_action[item.id] = False
                for item_action in item_actions:
                    if (item_action.role in user_roles):
                        ret_allow_action[item.id] = True
                        break
        elif ('restrict' == action.model):
            ret_allow_action[item.id] = True
        else:
            ret_allow_action[item.id] = False
    test_code = False
    if test_code:
        log.debug('allow_action_for_items:    test    start')
        for item in items:
            orig_value = self.allow_action(user_roles, action, item)
            if (orig_value == ret_allow_action[item.id]):
                log.debug(('Item    %d:    success' % item.id))
            else:
                log.debug(('Item    %d:    fail:    original:    %s;    new:    %s' % (item.id, orig_value, ret_allow_action[item.id])))
        log.debug('allow_action_for_items:    test    end')
    return ret_allow_action
