Development

This commit is contained in:
Matthew Grotke 2026-05-25 22:44:37 -04:00
parent cd667c5009
commit 3ee1a6f0de
3 changed files with 24 additions and 7 deletions

View file

@ -1,7 +1,7 @@
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_core,
revert_snapshot_to_config, queued_msg,
_is_locked, _format_timing, _seconds_until_next_run)
bp = Blueprint('action_actions', __name__)
@ -36,6 +36,13 @@ def actions_cardpending_applynow():
return redirect(_VIEW)
@bp.route('/action/queue_core_apply', methods=['POST'])
@require_level('administrator')
def queue_core_apply():
flash(queued_msg('core apply', action_label='Apply queued'), 'success')
return redirect(_VIEW)
@bp.route('/action/actions_cardhistory_revertselected', methods=['POST'])
@require_level('administrator')
def actions_cardhistory_revertselected():
@ -45,7 +52,7 @@ def actions_cardhistory_revertselected():
return redirect(_VIEW)
succeeded, failed = 0, 0
for uuid in selected_uuids:
msg, ok = revert_snapshot_to_core(uuid)
msg, ok = revert_snapshot_to_config(uuid)
if ok:
succeeded += 1
else:

View file

@ -328,7 +328,7 @@ def _items_match(item, ref):
return item == ref
def revert_snapshot_to_core(entry_uuid):
def revert_snapshot_to_config(entry_uuid):
"""Apply the inverse of a snapshot to config.json and queue a new pending change.
Returns (flash_message, success_bool).
@ -388,10 +388,10 @@ def load_snapshot_for_uuid(entry_uuid):
return None
def save_config_with_snapshot(new_core, path, key, operation, before, after,
def save_config_with_snapshot(new_config, path, key, operation, before, after,
description='', cmd='core apply', queue=True):
"""
Write a .snapshots/{ts}-{uuid}.json file, save new_core to disk, and
Write a .snapshots/{ts}-{uuid}.json file, save new_config to disk, and
optionally create a pending queue entry. Returns a flash message string.
queue=False: skips queueing and records the change directly in
@ -420,7 +420,7 @@ def save_config_with_snapshot(new_core, path, key, operation, before, after,
with open(os.path.join(SNAPSHOTS_DIR, f'{entry_ts}-{entry_uuid}.json'), 'w') as f:
json.dump(snapshot, f, indent=2)
save_config(new_core)
save_config(new_config)
if not queue:
with open(DASHBOARD_DONE, 'a') as f:

View file

@ -1700,7 +1700,17 @@ def render_layout(view_id, content_html, tokens):
+ '</ul>')
fix_html = ''
if fix_cmds:
fix_items = ''.join(f'<li>Run `{e(c)}`</li>' for c in fix_cmds)
_queue_urls = {
'sudo python3 core.py --apply': '/action/queue_core_apply',
}
def _fix_item(c):
url = _queue_urls.get(c)
if url:
btn = (f'<form class="form-inline" method="post" action="{e(url)}">'
f'<button type="submit" class="btn-link">Click here</button></form>')
return f'<li>{btn} or manually run <code>{e(c)}</code></li>'
return f'<li>Run <code>{e(c)}</code></li>'
fix_items = ''.join(_fix_item(c) for c in fix_cmds)
fix_html = ('<div style="margin-top:0.5em"><strong>To fix:</strong></div>'
f'<ul style="margin:0.25em 0;padding-left:1.25em">{fix_items}</ul>')
content = ('<div style="width:100%">'