Skip to content

Commit

Permalink
Merge pull request #1893 from Inist-CNRS/feat/dataset-deletion
Browse files Browse the repository at this point in the history
Add the possibility to delete the database
  • Loading branch information
parmentf authored Feb 13, 2024
2 parents 72fe059 + 7a8a549 commit ec692ee
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/api/controller/rootAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const putTenant = async (ctx, id) => {
};

const deleteTenant = async ctx => {
const { _id, name } = ctx.request.body;
const { _id, name, deleteDatabase } = ctx.request.body;
const tenantExists = await ctx.tenantCollection.findOne({
_id: new ObjectId(_id),
name,
Expand All @@ -131,8 +131,12 @@ const deleteTenant = async ctx => {
ctx.status = 403;
ctx.body = { error: `Invalid name: "${name}"` };
} else {
deleteWorkerQueue(tenantExists.name);
deleteWorkerQueue(tenantExists.name).then();
bullBoard.removeDashboardQueue(tenantExists.name);
if (deleteDatabase) {
const db = await mongoClient(name);
await db.dropDatabase();
}
await ctx.tenantCollection.deleteOne(tenantExists);
ctx.body = await getTenants(ctx);
}
Expand Down
20 changes: 19 additions & 1 deletion src/app/js/root-admin/DeleteTenantDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import {
DialogActions,
DialogTitle,
Button,
FormControlLabel,
Checkbox,
} from '@mui/material';

const DeleteTenantDialog = ({ tenant, handleClose, deleteAction }) => {
const [name, setName] = useState('');
const [deleteDatabase, setDeleteDatabase] = useState(true);

return (
<Dialog
Expand All @@ -34,14 +37,29 @@ const DeleteTenantDialog = ({ tenant, handleClose, deleteAction }) => {
error={name !== tenant.name}
value={name}
/>
<FormControlLabel
control={
<Checkbox
defaultChecked
value={deleteDatabase}
onChange={() => {
setDeleteDatabase(!deleteDatabase);
}}
color="error"
/>
}
label="Supprimer la base de données correspondante"
labelPlacement="end"
/>
</DialogContent>
<DialogActions>
<Button
variant="contained"
color="error"
onClick={() => {
deleteAction(tenant._id, tenant.name);
deleteAction(tenant._id, tenant.name, deleteDatabase);
setName('');
setDeleteDatabase(true);
}}
disabled={name !== tenant.name}
sx={{ height: '100%' }}
Expand Down
4 changes: 2 additions & 2 deletions src/app/js/root-admin/Tenants.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ const Tenants = ({ handleLogout }) => {
});
};

const deleteTenant = (_id, name) => {
const deleteTenant = (_id, name, deleteDatabase) => {
fetch('/rootAdmin/tenant', {
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'X-Lodex-Tenant': 'admin',
},
method: 'DELETE',
body: JSON.stringify({ _id, name }),
body: JSON.stringify({ _id, name, deleteDatabase }),
})
.then(response => {
if (response.status === 401) {
Expand Down

0 comments on commit ec692ee

Please sign in to comment.