refs #6085 refactor sql trad
This commit is contained in:
parent
866ad7a9f9
commit
584f3264ed
|
@ -68,4 +68,4 @@ Load more results: Cargar más resultados
|
|||
Send cau: Enviar cau
|
||||
By sending this ticket, all the data related to the error, the section, the user, etc., are already sent.: Al enviar este cau ya se envían todos los datos relacionados con el error, la sección, el usuario, etc
|
||||
ExplainReason: Explique el motivo por el que no deberia aparecer este fallo
|
||||
You already have the mailAlias: Ya tienes este mail
|
||||
You already have the mailAlias: Ya tienes este alias de correo
|
||||
|
|
|
@ -330,6 +330,6 @@
|
|||
"quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mínima",
|
||||
"Cannot past travels with entries": "No se pueden pasar envíos con entradas",
|
||||
"It was not able to remove the next expeditions:": "No se pudo eliminar las siguientes expediciones: {{expeditions}}",
|
||||
"You already have the mailAlias": "You already have the mailAlias",
|
||||
"The alias cant be modified": "The alias cant be modified"
|
||||
}
|
||||
"You already have the mailAlias": "Ya tienes este alias de correo",
|
||||
"The alias cant be modified": "Este alias de correo no puede ser modificado"
|
||||
}
|
||||
|
|
|
@ -22,12 +22,6 @@ module.exports = Self => {
|
|||
|
||||
async function checkModifyPermission(ctx, mailAliasFk) {
|
||||
const userId = ctx.options.accessToken.userId;
|
||||
const available = await Self.getAvailable(userId);
|
||||
if (!available.has(mailAliasFk))
|
||||
throw new UserError('The alias cant be modified');
|
||||
}
|
||||
|
||||
Self.getAvailable = async function(userId, options) {
|
||||
const models = Self.app.models;
|
||||
|
||||
const myOptions = {};
|
||||
|
@ -47,9 +41,11 @@ module.exports = Self => {
|
|||
roleFk: {
|
||||
inq: roles.map(role => role.roleId),
|
||||
},
|
||||
mailAliasFk
|
||||
}
|
||||
}, myOptions);
|
||||
const mailAliasArray = Array.from(availableMailAlias, alias => alias.mailAliasFk);
|
||||
return new Set(mailAliasArray);
|
||||
};
|
||||
|
||||
console.log(availableMailAlias);
|
||||
if (!availableMailAlias.length) throw new UserError('The alias cant be modified');
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
|
||||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.rewriteDbError(function(err) {
|
||||
if (err.code === 'ER_DUP_ENTRY')
|
||||
return new UserError(`You already have the mailAlias`);
|
||||
return err;
|
||||
});
|
||||
|
||||
Self.observe('before save', async ctx => {
|
||||
const changes = ctx.currentInstance || ctx.instance;
|
||||
|
||||
await checkModifyPermission(ctx, changes.mailAlias);
|
||||
});
|
||||
|
||||
Self.observe('before delete', async ctx => {
|
||||
const mailAliasAccount = await Self.findById(ctx.where.id);
|
||||
|
||||
await checkModifyPermission(ctx, mailAliasAccount.mailAlias);
|
||||
});
|
||||
|
||||
async function checkModifyPermission(ctx, mailAliasFk) {
|
||||
const userId = ctx.options.accessToken.userId;
|
||||
const available = await Self.getAvailable(userId);
|
||||
if (!available.has(mailAliasFk))
|
||||
throw new UserError('The alias cant be modified');
|
||||
}
|
||||
|
||||
Self.getAvailable = async function(userId, options) {
|
||||
const models = Self.app.models;
|
||||
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const roles = await models.RoleMapping.find({
|
||||
fields: ['roleId'],
|
||||
where: {principalId: userId}
|
||||
}, myOptions);
|
||||
|
||||
const availableMailAlias = await models.MailAliasAcl.find({
|
||||
fields: ['mailAliasFk'],
|
||||
include: {relation: 'mailAlias'},
|
||||
where: {
|
||||
roleFk: {
|
||||
inq: roles.map(role => role.roleId),
|
||||
},
|
||||
}
|
||||
}, myOptions);
|
||||
const mailAliasArray = Array.from(availableMailAlias, alias => alias.mailAliasFk);
|
||||
return new Set(mailAliasArray);
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue