feat: refs #8239 Added checkColumnPermission method
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Guillermo Bonet 2024-12-18 07:57:18 +01:00
parent 7d047017f6
commit fae728f1cb
6 changed files with 11 additions and 15 deletions

View File

@ -43,11 +43,8 @@ module.exports = Self => {
Self.checkColumnPermission = async(schema, table, column, privilegeType, userId) => { Self.checkColumnPermission = async(schema, table, column, privilegeType, userId) => {
const models = Self.app.models; const models = Self.app.models;
const $t = ((msg, vars) => // Me falta hacer funcionar el $t, ya que probando con ctx no funciona
msg.replace(/\{(\w+)\}/g, (_, key) => vars[key] || '')
);
const user = await models.VnUser.findById(userId); const user = await models.VnUser.findById(userId);
if (!user) return;
const role = await models.VnRole.findById(user.roleFk); const role = await models.VnRole.findById(user.roleFk);
const permissions = await Self.rawSql(` const permissions = await Self.rawSql(`
SELECT TRUE SELECT TRUE
@ -60,6 +57,6 @@ module.exports = Self => {
`, [schema, table, column, privilegeType, role.name]); `, [schema, table, column, privilegeType, role.name]);
if (!permissions.length) if (!permissions.length)
throw new UserError($t(`You don't have enough privileges to modify`, {column})); throw new UserError(`You do not have sufficient privileges to modify a specific column`);
}; };
}; };

View File

@ -249,6 +249,5 @@
"Sales already moved": "Sales already moved", "Sales already moved": "Sales already moved",
"Holidays to past days not available": "Holidays to past days not available", "Holidays to past days not available": "Holidays to past days not available",
"Price cannot be blank": "Price cannot be blank", "Price cannot be blank": "Price cannot be blank",
"There are tickets to be invoiced": "There are tickets to be invoiced", "There are tickets to be invoiced": "There are tickets to be invoiced"
"You don't have enough privileges to modify": "You don't have enough privileges to modify: {{column}}"
} }

View File

@ -399,5 +399,5 @@
"All tickets have a route order": "Todos los tickets tienen orden de ruta", "All tickets have a route order": "Todos los tickets tienen orden de ruta",
"Price cannot be blank": "Price cannot be blank", "Price cannot be blank": "Price cannot be blank",
"There are tickets to be invoiced": "La zona tiene tickets por facturar", "There are tickets to be invoiced": "La zona tiene tickets por facturar",
"You don't have enough privileges to modify": "No tienes suficientes permisos para modificar la columna: {{column}}" "You do not have sufficient privileges to modify a specific column": "No tienes suficientes permisos para modificar una columna específica"
} }

View File

@ -366,6 +366,5 @@
"The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne", "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne",
"You do not have permission to modify the booked field": "Vous n'avez pas la permission de modifier le champ comptabilisé", "You do not have permission to modify the booked field": "Vous n'avez pas la permission de modifier le champ comptabilisé",
"ticketLostExpedition": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a l'expédition perdue suivante : {{expeditionId}}", "ticketLostExpedition": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a l'expédition perdue suivante : {{expeditionId}}",
"The web user's email already exists": "L'email de l'internaute existe déjà", "The web user's email already exists": "L'email de l'internaute existe déjà"
"You don't have enough privileges to modify": "Vous n'avez pas suffisamment de privilèges pour modifier: {{column}}"
} }

View File

@ -365,6 +365,5 @@
"Cannot send mail": "Não é possível enviar o email", "Cannot send mail": "Não é possível enviar o email",
"The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha", "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha",
"ticketLostExpedition": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem a seguinte expedição perdida: {{expeditionId}}", "ticketLostExpedition": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem a seguinte expedição perdida: {{expeditionId}}",
"The web user's email already exists": "O e-mail do utilizador da web já existe.", "The web user's email already exists": "O e-mail do utilizador da web já existe."
"You don't have enough privileges to modify": "Você não tem privilégios suficientes para modificar: {{column}}"
} }

View File

@ -23,9 +23,11 @@ module.exports = Self => {
Self.observe('before save', async function(ctx) { Self.observe('before save', async function(ctx) {
await Self.availableId(ctx); await Self.availableId(ctx);
if (!(ctx?.data?.packingOut === undefined)) {
await models.Application.checkColumnPermission( await models.Application.checkColumnPermission(
'vn', 'item', 'packingOut', 'UPDATE', ctx.options.accessToken.userId 'vn', 'item', 'packingOut', 'UPDATE', ctx.options.accessToken.userId
); );
}
}); });
Self.availableId = async function(ctx) { Self.availableId = async function(ctx) {