fix: prevent deleting absences for past dates #3346

Merged
jorgep merged 9 commits from hotfix-restrictAbsencePrivs into master 2025-01-09 08:53:25 +00:00
5 changed files with 11 additions and 8 deletions
Showing only changes of commit 412638d590 - Show all commits

View File

@ -58,12 +58,10 @@ module.exports = Self => {
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
throw new UserError(`You don't have enough privileges`);
const canModifyAbsenceInPast =
await models.ACL.checkAccessAcl(ctx, 'Worker', 'canModifyAbsenceInPast', 'WRITE');
const now = Date.vnNew();
const newDate = new Date(args.dated).getTime();
if ((now.getTime() > newDate) && !canModifyAbsenceInPast)
if (!await Self.canModifyAbsenceInPast(ctx, newDate))
throw new UserError(`Holidays to past days not available`);
Review

No acabo de ver el duplicar el UserError

No acabo de ver el duplicar el UserError
const labour = await models.WorkerLabour.findById(args.businessFk,

View File

@ -53,10 +53,8 @@ module.exports = Self => {
}
}
}, myOptions);
const canModifyAbsenceInPast =
await models.ACL.checkAccessAcl(ctx, 'Worker', 'canModifyAbsenceInPast', 'WRITE');
if (!canModifyAbsenceInPast && Date.vnNow() > absence.dated.getTime())
if (!await Self.canModifyAbsenceInPast(ctx, absence.dated.getTime()))
jorgep marked this conversation as resolved Outdated
Outdated
Review

En create ya esta codigo parecido b14268ef1b/modules/worker/back/methods/worker/createAbsence.js (L63)

Ver si unificar

En create ya esta codigo parecido https://gitea.verdnatura.es/verdnatura/salix/src/commit/b14268ef1bfd0091526255e390255ad664f3839a/modules/worker/back/methods/worker/createAbsence.js#L63 Ver si unificar
throw new UserError(`Holidays to past days not available`);
const result = await absence.destroy(myOptions);

View File

@ -1,7 +1,7 @@
const app = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('Worker createAbsence()', () => {
fdescribe('Worker createAbsence()', () => {
const workerId = 18;
it('should return an error for a user without enough privileges', async() => {

View File

@ -1,7 +1,7 @@
const app = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('Worker deleteAbsence()', () => {
fdescribe('Worker deleteAbsence()', () => {
const businessId = 18;
const workerId = 18;
const hrId = 37;

View File

@ -26,6 +26,13 @@ module.exports = Self => {
message: 'Invalid TIN'
});
Self.canModifyAbsenceInPast = async(ctx, time) => {
const hasPrivs = await Self.app.models.ACL.checkAccessAcl(ctx, 'Worker', 'canModifyAbsenceInPast', 'WRITE');
const now = Date.vnNew();
now.setHours(0, 0, 0, 0);
return hasPrivs || now.getTime() < time;
};
async function tinIsValid(err, done) {
const country = await Self.app.models.Country.findOne({
fields: ['code'],