'List all available histories'

@web.expose
@web.json
@web.require_login('work    with    multiple    histories')
def list(self, trans, **kwargs):

    current_history = trans.get_history()
    status = message = None
    if ('operation' in kwargs):
        operation = kwargs['operation'].lower()
        history_ids = galaxy.util.listify(kwargs.get('id', []))
        (status, message) = (None, None)
        histories = []
        for history_id in history_ids:
            history = self.history_manager.get_owned(self.decode_id(history_id), trans.user, current_history=trans.history)
            if history:
                if ((history.user_id is not None) and trans.user):
                    assert (trans.user.id == history.user_id), 'History    does    not    belong    to    current    user'
                histories.append(history)
            else:
                log.warning("Invalid    history    id    '%r'    passed    to    list", history_id)
        if histories:
            if (operation == 'switch'):
                (status, message) = self._list_switch(trans, histories)
                use_panels = (kwargs.get('use_panels', False) == 'True')
                if use_panels:
                    return trans.response.send_redirect(url_for('/'))
                else:
                    kwargs['refresh_frames'] = ['history']
            elif (operation in ('delete', 'delete    permanently')):
                if (operation == 'delete    permanently'):
                    (status, message) = self._list_delete(trans, histories, purge=True)
                else:
                    (status, message) = self._list_delete(trans, histories)
                if (current_history in histories):
                    kwargs['refresh_frames'] = ['history']
            elif (operation == 'undelete'):
                (status, message) = self._list_undelete(trans, histories)
            elif (operation == 'unshare'):
                for history in histories:
                    for husa in trans.sa_session.query(trans.app.model.HistoryUserShareAssociation).filter_by(history=history):
                        trans.sa_session.delete(husa)
            elif (operation == 'enable    import    via    link'):
                for history in histories:
                    if (not history.importable):
                        self._make_item_importable(trans.sa_session, history)
            elif (operation == 'disable    import    via    link'):
                if history_ids:
                    histories = []
                    for history_id in history_ids:
                        history = self.history_manager.get_owned(self.decode_id(history_id), trans.user, current_history=trans.history)
                        if history.importable:
                            history.importable = False
                        histories.append(history)
            trans.sa_session.flush()
    kwargs['dict_format'] = True
    return self.stored_list_grid(trans, status=status, message=message, **kwargs)
