Do Not Delete
Protect certain entries from being deleted.
Strapi "Do Not Delete"
A plugin for Strapi CMS that protects certain entries from being deleted.
Get Started
✨ Features
- Protect certain entries from being deleted.
- Use various comparators to match against protection rules.
💎 Installation
yarn add strapi-plugin-do-not-delete@latestDon't forget to restart or rebuild your Strapi app when installing a new plugin.
🔧 Configuration
Configuration can be added to the pluginOptions of a schema. This will need to apply to each individual content type that utilizes this plugin.
1// ./api/page/content-types/page/schema.json
2{
3 "kind": "collectionType",
4 "collectionName": "pages",
5 "info": {
6 "singularName": "page",
7 "pluralName": "pages",
8 "displayName": "Page",
9 "description": "Generic web page"
10 },
11 "options": {
12 "draftAndPublish": true
13 },
14 "pluginOptions": {
15 "do-not-delete": {
16 // Config goes here.
17 }
18 },
19 "attributes": {
20 "title": {
21 "type": "string",
22 "required": true
23 },
24 "slug": {
25 "type": "uid",
26 "targetField": "title",
27 "required": true
28 }
29 }
30}| property | type | description |
|---|---|---|
| rules | array | An array of protection rules. |
rules
An array of protection rules.
Example
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.
1// ./api/page/content-types/page/schema.json
2"pluginOptions": {
3 "do-not-delete": {
4 "rules": [
5 ["slug", "is", "home"]
6 ]
7 }
8}Comparators
The items in each comparison array must follow the format:
1['attribute', 'comparator', 'value or pattern']| Comparator | Description |
|---|---|
is | Strict equality with === |
isNot | Strict inequality with !== |
in | Does the value array include attribute? |
notIn | Does the value array not include attribute? |
has | Does the attribute contain value? |
hasNot | Does the attribute not contain value? |
lt | Is attribute less than value? |
lte | Is attribute less than or equal to value? |
gt | Is attribute greater than value? |
gte | Is attribute greater than or equal to value? |
between | Does attribute fall between the pair of values? |
after | Does attribute occur after the value date? |
before | Does attribute occur before the value date? |
day | Does attribute occur on the same day of the value date? |
month | Does attribute occur in the same month of the value date? |
year | Does attribute occur in the same year of the value date? |
matches | RegExp test against pattern (do not include outer slashes) |
1// ./api/page/content-types/page/schema.json
2"pluginOptions": {
3 "do-not-delete": {
4 "rules": [
5 // Equality.
6 ["slug", "is", "home"],
7 ["slug", "isNot", "test"],
8
9 // Contains.
10 ["slug", "in", ["home", "blog", "404"]],
11 ["slug", "notIn", ["test", "temp"]],
12 ["slug", "has", "admin"],
13 ["slug", "hasNot", "-test"],
14
15 // Regular expression.
16 ["slug", "matches", "^foobar"], // same as "starts with"
17 ["slug", "matches", "foobar$"], // same as "ends with"
18
19 // Greater than or equal to.
20 ["rating", "lt", 10],
21 ["rating", "lte", 9],
22 ["rating", "gt", 4],
23 ["rating", "gte", 5],
24 ["rating", "between", [3, 6]],
25
26 // Dates (any valid date string format can be used).
27 ["publishedAt", "after", "2022-12-31"],
28 ["publishedAt", "before", "2020-01-01T00:00:00.000Z"],
29 ["publishedAt", "day", "Wed, 01 Jan 2020 00:00:00 GMT"],
30 ["publishedAt", "month", "January 2020"],
31 ["publishedAt", "year", "2023"],
32 ]
33 }
34}📘 User Guide
Attempting to delete a protected entry
When attempting to delete a protected entry, a validation error will display at the top of the screen that reads:
This entry is protected and cannot be deleted.
Deleting an entry that is currently protected
If you find yourself in a scenario where a protected entry actually does need to be deleted, you must first update the pluginOptions and restart Strapi to remove the protection rule that applies to that entry.
💩 Troubleshooting
In general
Remember to rebuild your app after making changes to some config or other code.
yarn build
# OR
yarn develop🚌 Migration
Follow the migration guides to keep your "do not delete" plugin up-to-date.
❤️ Support or Donate
If you are enjoying this plugin and feel extra appreciative, you can buy me a beer or 3 🍺🍺🍺.
🚧 Roadmap
- Custom validation error messages.
- RBAC features.
Install now
npm install strapi-plugin-do-not-delete
Create your own plugin
Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.