Permit superuser to translate paroles in dashboard
This commit is contained in:
@@ -76,24 +76,35 @@ const jwennUserAdminEpiId = async userAdminId => {
|
|||||||
return userAdmin
|
return userAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
const validateParoles = (titre, transcription) => {
|
const jwennSuperAdminEpiId = async userAdminId => {
|
||||||
if (!titre || titre.trim().length === 0) {
|
if (!userAdminId) {
|
||||||
throw new ValidationError('Champ obligatoire. Veuillez choisir un titre.');
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!transcription || transcription.trim().length === 0) {
|
const userAdmin = await strapi.db.query('admin::user').findOne({
|
||||||
throw new ValidationError('Champ obligatoire. Veuillez renseigner la transcription.')
|
where: {
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
id: userAdminId
|
||||||
|
},
|
||||||
|
{
|
||||||
|
roles: {
|
||||||
|
code: {
|
||||||
|
$eq: 'strapi-super-admin'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
if (transcription.trim().length < 10) {
|
return userAdmin
|
||||||
throw new ValidationError('La transcription doit contenir au moins 10 caractères.')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
beforeCreate: async event => {
|
beforeCreate: async event => {
|
||||||
let {data} = event.params
|
let {data} = event.params
|
||||||
validateParoles(data.titre, data.transcription)
|
strapi.service('api::parole.parole').validateParoles(data.titre, data.transcription)
|
||||||
|
|
||||||
const userAdmin = await jwennUserAdminEpiId(data?.createdBy)
|
const userAdmin = await jwennUserAdminEpiId(data?.createdBy)
|
||||||
|
|
||||||
@@ -117,7 +128,7 @@ module.exports = {
|
|||||||
const {where} = event.params
|
const {where} = event.params
|
||||||
|
|
||||||
if(!data.publishedAt && data.titre && data.transcription) {
|
if(!data.publishedAt && data.titre && data.transcription) {
|
||||||
validateParoles(data.titre, data.transcription)
|
strapi.service('api::parole.parole').validateParoles(data.titre, data.transcription)
|
||||||
if (data.titre && !data.forceSlug) {
|
if (data.titre && !data.forceSlug) {
|
||||||
const artiste = await jwennAwtisEpiId(data.artistes)
|
const artiste = await jwennAwtisEpiId(data.artistes)
|
||||||
data.slug = getSlug(artiste, data.titre)
|
data.slug = getSlug(artiste, data.titre)
|
||||||
@@ -170,6 +181,28 @@ module.exports = {
|
|||||||
const {data} = event.params
|
const {data} = event.params
|
||||||
const user = await jwennUserEpiId(data.user)
|
const user = await jwennUserEpiId(data.user)
|
||||||
const userAdmin = await jwennUserAdminEpiId(data?.createdBy)
|
const userAdmin = await jwennUserAdminEpiId(data?.createdBy)
|
||||||
|
const superAdmin = await jwennSuperAdminEpiId(data?.createdBy)
|
||||||
|
const traductionsId = data.traductions.id
|
||||||
|
|
||||||
|
const result = await strapi.db.query('api::parole.parole').findOne({
|
||||||
|
where: {
|
||||||
|
traductions: {
|
||||||
|
id: {
|
||||||
|
$eq: traductionsId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
populate: {traductions: true, artistes: true}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (superAdmin && data.traductionAuto && result.traductions.francais && (!result.traductions.anglais || !result.traductions.espagnol || !result.traductions.allemand || !result.traductions.italien)) {
|
||||||
|
const traductions = await strapi.service('api::parole.parole').translateLyrics(result.traductions.francais)
|
||||||
|
await strapi.entityService.update('api::parole.parole', result.id, {
|
||||||
|
data: {
|
||||||
|
traductions
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
strapi.plugins['email'].services.email.send({
|
strapi.plugins['email'].services.email.send({
|
||||||
|
|||||||
Reference in New Issue
Block a user