Add jwennUserAdminEpiId
This commit is contained in:
+22
-4
@@ -22,6 +22,15 @@ const jwennUserEpiId = async userId => {
|
|||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const jwennUserAdminEpiId = async userAdminId => {
|
||||||
|
if (!userAdminId) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = await strapi.query('user', 'admin').findOne({id: userAdminId, 'roles.code_nin': 'strapi-super-admin'})
|
||||||
|
return user
|
||||||
|
}
|
||||||
|
|
||||||
const translateTeks = async teksFR => {
|
const translateTeks = async teksFR => {
|
||||||
const english = await strapi.services.translator.translate('FR', 'EN', teksFR)
|
const english = await strapi.services.translator.translate('FR', 'EN', teksFR)
|
||||||
const espagnol = await strapi.services.translator.translate('FR', 'ES', teksFR)
|
const espagnol = await strapi.services.translator.translate('FR', 'ES', teksFR)
|
||||||
@@ -41,6 +50,11 @@ module.exports = {
|
|||||||
lifecycles: {
|
lifecycles: {
|
||||||
beforeCreate: async data => {
|
beforeCreate: async data => {
|
||||||
const user = await jwennUserEpiId(data?.user?.id)
|
const user = await jwennUserEpiId(data?.user?.id)
|
||||||
|
const userAdmin = await jwennUserAdminEpiId(data?.created_by)
|
||||||
|
|
||||||
|
if (userAdmin) {
|
||||||
|
data.userAdmin = userAdmin.username
|
||||||
|
}
|
||||||
|
|
||||||
if (data.tit && !data.forceSlug) {
|
if (data.tit && !data.forceSlug) {
|
||||||
const awtis = await jwennAwtisEpiId(data.awtis)
|
const awtis = await jwennAwtisEpiId(data.awtis)
|
||||||
@@ -76,10 +90,12 @@ module.exports = {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previousData.created_by) {
|
const user = await jwennUserAdminEpiId(previousData?.created_by?.id)
|
||||||
|
|
||||||
|
if (user) {
|
||||||
strapi.services.email.send(
|
strapi.services.email.send(
|
||||||
process.env.SMTP_FROM,
|
process.env.SMTP_FROM,
|
||||||
previousData.created_by.email,
|
user.email,
|
||||||
`Publication de "${previousData.tit}"`,
|
`Publication de "${previousData.tit}"`,
|
||||||
`Le titre que vous avez soumis, "${previousData.tit}" a été publié sur le site. Vous pouvez le trouver à l'adresse ${process.env.WEBSITE_URL}/paroles/${previousData.slug}`
|
`Le titre que vous avez soumis, "${previousData.tit}" a été publié sur le site. Vous pouvez le trouver à l'adresse ${process.env.WEBSITE_URL}/paroles/${previousData.slug}`
|
||||||
)
|
)
|
||||||
@@ -99,11 +115,13 @@ module.exports = {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.created_by) {
|
const user = await jwennUserAdminEpiId(data?.created_by?.id)
|
||||||
|
|
||||||
|
if (user) {
|
||||||
strapi.services.email.send(
|
strapi.services.email.send(
|
||||||
process.env.SMTP_FROM,
|
process.env.SMTP_FROM,
|
||||||
process.env.SMTP_SEND_TO,
|
process.env.SMTP_SEND_TO,
|
||||||
`Nouveau texte de ${data.created_by.username} : "${data.tit}" (dashboard)`,
|
`Nouveau texte de ${user.username} : "${data.tit}" (dashboard)`,
|
||||||
`Le titre "${data.tit}" a été soumis depuis le dashboard.`
|
`Le titre "${data.tit}" a été soumis depuis le dashboard.`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user