Skip to content

Commit

Permalink
networkmanager: Handle cancelling of superuser changes
Browse files Browse the repository at this point in the history
Opening the superuser dialog (necessarily) already initiates the sudo
(or similar) process, changes `superuser.allowed` to `null`, and thus
triggers all kinds of reinitialization. However, `model` becomes invalid
(`model.ready == false`) after cancelling the dialog, so that the page
is stuck in the empty state.

Fix that by reinitializing the model after superuser changes.

Fixes the first part of cockpit-project#19655 (this applies to more pages)
  • Loading branch information
martinpitt committed Jan 17, 2025
1 parent 36c4411 commit e90ffe6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/networkmanager/networkmanager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const App = () => {
[]);
useEvent(nmService, "changed");

const model = useObject(() => new NetworkManagerModel(), null, []);
const model = useObject(() => new NetworkManagerModel(), null, [superuser.allowed]);
useEvent(model, "changed");

const nmRunning_ref = useRef(undefined);
Expand Down
11 changes: 11 additions & 0 deletions test/verify/check-networkmanager-basic
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,17 @@ class TestNetworkingBasic(netlib.NetworkCase):
m.execute(f"nmcli connection up '{con_id}'")
self.wait_onoff(f".pf-v5-c-card__header:contains('{iface}')", val=True)

# cancelling superuser dialog goes back to unpriv state
b.switch_to_top()
b.open_superuser_dialog()
b.click("div[role=dialog] button[aria-label=Close]")
b.wait_not_present("div[role=dialog]")

b.enter_page("/network")
b.wait_visible("#network-interface")
# On/Off button is disabled, but shows the correct value
b.wait_visible(f".pf-v5-c-card__header:contains('{iface}') .pf-v5-c-switch input:disabled")

# UI becomes editable when gaining privileges
b.become_superuser()
b.wait_visible('#autoreconnect:not(disabled)')
Expand Down

0 comments on commit e90ffe6

Please sign in to comment.