Skip to content

Commit

Permalink
networkmanager: use usePolkitPermissions hook as an alternative for p…
Browse files Browse the repository at this point in the history
…ermissions
  • Loading branch information
chriswiggins committed Apr 10, 2024
1 parent 977072a commit 83d7421
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/networkmanager/networkmanager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { PlotState } from 'plot';

import { useObject, useEvent, usePageLocation } from "hooks";
import { WithDialogs } from "dialogs.jsx";
import { usePolkitPermissions } from '../lib/hooks.js';

const _ = cockpit.gettext;

Expand All @@ -56,6 +57,17 @@ const App = () => {
const { path } = usePageLocation();

useEvent(superuser, "changed");
const polkitPermissions = usePolkitPermissions([
'org.freedesktop.NetworkManager.reload',
'org.freedesktop.NetworkManager.checkpoint-rollback',
'org.freedesktop.NetworkManager.network-control',
'org.freedesktop.NetworkManager.settings.modify.global-dns',
'org.freedesktop.NetworkManager.settings.modify.hostname',
'org.freedesktop.NetworkManager.settings.modify.own',
'org.freedesktop.NetworkManager.settings.modify.system'
]);

const polkitAllowed = polkitPermissions.every((permission) => permission);

const usage_monitor = useObject(() => new UsageMonitor(), null, []);
const plot_state_main = useObject(() => new PlotState(), null, []);
Expand Down Expand Up @@ -117,7 +129,7 @@ const App = () => {
return (
<ModelContext.Provider value={model}>
<WithDialogs key="1">
<NetworkPage privileged={superuser.allowed}
<NetworkPage privileged={superuser.allowed || polkitAllowed}
operationInProgress={model.operationInProgress}
usage_monitor={usage_monitor}
plot_state={plot_state_main}
Expand All @@ -132,7 +144,7 @@ const App = () => {
return (
<ModelContext.Provider value={model}>
<WithDialogs key="2">
<NetworkInterfacePage privileged={superuser.allowed}
<NetworkInterfacePage privileged={superuser.allowed || polkitAllowed}
operationInProgress={model.operationInProgress}
usage_monitor={usage_monitor}
plot_state={plot_state_iface}
Expand Down

0 comments on commit 83d7421

Please sign in to comment.