mattmilburn / strapi-plugin-menus

A plugin for Strapi CMS to customize the structure of menus and menu items.
MIT License
110 stars 27 forks source link

lifecycle hooks in menus plugin #126

Open atul1104 opened 12 months ago

atul1104 commented 12 months ago

I am trying to log the audit logs, how can i use lifecycle hooks in Menus plugin to achieve the activity logs by user.

mattmilburn commented 11 months ago

Hi @atul1104 Currently there are no custom hooks in the menus plugin to allow you to do that, but we could talk about where they need to be added. I have never used the audit logs feature of Strapi so I might need an overview of what you're trying to capture in audit logs.

atul1104 commented 11 months ago

Yes surely, So I am implementing audit logs collection type where I am logging the users activities on other collection type such as if user create, update or delete any entry the same actions would be added as an entry in audit logs collection type. for this I am using lifecycle hooks e.g. afterCreate, afterUpdate, afterDelete etc. Now I want to implement the same for Menus plugin. For this I have created a filed called lifecycle.js beside the strapi-server.js file, i am trying with same lifecycle methods. and importing the same methods in strapi-server.js file. below is my lifecycle.js file as well as server.js file but when I console log the Menus entered data I am not getting the same. Lifecycle.js file: "use strict"; module.exports = { async afterCreate(event) { const { result, params } = event; console.log('result aftercreate in menus', result) strapi.entityService.create("api::log.log", { data: { contentType: "Menus", action: "New Content Entry", content: result, author: result.createdBy.email, }, }); }, }

strapi-server.js file: const menuItemLifecycle = require('./lifecycle'); plugin.contentTypes['menu-item'].lifecycle = menuItemLifecycle; console.log('menuItemLifecycle', menuItemLifecycle)