diff --git a/docker/routlin-dash/app/config_utils.py b/docker/routlin-dash/app/config_utils.py index 6107d65..1604b42 100644 --- a/docker/routlin-dash/app/config_utils.py +++ b/docker/routlin-dash/app/config_utils.py @@ -404,6 +404,7 @@ def revert_snapshot_to_config(entry_uuid): before=after, after=before, description=f"Reverted: {snap.get('description', '')}", cmd=snap.get('cmd', 'core apply'), + reverts=entry_uuid, ) return msg or 'Reverted.', True @@ -421,7 +422,7 @@ def load_snapshot_for_uuid(entry_uuid): def save_config_with_snapshot(new_config, path, key, operation, before, after, - description='', cmd='core apply', queue=True): + description='', cmd='core apply', queue=True, reverts=None): """ Write a .snapshots/{ts}-{uuid}.json file, save new_config to disk, and optionally create a pending queue entry. Returns a flash message string. @@ -448,6 +449,7 @@ def save_config_with_snapshot(new_config, path, key, operation, before, after, 'before': before, 'after': after, 'depends_on': depends_on, + 'reverts': reverts, } with open(os.path.join(SNAPSHOTS_DIR, f'{entry_ts}-{entry_uuid}.json'), 'w') as f: json.dump(snapshot, f, indent=2) diff --git a/docker/routlin-dash/app/view_page.py b/docker/routlin-dash/app/view_page.py index c65a6bd..4f1bc2c 100644 --- a/docker/routlin-dash/app/view_page.py +++ b/docker/routlin-dash/app/view_page.py @@ -632,6 +632,14 @@ def collect_tokens(): all_snaps = load_all_snapshots() done_ts_map = get_done_timestamps() if all_snaps: + # UUIDs that cannot be reverted: revert entries themselves, and entries + # that have already been reverted (referenced in another snap's 'reverts'). + _no_revert = set() + for _s in all_snaps: + if _s.get('operation') == 'revert': + _no_revert.add(_s.get('uuid', '')) + if _s.get('reverts'): + _no_revert.add(_s['reverts']) hist_rows = '' _hist_onclick = ( 'onclick="if(event.target.type!==\'checkbox\')' @@ -650,8 +658,9 @@ def collect_tokens(): f'{e(_uuid[:8])}' f'') snap_user = e(snap.get('user', '')) + _cb_attrs = 'disabled title="Cannot revert"' if _uuid in _no_revert else '' hist_rows += (f'