User Manager: undo/redo user add and delete on a device
Uses LiveComponentCommand, so undoing a delete puts the user back on the device with its exact cred, perm and prov. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@ so later rebinding would only ever be seen by the module that did it.
|
||||
import configparser
|
||||
import os
|
||||
|
||||
VERSION = "0.0.0.150"
|
||||
VERSION = "0.0.0.151"
|
||||
PROPERTIES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "editor.properties")
|
||||
DEFAULT_GRID_SIZE = 10
|
||||
DEFAULT_ADD_TIMESTAMP = True
|
||||
|
||||
+16
-1
@@ -449,7 +449,10 @@ class _UserDialog:
|
||||
ET.SubElement(elem, "prop", name=name, val=val)
|
||||
|
||||
if app_state.live_mode:
|
||||
index = len(list(self._service_comp))
|
||||
self._service_comp.append(elem)
|
||||
undo.push(sax_file.LiveComponentCommand(
|
||||
self._service_comp, index, elem, present=True, label="add user"))
|
||||
app_state.mark_dirty()
|
||||
app_state.set_status(f"User '{username}' added to device.")
|
||||
return
|
||||
@@ -643,12 +646,24 @@ class UserServicePanel:
|
||||
return
|
||||
|
||||
if app_state.live_mode:
|
||||
# Read before it goes: once deleted, the device has nothing left to read back.
|
||||
snapshot = live_hooks.read_subtree(user_elem)
|
||||
unreadable = live_hooks.last_error if snapshot is None else ""
|
||||
if not live_hooks.live_delete_component(user_elem):
|
||||
live_hooks.warn_failure("Delete User", f"User '{name}' was not deleted from the device")
|
||||
return
|
||||
index = list(self.comp).index(user_elem)
|
||||
self.comp.remove(user_elem)
|
||||
app_state.mark_dirty()
|
||||
app_state.set_status(f"User '{name}' deleted from device.")
|
||||
if snapshot is not None:
|
||||
undo.push(sax_file.LiveComponentCommand(
|
||||
self.comp, index, user_elem, present=False, snapshot=snapshot,
|
||||
label="delete user"))
|
||||
app_state.set_status(f"User '{name}' deleted from device.")
|
||||
else:
|
||||
app_state.set_status(
|
||||
f"User '{name}' was deleted from the device, but this delete cannot be "
|
||||
f"undone: {unreadable}", warn=True)
|
||||
self._after_change()
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user