Development

This commit is contained in:
Matthew Grotke 2026-05-27 22:04:04 -04:00
parent eed1d295dc
commit d9f3bd8289
45 changed files with 635 additions and 666 deletions

View file

@ -1,41 +1,41 @@
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)
bp = Blueprint('actions', __name__)
_PAGE = Path(__file__).parent.name
_VIEW = '/view/view_actions'
bp = Blueprint(_PAGE, __name__)
@bp.route('/action/actions_cardpending_save', methods=['POST'])
@bp.route('/action/actions/pending_save', methods=['POST'])
@require_level('administrator')
def actions_cardpending_save():
def pending_save():
session['apply_changes_immediately'] = 'apply_changes_immediately' in request.form
flash('Preference saved.', 'success')
return redirect(_VIEW)
return redirect(f'/{_PAGE}')
@bp.route('/action/actions_cardpending_applynow', methods=['POST'])
@bp.route('/action/actions/pending_apply', methods=['POST'])
@require_level('administrator')
def actions_cardpending_applynow():
def pending_apply():
pending = get_dashboard_pending()
if not pending:
flash('No pending changes to apply.', 'info')
return redirect(_VIEW)
return redirect(f'/{_PAGE}')
flush_pending_to_queue()
if any(cmd != 'fix problems' for _, _, cmd, _ in pending):
flash('Changes queued.', 'success')
return redirect(_VIEW)
return redirect(f'/{_PAGE}')
@bp.route('/action/actions_cardhistory_revertselected', methods=['POST'])
@bp.route('/action/actions/history_revert', methods=['POST'])
@require_level('administrator')
def actions_cardhistory_revertselected():
def history_revert():
selected_uuids = request.form.getlist('selected_uuids')
if not selected_uuids:
flash('No items selected.', 'info')
return redirect(_VIEW)
return redirect(f'/{_PAGE}')
succeeded, failed = 0, 0
for uuid in selected_uuids:
msg, ok = revert_snapshot_to_config(uuid)
@ -47,4 +47,4 @@ def actions_cardhistory_revertselected():
if succeeded:
plural = 's' if succeeded != 1 else ''
flash(f'{succeeded} change{plural} reverted.', 'success')
return redirect(_VIEW)
return redirect(f'/{_PAGE}')

View file

@ -1,5 +1,4 @@
{
"id": "view_actions",
"client_requirement": "client_is_viewer+",
"items": [
{
@ -22,7 +21,7 @@
"items": [
{
"type": "form",
"action": "/action/actions_cardpending_applynow",
"action": "/action/actions/pending_apply",
"method": "post",
"items": [
{
@ -50,7 +49,7 @@
},
{
"type": "form",
"action": "/action/actions_cardpending_save",
"action": "/action/actions/pending_save",
"method": "post",
"items": [
{
@ -66,7 +65,7 @@
"items": [
{
"type": "button_primary",
"action": "/action/actions_cardpending_save",
"action": "/action/actions/pending_save",
"method": "post",
"text": "Save"
},
@ -87,7 +86,7 @@
"items": [
{
"type": "form",
"action": "/action/actions_cardhistory_revertselected",
"action": "/action/actions/history_revert",
"method": "post",
"items": [
{