Skip to content

Commit

Permalink
Don't show the system session option on limited access
Browse files Browse the repository at this point in the history
A limited access user cannot create a system session virtual machine so
this would just throw an error after creation.
  • Loading branch information
jelly committed Dec 3, 2024
1 parent 5cc6c32 commit 3a96bad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const App = () => {
const [loadingResources, setLoadingResources] = useState(true);
const [error, setError] = useState('');
const [systemSocketInactive, setSystemSocketInactive] = useState(false);
const [systemSocketAvailable, setSystemSocketAvailable] = useState(false);
const [virtualizationEnabled, setVirtualizationEnabled] = useState(true);
const [emptyStateIgnored, setEmptyStateIgnored] = useState(() => {
const ignored = localStorage.getItem('virtualization-disabled-ignored');
Expand All @@ -89,6 +90,8 @@ export const App = () => {
.filter(promise => promise.status === 'rejected')
.map(promise => promise.reason.message);
setError(errorMsgs.join(', '));
if (connectionName == "system")
setSystemSocketAvailable(true);
} catch (ex) {
// access denied is expected for unprivileged session
if (connectionName !== 'system' || superuser.allowed || ex.name !== 'org.freedesktop.DBus.Error.AccessDenied')
Expand Down Expand Up @@ -150,7 +153,7 @@ export const App = () => {
</Page>
);
} else return (
<AppActive error={error} />
<AppActive error={error} systemSocketAvailable={systemSocketAvailable} />
);
};

Expand Down Expand Up @@ -260,6 +263,7 @@ class AppActive extends React.Component {
unattendedSupported,
unattendedUserLogin,
virtInstallAvailable,
systemSocketAvailable: this.props.systemSocketAvailable,
};
const createVmAction = <CreateVmAction {...properties} mode='create' />;
const importDiskAction = <CreateVmAction {...properties} mode='import' />;
Expand Down
9 changes: 6 additions & 3 deletions src/components/create-vm-dialog/createVmDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ class CreateVmModal extends React.Component {
validate: false,
vmName: '',
suggestedVmName: '',
connectionName: LIBVIRT_SYSTEM_CONNECTION,
connectionName: this.props.systemSocketAvailable ? LIBVIRT_SYSTEM_CONNECTION : LIBVIRT_SESSION_CONNECTION,
sourceType: defaultSourceType,
source: '',
os: undefined,
Expand Down Expand Up @@ -1331,12 +1331,13 @@ class CreateVmModal extends React.Component {

const detailsTab = (
<>
{this.props.systemSocketAvailable &&
<MachinesConnectionSelector
id='connection'
connectionName={this.state.connectionName}
onValueChanged={this.onValueChanged}
loggedUser={loggedUser}
showInfoHelper />
showInfoHelper />}
<SourceRow
connectionName={this.state.connectionName}
networks={networks.filter(network => network.connectionName == this.state.connectionName)}
Expand Down Expand Up @@ -1513,7 +1514,9 @@ export class CreateVmAction extends React.Component {
downloadOSSupported={this.props.downloadOSSupported}
unattendedSupported={this.props.unattendedSupported}
unattendedUserLogin={this.props.unattendedUserLogin}
loggedUser={this.props.systemInfo.loggedUser} />);
loggedUser={this.props.systemInfo.loggedUser}
systemsocketAvailable={this.props.systemSocketAvailable}
/>);
};

let testdata;
Expand Down
12 changes: 10 additions & 2 deletions test/check-machines-lifecycle
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,16 @@ class TestMachinesLifecycle(machineslib.VirtualMachinesCase):
b.wait_in_text(".pf-v5-c-popover__body", message)
m.execute("virt-xml subVmTest1 --remove-device --watchdog 1 --update")

checkConnectionDescription("#import-existing-vm", "Ideal for server VMs")
checkConnectionDescription("#create-new-vm", "Good choice for desktop virtualization")
if superuser:
checkConnectionDescription("#import-existing-vm", "Ideal for server VMs")
checkConnectionDescription("#create-new-vm", "Good choice for desktop virtualization")
else:
b.click("#create-new-vm")
b.wait_visible("#create-vm-dialog")
b.wait_not_present("#connection")
b.click('#create-vm-dialog button:contains("Cancel")')
b.wait_not_present("#create-vm-dialog")

checkNeedsShutdownLabel("Watchdog")

b.wait_in_text("#vm-subVmTest1-system-state", "Running")
Expand Down

0 comments on commit 3a96bad

Please sign in to comment.