/strapi-plugin-do-not-delete

A plugin for Strapi CMS that protects certain entries from being deleted.

Primary LanguageJavaScriptMIT LicenseMIT

Logo for Strapi do not delete plugin

Strapi "Do Not Delete"

A plugin for Strapi CMS that protects certain entries from being deleted.

Screenshot for Strapi do not delete plugin

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@latest

πŸ”§ Configuration

property type (default) description
contentTypes object (null) A config object that describes protection rules for content types.

contentTypes

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.

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.

// ./config/plugins.js`
'use strict';

module.exports = {
  'do-not-delete': {
    config: {
      contentTypes: {
        'api::page.page': [
          ['slug', 'is', 'home'],
        ],
      },
    },
  },
};

Comparators

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"
        ],
      },
    },
  },
};

πŸ“˜ 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 protected entry 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 plugin config 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

❀️ Support or Donate

If you are enjoying this plugin and feel extra appreciative, you can buy me a beer or 3 🍺🍺🍺.

🚧 Roadmap

  • 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.