Giter Club home page Giter Club logo

strapi-plugin-soft-delete's Introduction

Hi πŸ‘‹, I'm Chris

A passionate Full Stack Lead Developer

profile views

trophies

Connect with me:

twitter linkedin stackoverflow medium

Languages and Tools:

android angular aws bash css3 docker elasticsearch firebase gcp git graphql heroku html5 java javascript jenkins kotlin linux mariadb mongodb mysql nodejs nuxtjs php postgresql python rails react realm redis ruby sqlite tailwind vuejs vuetify nest nextjs

languages

Github Stats

Streak Stats

strapi-plugin-soft-delete's People

Contributors

christophecvb avatar derrickmehaffy avatar quiloos39 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

strapi-plugin-soft-delete's Issues

Tiny patch for issues, can not delete one or many data

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/strapi-plugin-soft-delete/dist/server/utils/index.js b/node_modules/strapi-plugin-soft-delete/dist/server/utils/index.js
index 5e664e9..c368c74 100644
--- a/node_modules/strapi-plugin-soft-delete/dist/server/utils/index.js
+++ b/node_modules/strapi-plugin-soft-delete/dist/server/utils/index.js
@@ -15,6 +15,7 @@ const getService = (name) => {
 };
 exports.getService = getService;
 const eventHubEmit = async (params) => {
+    if (!params.uid) { return };
     const modelDef = strapi.getModel(params.uid);
     const sanitizedEntity = await utils_1.sanitize.sanitizers.defaultSanitizeOutput(modelDef, params.entity);
     strapi.eventHub.emit(params.event, {


diff --git a/node_modules/strapi-plugin-soft-delete/server/utils/index.ts b/node_modules/strapi-plugin-soft-delete/server/utils/index.ts
index 6c541d9..d3d4efa 100644
--- a/node_modules/strapi-plugin-soft-delete/server/utils/index.ts
+++ b/node_modules/strapi-plugin-soft-delete/server/utils/index.ts
@@ -29,6 +29,7 @@ declare type CustomEventHubEmit = {
 });
 
 export const eventHubEmit = async (params: CustomEventHubEmit) => {
+  if (!params.uid) { return };
   const modelDef = strapi.getModel(params.uid);
   const sanitizedEntity = await sanitize.sanitizers.defaultSanitizeOutput(
     modelDef,

This issue body was partially generated by patch-package.

node v20

Please add support for node v20 as that is LTS and also preferred by current strapi 4 releases

npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '[email protected]',
npm WARN EBADENGINE   required: { node: '>=14.19.1 <=18.x.x', npm: '>=6.0.0' },
npm WARN EBADENGINE   current: { node: 'v20.11.0', npm: '10.2.4' }
npm WARN EBADENGINE }

Website crash when Bulk delete records from Content Manager in Strapi Admin

Bug report

Required System information

  • Node.js version: 20.11.1
  • NPM version: 10.2.4
  • Strapi version: 4.20.1
  • Database: MySql
  • Operating system: Windows
  • Is your project Javascript or Typescript: Javascript

Describe the bug

When i select any item from listing, and click on delete button. the Strapi Admin site is crash with below error.
image

if remove this plugin from Strapi, the bulk delete is working without any error.

Steps to reproduce the behavior

  1. Go to Content Manager
  2. Click on check box for Select item
  3. Click on Delete button which is display after filter button
  4. Strapi admin crash after that action with above error.

image

Expected behavior

Delete the item without error.

Add support soft-delete for tables from 'plugins'

Is your feature request related to a problem? Please describe.

For all entities from api section softDelete works correctly.

But for @strapi/plugin-users-permissions
SofDelete didn't add the fields

_softDeletedAt: Attribute.DateTime & Attribute.Private;
_softDeletedById: Attribute.Integer & Attribute.Private;
_softDeletedByType: Attribute.String & Attribute.Private;

But for queries (update up_users) apply.

Describe the solution you'd like
in the strapi-plugin-soft-delete/utils/plugin.ts


export const supportsContentType = (uid?: string) => {
  return uid?.match(/^api::/) || false;// || !uid?.match(/^\w+::/) || false; // TODO: Deleting a compoment doesn't use the entityService
};

replace by


export const supportsContentType = (uid?: string) => {
  return uid?.match(/^api::/) || uid?.match(/^plugin::/) || false;// || !uid?.match(/^\w+::/) || false; // TODO: Deleting a compoment doesn't use the entityService
};

[FR]: Implement custom event on event hub for audit logs

Recommendation to emit some events into the eventhub to get picked up by audit logs and webhooks:

Events that you can use (for now until I figure out if we can have custom events): https://github.com/strapi/strapi/blob/07bbe1588e18f8a5881766f82c8223e154f97688/packages/core/admin/ee/server/services/audit-logs.js#L9-L38

I wrote a few samples from your bootstrap for delete and deleteMany:

(you'll need the utils package like const strapiUtils = require('@strapi/utils');

For delete I tweaked your return to throw it into a var:

            const data = await defaultService.update(uid, id, {
                ...wrappedParams,
                data: {
                    ...wrappedParams.data,
                    _softDeletedAt: Date.now(),
                    _softDeletedById: authId,
                    _softDeletedByType: authStrategy,
                },
            });

            const modelDef = strapi.getModel(uid);
            const sanitizedEntity = await strapiUtils.sanitize.sanitizers.defaultSanitizeOutput(
              modelDef,
              data
            );

            strapi.eventHub.emit('entry.delete', { model: modelDef.modelName, uid: uid, plugin: 'soft-delete', entry: sanitizedEntity });

            return data;

Same for deleteMany but included a loop to emit events for each:

           const modelDef = strapi.getModel(uid);

           for (let i = 0; i < deletedEntities.length; i++) {

             const sanitizedEntity = await strapiUtils.sanitize.sanitizers.defaultSanitizeOutput(
               modelDef,
               deletedEntities[i]
             );
             strapi.eventHub.emit('entry.delete', { model: modelDef.modelName, uid: uid, plugin: 'soft-delete', entry: sanitizedEntity });
           }

           return deletedEntities;

_softDeletedAt filter do not spread for nested records

Bug report

Required System information

  • Node.js version:
  • NPM version:
  • Strapi version:
  • Database:
  • Operating system:
  • Is your project Javascript or Typescript:

Describe the bug

I run the following query


query Suppliers($filters: SupplierFiltersInput, $certificationsFilters2: CertificationFiltersInput) {
  suppliers(filters: $filters) {
    data {
      id
      attributes {
        companyName
        recipient_organization {
          data {
            id
            attributes {
              name
              certifications(filters: $certificationsFilters2) {
                data {
                  id
                }
              }
            }
          }
        }
      }
    }
  }
}

some of the Suppliers have a recipient_organization that have a few deleted certifications

And they appear in the results. Unfortunately.

I guess because


const sdWrapParams = async (defaultService: any, opts: any, ctx: { uid: string, action: string }) => {
  const { uid, action } = ctx;
  const wrappedParams = await defaultService.wrapParams(opts, ctx);

  if (!plugin.supportsContentType(uid)) {
    return wrappedParams;
  }

  // Prevent users to set values for _softDeletedAt, _softDeletedById, and _softDeletedByType
  if (wrappedParams.data) {
    delete wrappedParams.data._softDeletedAt;
    delete wrappedParams.data._softDeletedById;
    delete wrappedParams.data._softDeletedByType;
  }

  return {
    ...wrappedParams,
    filters: {
      $and: [
        {
          ...wrappedParams.filters
        },
        {
          _softDeletedAt: {
            $null: true
          },
        },
      ],
    },
  };
}

the following filter

     _softDeletedAt: {
            $null: true
          },
          

apply only for top level entity.

Steps to reproduce the behavior

  1. Create two or more entities
  2. add relations between they
  3. add records to both of the table
  4. remove some of nested records
  5. Make request with related nested records.

You will see deleted records in the result

Expected behavior

I think would be good to get only non-deleted records.

Media library : Unknown column 't0._softDeletedAt' in 'where clause'

Hi,

When trying to edit a media from media library (Media library > Click on media > "Replace media" button) I get the following error :

Exception has occurred: Error: select t0.id from files as t0 where (t0.id = 2 and t0._softDeletedAt is null) limit 1
Unknown column 't0._softDeletedAt' in 'where clause'

I've tried to debug and I think that the source of the problem is here :

if (event === 'entry.update' && data.plugin?.id !== plugin.pluginId) {

Shouldn't the test include the same filtering as done in the entityService overrides ?

if (!plugin.supportsContentType(uid)) {

Note that I've had this bug with other scenarios working with media library that I haven't been able to reproduce.

  • Node.js version: 20
  • Strapi version: 4.15.0
  • Database: mysql
  • Operating system: macos
  • Is your project Javascript or Typescript: TS

Server will be crashed in batch delete

Bug report

Required System information

  • Node.js version: v18.12.0
  • NPM version:
  • Strapi version: 4.14.4
  • Database:
  • Operating system: OSX
  • Is your project Javascript or Typescript: Javascript

Describe the bug

If you select one or more records from the list with the checkbox at the beginning of the rows and after that push the delete button, then the server has been crashed with the following exception:

node_modules/strapi-plugin-soft-delete/node_modules/@strapi/utils/dist/index.js:1957 throw new Error("Missing schema in defaultSanitizeOutput");

Steps to reproduce the behavior

  1. Go to a collection list on admin dashboard
  2. Select one or more records from the list
  3. The delete button will be shown after the first record has been selected. Push the delete button
  4. The server will be crashed.

Custom collection entity deletion from Content Manager throws Error and halts the dev server.

Bug report

Required System information

  • Node.js version: 18.18.2
  • NPM version: 10.2.4
  • YARN: 1.22.21
  • Strapi version: 4.15.0
  • Database: sqlite
  • Operating system: Ubuntu 22.04
  • Is your project Javascript or Typescript: TS

Describe the bug

When deleting a custom collection entity from the Content Manager an Error is thrown and halts the dev server.

Error

node_modules/strapi-plugin-soft-delete/node_modules/@strapi/utils/dist/index.js
throw new Error("Missing schema in defaultSanitizeOutput");
Missing schema in defaultSanitizeOutput

Steps to reproduce the behavior

  1. Running locally yarn dev
  2. Go to Content Manager
  3. Delete entry for a custom collection

Expected behavior

Shouldn't throw an Error and halt the server.

Code snippets

It appears that params.uid is undefined HERE

console output for params

{
  uid: undefined,
  event: 'entry.delete',
  action: 'soft-delete',
  entity: {
    id: 57,
    uuid: '...',
    note: '...',
    total: 73,
    currency: '...',
    createdAt: '2023-12-21T14:08:35.126Z',
    updatedAt: '2023-12-21T21:39:43.356Z',
    status: 'pending',
    _softDeletedAt: '2023-12-21T21:39:43.353Z',
    _softDeletedById: 2,
    _softDeletedByType: 'admin'
  }
}

Simply checking if params.uid is empty and returning if (!params.uid) return; bypasses the issue with no thoroughly verified side effects.

Additional context

I can see the Order is properly deleted and I can access and Restore it from the Soft Delete menu.

I have also upgraded the plugin to strapi 4.15.0 and it appears to function as expected, but still contains the bug.

I have patched the plugin locally for now.

Looking forward to feedback.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.