fix: prevent deleting absences for past dates #3346
|
@ -1,2 +1,4 @@
|
||||||
|
DELETE FROM salix.ACL WHERE property = 'canCreateAbsenceInPast';
|
||||||
|
|
||||||
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
|
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
|
||||||
VALUES ('Worker','canDeleteAbsenceInPast','WRITE','ALLOW','ROLE','hr');
|
VALUES ('Worker','canModifyAbsenceInPast','WRITE','ALLOW','ROLE','hr');
|
||||||
|
|
|
@ -58,12 +58,12 @@ module.exports = Self => {
|
||||||
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
|
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
|
||||||
throw new UserError(`You don't have enough privileges`);
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
const canCreateAbsenceInPast =
|
const canModifyAbsenceInPast =
|
||||||
await models.ACL.checkAccessAcl(ctx, 'Worker', 'canCreateAbsenceInPast', 'WRITE');
|
await models.ACL.checkAccessAcl(ctx, 'Worker', 'canModifyAbsenceInPast', 'WRITE');
|
||||||
const now = Date.vnNew();
|
const now = Date.vnNew();
|
||||||
const newDate = new Date(args.dated).getTime();
|
const newDate = new Date(args.dated).getTime();
|
||||||
|
|
||||||
|
|||||||
if ((now.getTime() > newDate) && !canCreateAbsenceInPast)
|
if ((now.getTime() > newDate) && !canModifyAbsenceInPast)
|
||||||
throw new UserError(`Holidays to past days not available`);
|
throw new UserError(`Holidays to past days not available`);
|
||||||
|
|
||||||
const labour = await models.WorkerLabour.findById(args.businessFk,
|
const labour = await models.WorkerLabour.findById(args.businessFk,
|
||||||
|
|
|
@ -53,10 +53,10 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
const canDeleteAbsenceInPast =
|
const canModifyAbsenceInPast =
|
||||||
await models.ACL.checkAccessAcl(ctx, 'Worker', 'canDeleteAbsenceInPast', 'WRITE');
|
await models.ACL.checkAccessAcl(ctx, 'Worker', 'canModifyAbsenceInPast', 'WRITE');
|
||||||
jorgep marked this conversation as resolved
Outdated
alexm
commented
En create ya esta codigo parecido 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
|
|||||||
|
|
||||||
if (!canDeleteAbsenceInPast && Date.vnNow() > absence.dated.getTime())
|
if (!canModifyAbsenceInPast && Date.vnNow() > absence.dated.getTime())
|
||||||
throw new UserError(`Holidays to past days not available`);
|
throw new UserError(`Holidays to past days not available`);
|
||||||
|
|
||||||
const result = await absence.destroy(myOptions);
|
const result = await absence.destroy(myOptions);
|
||||||
|
|
Loading…
Reference in New Issue
No acabo de ver el duplicar el UserError