- Protect certain entries from being deleted.
- Use various comparators to match against protection rules.
yarn add strapi-plugin-do-not-delete@latest
property | type (default) | description |
---|---|---|
contentTypes | object (null ) |
A config object that describes protection rules for content types. |
A config object that describes protection rules for content types using the model UID and an array of comparators.
The object keys for contentTypes
should be a valid model UID and the value should be an array or arrays which describe the comparison rules.
Below, the comparison rule is querying if the slug
value for Page
is equal to home
, and if this condition is true, the delete operation is cancelled.
// ./config/plugins.js`
'use strict';
module.exports = {
'do-not-delete': {
config: {
contentTypes: {
'api::page.page': [
['slug', 'is', 'home'],
],
},
},
},
};
The items in each comparison array must follow the format:
[ 'attribute', 'comparator', 'value or pattern' ]
Comparator | Description |
---|---|
has |
Does the string attribute contain value ? |
in |
Does the value array include attribute ? |
is |
Strict equality with === |
matches |
RegExp test against pattern (do not include outer slashes) |
// ./config/plugins.js`
'use strict';
module.exports = {
'do-not-delete': {
config: {
contentTypes: {
'api::page.page': [
['slug', 'is', 'home'],
['slug', 'in', ['home', 'blog', '404']],
['slug', 'has', 'admin'],
['slug', 'matches', '^foobar'], // same as "starts with"
['slug', 'matches', 'foobar$'], // same as "ends with"
],
},
},
},
};
When attempting to delete a protected entry, a validation error will display at the top of the screen that reads:
This protected entry cannot be deleted.
If you find yourself in a scenario where a protected entry actually does need to be deleted, you must first update the plugin config to remove the protection rule that applies to that entry.
Remember to rebuild your app after making changes to some config or other code.
yarn build
# OR
yarn develop
If you are enjoying this plugin and feel extra appreciative, you can buy me a beer or 3 🍺🍺🍺.
- Settings page to visually manage protected entries and their applicable rules.
- Edit view sidebar button to "lock" an entity based on it's
id
. - Custom validation error messages.
- More comparators for protection rules.