'Undelete histories'

def _list_undelete(self, trans, histories):

    n_undeleted = 0
    n_already_purged = 0
    for history in histories:
        if history.purged:
            n_already_purged += 1
        if history.deleted:
            history.deleted = False
            if (not history.default_permissions):
                default_action = trans.app.security_agent.permitted_actions.DATASET_MANAGE_PERMISSIONS
                private_user_role = trans.app.security_agent.get_private_user_role(history.user)
                default_permissions = {}
                default_permissions[default_action] = [private_user_role]
                trans.app.security_agent.history_set_default_permissions(history, default_permissions)
            n_undeleted += 1
            trans.log_event(('History    (%s)    %d    marked    as    undeleted' % (history.name, history.id)))
    status = SUCCESS
    message_parts = []
    if n_undeleted:
        message_parts.append(('Undeleted    %d    %s.        ' % (n_undeleted, iff((n_undeleted != 1), 'histories', 'history'))))
    if n_already_purged:
        message_parts.append(('%d    histories    have    already    been    purged    and    cannot    be    undeleted.' % n_already_purged))
        status = WARNING
    return (status, ''.join(message_parts))
