Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7
Powerful Strapi based Soft Delete feature, never loose content again
License
ChristopheCVB/strapi-plugin-soft-delete
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A plugin forStrapi Headless CMS that provides a Soft Delete feature.
- 🛢 Database
- Adds
_softDeletedAt,_softDeletedByIdand_softDeletedByTypefields to all your collection and single content types. Those fields are not visible in the Content Manager nor through the API.
- Adds
- 🗂️ Content Manager & API
- The delete from the Content Manager & API behaves as a soft delete. It will set
_softDeletedAtto the current datetime,_softDeletedByIdto the action initiator id that deleted it and_softDeletedByTypeto the type of the delete action initiator.
- The delete from the Content Manager & API behaves as a soft delete. It will set
- 👤 RBAC
- The
Deleteis renamed toSoft Deleteand it is located in theSettings > Roles > Edit a Role > Collection Types | Single Typessection. - A new admin permission is added to the
Settings > Roles > Edit a Role > Collection Types | Single Typessection. This is theDeleted Readpermission. This will allow the admin role to view the soft deleted entries. - A new admin permission is added to the
Settings > Roles > Edit a Role > Collection Types | Single Typessection. This is theDeleted Restorepermission. This will allow the admin role to restore the soft deleted entries. - A new admin permission is added to the
Settings > Roles > Edit a Role > Collection Types | Single Typessection. This is theDelete Permanentlypermission. This will allow the admin role to delete permanently the soft deleted entries. - A new admin permission is added to the
Settings > Roles > Edit a Role > Plugins > Soft Deletesection. This is the globalReadpermission of the plugin. This will allow the admin role to view the Soft Delete item in the Admin left Panel. Accessing this will list all the content types the admin role has access to. They can restore or delete permanently the entries from here depending on the above permissions. - A new admin permission is added to the
Settings > Roles > Edit a Role > Plugins > Soft Deletesection. This is the globalSettingspermission of the plugin. This will allow the admin role to view the Soft Delete plugin settings.
- The
- 🗂️ Soft Delete Explorer (Admin left Panel item): Displays Soft Deleted Collection & Single Type entries
- ♻️ Entries can be restored with the
Restoreaction. This will set the fields_softDeletedAt,_softDeletedByIdand_softDeletedByTypetonull. - 🗑️ Entries can be permanently deleted with the
Delete Permanentlyaction. This will delete the entry permanently from the databse.
- ♻️ Entries can be restored with the
- ⚙️ Settings
- Restoration Behavior: This setting allows you to choose the behavior when restoring an entry.
- Single Type
- Soft Delete: Restoring a Single Type entry will restore it to the Content Manager explorer and Soft Delete the existing entry.
- Delete Permanently: Restoring a Single Type entry will restore it to the Content Manager explorer and Delete Permanently the existing entry.
- Draft & Publish
- Draft: Restoring a Draft & Publish entry will restore it to the Content Manager explorer as a draft.
- Unchanged: Restoring a Draft & Publish entry will restore it to the Content Manager explorer unchanged, meaning that if the entry was published, it will be restored as published.
- Single Type
- Restoration Behavior: This setting allows you to choose the behavior when restoring an entry.
| Section | Permission | Description |
|---|---|---|
| Collection & Single Types | Deleted Restore | Allows the admin role to restore the soft deleted entries. |
| Collection & Single Types | Deleted Read | Allows the admin role to view the soft deleted entries. |
| Collection & Single Types | Delete Permanently | Allows the admin role to delete permanently the soft deleted entries. |
| Plugins | Read | Allows the admin role to view the Soft Delete item in the Admin left Panel. |
| Plugins | Settings | Allows the admin role to view the Soft Delete plugin settings. |
| Strapi Version | Plugin Version |
|---|---|
| ^4.11 | 1.0.0 |
| ^3 | Not Supported |
This plugin is designed forStrapi v4 and will not work with v3.x.
Because of the way the plugin handles soft deleted entries, there are some caveats to be aware of:
- Lifecycle hooks:
beforeDelete,afterDelete,beforeDeleteManyandafterDeleteManylifecycle hooks are not triggered when soft deleting entries. Instead, thebeforeUpdate,afterUpdate,beforeUpdateManyandafterUpdateManyare.beforeDelete,afterDelete,beforeDeleteManyandafterDeleteManylifecycle hooks are triggered when permanently deleting entries.
To install this plugin, you need to add an NPM dependency to your Strapi application:
# Using Yarnyarn add strapi-plugin-soft-delete# Or using PNPMpnpm add strapi-plugin-soft-delete# Or using NPMnpm install strapi-plugin-soft-delete
Edit yourconfig/plugins.js|ts orconfig/<env>/plugins.js|ts file and add the following configuration:
// ..."soft-delete":{enabled:true,},// ...
Then, you'll need to build your admin panel:
# Using Yarnyarn build# Or using PNPMpnpm run build# Or using NPMnpm run build
Finally, start your application:
# Using Yarnyarn develop# Or using PNPMpnpm run develop# Or using NPMnpm run develop
Feel free to fork and make a PR if you want to add something or fix a bug.
- 🖧 Server
_softDeletedAtfield on API Content Types_softDeletedByIdfield on API Content Types_softDeletedByTypefield on API Content Types- Decorate Content Type Entity Services to handle
_softDeleted*fields when deleting an entry upondeleteordeleteManymethods - Decorate Content Type Entity Services to hide entries upon
findorfindManymethods - RBAC Permissions
- Admin Routes
- Single Type entry restore special case
- Draft & Publish support when restoring an entry
- Audit Logs support
- Custom Lifecycle Hooks
- Handle Soft Deleting Components
- Add tests
- 🗂️ Soft Delete Explorer
- Content Types list
- Entries list
- Pagination
- Filters
- Restore action
- Delete Permanently action
- Translation
- Soft Deleted Entry details
- ⚙️ Plugin Settings
- Restoration Behavior
- Single Type
- Draft & Publish
- Deletion Automation
- Restoration Behavior
To uninstall this plugin, you need to remove the NPM dependency from your Strapi application:
# Using Yarnyarn remove strapi-plugin-soft-delete# Or using PNPMpnpm remove strapi-plugin-soft-delete# Or using NPMnpm uninstall strapi-plugin-soft-delete
Edit yourconfig/plugins.js|ts orconfig/<env>/plugins.js|ts file and remove the following configuration:
// ..."soft-delete":{enabled:true,},// ...
Also,if you have edited your API Content Types through the Content Builder, and because the plugin adds fields to it, you'll need to remove them from the schemas manually. The fields are:
_softDeletedAt_softDeletedById_softDeletedByType
Then, you'll need to build your admin panel:
# Using Yarnyarn build# Or using PNPMpnpm run build# Or using NPMnpm run build
Finally, start your application:
# Using Yarnyarn develop# Or using PNPMpnpm run develop# Or using NPMnpm run develop
For general help using Strapi, please refer tothe official Strapi documentation. For additional help, you can use one of these channels to ask a question:
- Discord I'm present on official Strapi Discord workspace. Find me by
ChristopheCVB. - GitHub (Bug reports, Contributions, Questions and Discussions)
MIT License Copyright (c)ChristopheCVB.
About
Powerful Strapi based Soft Delete feature, never loose content again
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.

