npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

strapi-plugin-do-not-delete

v1.2.0

Published

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

Downloads

534

Readme

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

Don't forget to restart or rebuild your Strapi app when installing a new plugin.

🔧 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 | | -- | -- | | 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) |

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

module.exports = {
  'do-not-delete': {
    config: {
      contentTypes: {
        'api::page.page': [
          // Equality.
          ['slug', 'is', 'home'],
          ['slug', 'isNot', 'test'],

          // Contains.
          ['slug', 'in', ['home', 'blog', '404']],
          ['slug', 'notIn', ['test', 'temp']],
          ['slug', 'has', 'admin'],
          ['slug', 'hasNot', '-test'],

          // Regular expression.
          ['slug', 'matches', '^foobar'], // same as "starts with"
          ['slug', 'matches', 'foobar$'], // same as "ends with"

          // Greater than or equal to.
          ['rating', 'lt', 10],
          ['rating', 'lte', 9],
          ['rating', 'gt', 4],
          ['rating', 'gte', 5],
          ['rating', 'between', [3, 6]],

          // Dates (any valid date string format can be used).
          ['publishedAt', 'after', '2022-12-31'],
          ['publishedAt', 'before', '2020-01-01T00:00:00.000Z'],
          ['publishedAt', 'day', 'Wed, 01 Jan 2020 00:00:00 GMT'],
          ['publishedAt', 'month', 'January 2020'],
          ['publishedAt', 'year', '2023'],
        ],
      },
    },
  },
};

📘 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.
  • RBAC features.
  • Custom validation error messages.