refs #4797 minor fixes
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alexandre Riera 2023-05-10 14:10:00 +02:00
parent 5171e63188
commit f9e7963e74
2 changed files with 18 additions and 34 deletions

View File

@ -21,7 +21,7 @@ module.exports = Self => {
});
Self.getList = async(id, options) => {
const notifications = [];
const notifications = new Map();
const models = Self.app.models;
const myOptions = {};
@ -29,11 +29,6 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
const activeNotifications = await models.NotificationSubscription.find({
include: {relation: 'notification'},
where: {userFk: id}
}, myOptions);
const roles = await models.RoleMapping.find({
fields: ['roleId'],
where: {principalId: id}
@ -43,29 +38,13 @@ module.exports = Self => {
include: {relation: 'notification'},
where: {
roleFk: {
inq: roles.map(role => {
return role.roleId;
}),
inq: roles.map(role => role.roleId),
},
}
}, myOptions);
for (subscription of activeNotifications) {
notifications.push({
id: subscription.id,
notificationFk: subscription.notificationFk,
name: subscription.notification().name,
description: subscription.notification().description,
active: true
});
}
for (acl of availableNotifications) {
const activeNotif = notifications.find(
notif => notif.notificationFk === acl.notificationFk
);
if (!activeNotif) {
notifications.push({
notifications.set(acl.notificationFk, {
id: null,
notificationFk: acl.notificationFk,
name: acl.notification().name,
@ -73,8 +52,15 @@ module.exports = Self => {
active: false,
});
}
}
return notifications;
const activeNotifications = await models.NotificationSubscription.find({
include: {relation: 'notification'},
where: {userFk: id}
}, myOptions);
for (subscription of activeNotifications)
notifications.get(subscription.notificationFk).active = true;
return [...notifications.values()];
};
};

View File

@ -30,9 +30,7 @@ module.exports = Self => {
const worker = await models.Worker.findById(workerId, {fields: ['id', 'bossFk']});
const notificationsAvailables = await models.NotificationSubscription.getList(workerId);
const hasAcl = notificationsAvailables.some(function(available) {
return available.notificationFk === notificationFk;
});
const hasAcl = notificationsAvailables.some(available => available.notificationFk === notificationFk);
if (!hasAcl || (userId != worker.id && userId != worker.bossFk))
throw new UserError('The notification subscription of this worker cant be modified');