0.12.8 : add activity and notification after user creation
All checks were successful
Build release Docker image / Build Docker Images (push) Successful in 6m47s
All checks were successful
Build release Docker image / Build Docker Images (push) Successful in 6m47s
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
"name": "Apache 2.0",
|
||||
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
},
|
||||
"x-generation-date": "2025-11-19T13:05:17.727Z"
|
||||
"x-generation-date": "2025-11-21T12:49:29.594Z"
|
||||
},
|
||||
"x-strapi-config": {
|
||||
"plugins": [
|
||||
|
||||
@@ -442,6 +442,45 @@ module.exports = (plugin) => {
|
||||
}
|
||||
};
|
||||
|
||||
plugin.contentTypes.user.lifecycles = {
|
||||
async afterCreate(event) {
|
||||
const { result } = event;
|
||||
|
||||
const newActivity = {
|
||||
activityMessage: `Bienvenue ${result.username}, Ton compte est maintenant activé.`,
|
||||
activityUser: result.username,
|
||||
activityDate: new Date(),
|
||||
activityType: "user" as const,
|
||||
};
|
||||
|
||||
await strapi.entityService.update(
|
||||
"plugin::users-permissions.user",
|
||||
result.id,
|
||||
{
|
||||
data: {
|
||||
activities: [newActivity],
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
// Appel du service de notification
|
||||
await strapi
|
||||
.service("api::notification.notification")
|
||||
?.createNotification({
|
||||
title: "Bienvenue !",
|
||||
message: `Ton compte est maintenant activé.`,
|
||||
type: "success",
|
||||
target_user: result.id,
|
||||
source: "system",
|
||||
payload: { email: result.email },
|
||||
});
|
||||
|
||||
strapi.log.info(
|
||||
`🔔 Notification envoyée pour l'utilisateur ${result.id}`
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
plugin.routes["content-api"].routes.push({
|
||||
method: "PUT",
|
||||
path: "/users/me",
|
||||
|
||||
Reference in New Issue
Block a user