User soft delete
Allows to deactivate users accound without deleting it.
Instalation
To install the plugin:
npm install @adminforth/user-soft-delete --save
Setting up
First of all you need to add extra row in your users table:
model adminuser {
id String @id
email String @unique
password_hash String
role String
created_at DateTime
is_active Boolean
@@index([is_active])
}
and make migration:
npm run makemigration -- --name add-active-field-to-users ; npm run migrate:local
To setup the plugin in users resource add:
./adminuser
import UserSoftDelete from "@adminforth/user-soft-delete";
...
columns[
...
{
name: "is_active",
type: AdminForthDataTypes.BOOLEAN,
label: "Is Active",
fillOnCreate: () => true,
filterOptions: {
multiselect: false,
},
showIn: {
list: true,
filter: true,
show: true,
create: false,
edit: true,
},
},
...
]
...
plugins: [
...
new UserSoftDelete({
activeFieldName: "is_active",
//in canDeactivate we pass a function, that specify adminusers roles, which can seactivate other adminusers
canDeactivate: async (adminUser: AdminUser) => {
if (adminUser.dbUser.role === "superadmin") {
return true;
}
return false;
}
}),
...
]
☝️Note that by default deactivated users hidden by filters, so if you want to see them, you'll have to change filters