| 1 |
/* |
| 2 |
* Copyright (C) 2020 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
import cockpit from 'cockpit'; |
| 7 |
import React from 'react'; |
| 8 |
import { Checkbox } from "@patternfly/react-core/dist/esm/components/Checkbox/index.js"; |
| 9 |
|
| 10 |
import { show_modal_dialog } from "cockpit-components-dialog.jsx"; |
| 11 |
|
| 12 |
const _ = cockpit.gettext; |
| 13 |
|
| 14 |
function DeleteAccountDialogBody({ state, change }) { |
| 15 |
const { delete_files } = state; |
| 16 |
|
| 17 |
return ( |
| 18 |
<Checkbox id="account-confirm-delete-files" |
| 19 |
label={_("Delete files")} |
| 20 |
isChecked={delete_files} onChange={(_event, checked) => change("delete_files", checked)} /> |
| 21 |
); |
| 22 |
} |
| 23 |
|
| 24 |
export function delete_account_dialog(account) { |
| 25 |
let dlg = null; |
| 26 |
|
| 27 |
const state = { |
| 28 |
delete_files: false |
| 29 |
}; |
| 30 |
|
| 31 |
function change(field, value) { |
| 32 |
state[field] = value; |
| 33 |
update(); |
| 34 |
} |
| 35 |
|
| 36 |
function update() { |
| 37 |
const props = { |
| 38 |
id: "account-confirm-delete-dialog", |
| 39 |
title: cockpit.format(_("Delete $0"), account.name), |
| 40 |
body: <DeleteAccountDialogBody state={state} change={change} /> |
| 41 |
}; |
| 42 |
|
| 43 |
const footer = { |
| 44 |
actions: [ |
| 45 |
{ |
| 46 |
caption: _("Delete"), |
| 47 |
style: "danger", |
| 48 |
clicked: () => { |
| 49 |
const prog = ["/usr/sbin/userdel"]; |
| 50 |
if (state.delete_files) |
| 51 |
prog.push("-r"); |
| 52 |
prog.push(account.name); |
| 53 |
|
| 54 |
return cockpit.spawn(prog, { superuser: "require", err: "message" }) |
| 55 |
.then(function () { |
| 56 |
cockpit.location.go("/"); |
| 57 |
}); |
| 58 |
} |
| 59 |
} |
| 60 |
] |
| 61 |
}; |
| 62 |
|
| 63 |
if (!dlg) |
| 64 |
dlg = show_modal_dialog(props, footer); |
| 65 |
else { |
| 66 |
dlg.setProps(props); |
| 67 |
dlg.setFooterProps(footer); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
update(); |
| 72 |
} |