50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
from pathlib import Path
|
|
from flask import Blueprint, request, redirect, flash, session
|
|
from auth import require_level
|
|
from config_utils import (flush_pending_to_queue, get_dashboard_pending,
|
|
revert_snapshot_to_config, queued_msg)
|
|
|
|
_PAGE = Path(__file__).parent.name
|
|
|
|
bp = Blueprint(_PAGE, __name__)
|
|
|
|
@bp.route('/action/actions/pending_save', methods=['POST'])
|
|
@require_level('administrator')
|
|
def pending_save():
|
|
session['apply_changes_immediately'] = 'apply_changes_immediately' in request.form
|
|
flash('Preference saved.', 'success')
|
|
return redirect(f'/{_PAGE}')
|
|
|
|
|
|
@bp.route('/action/actions/pending_apply', methods=['POST'])
|
|
@require_level('administrator')
|
|
def pending_apply():
|
|
pending = get_dashboard_pending()
|
|
if not pending:
|
|
flash('No pending changes to apply.', 'info')
|
|
return redirect(f'/{_PAGE}')
|
|
flush_pending_to_queue()
|
|
if any(cmd != 'fix problems' for _, _, cmd, _ in pending):
|
|
flash('Changes queued.', 'success')
|
|
return redirect(f'/{_PAGE}')
|
|
|
|
|
|
@bp.route('/action/actions/history_revert', methods=['POST'])
|
|
@require_level('administrator')
|
|
def history_revert():
|
|
selected_uuids = request.form.getlist('selected_uuids')
|
|
if not selected_uuids:
|
|
flash('No items selected.', 'info')
|
|
return redirect(f'/{_PAGE}')
|
|
succeeded, failed = 0, 0
|
|
for uuid in selected_uuids:
|
|
msg, ok = revert_snapshot_to_config(uuid)
|
|
if ok:
|
|
succeeded += 1
|
|
else:
|
|
flash(msg, 'error')
|
|
failed += 1
|
|
if succeeded:
|
|
plural = 's' if succeeded != 1 else ''
|
|
flash(f'{succeeded} change{plural} reverted.', 'success')
|
|
return redirect(f'/{_PAGE}')
|