From dbab17cf3653419b16367ef2a1b28fc498a58be7 Mon Sep 17 00:00:00 2001 From: Chris Wiggins Date: Wed, 10 Apr 2024 20:08:43 +0000 Subject: [PATCH] networkmanager: use usePolkitPermissions hook --- pkg/networkmanager/networkmanager.jsx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/networkmanager/networkmanager.jsx b/pkg/networkmanager/networkmanager.jsx index ef4f3c4651f8..8e4f68c8d2a9 100644 --- a/pkg/networkmanager/networkmanager.jsx +++ b/pkg/networkmanager/networkmanager.jsx @@ -33,11 +33,11 @@ import { UsageMonitor } from './helpers.js'; import * as service from 'service.js'; import { init as initDialogs, NetworkManagerModel } from './interfaces.js'; -import { superuser } from 'superuser'; import { PlotState } from 'plot'; import { useObject, useEvent, usePageLocation } from "hooks"; import { WithDialogs } from "dialogs.jsx"; +import { usePolkitPermissions } from '../lib/hooks.js'; const _ = cockpit.gettext; @@ -55,7 +55,19 @@ const App = () => { const { path } = usePageLocation(); - useEvent(superuser, "changed"); + // This uses polkit but falls back to superuser.allowed + 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' + ]); + + // For now we require all of the permissions to be true + const privileged = Object.values(polkitPermissions).every(Boolean); const usage_monitor = useObject(() => new UsageMonitor(), null, []); const plot_state_main = useObject(() => new PlotState(), null, []); @@ -117,7 +129,7 @@ const App = () => { return ( - { return ( -