This commit is contained in:
parent
5171e63188
commit
f9e7963e74
|
@ -21,7 +21,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getList = async(id, options) => {
|
Self.getList = async(id, options) => {
|
||||||
const notifications = [];
|
const notifications = new Map();
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
@ -29,11 +29,6 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const activeNotifications = await models.NotificationSubscription.find({
|
|
||||||
include: {relation: 'notification'},
|
|
||||||
where: {userFk: id}
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const roles = await models.RoleMapping.find({
|
const roles = await models.RoleMapping.find({
|
||||||
fields: ['roleId'],
|
fields: ['roleId'],
|
||||||
where: {principalId: id}
|
where: {principalId: id}
|
||||||
|
@ -43,29 +38,13 @@ module.exports = Self => {
|
||||||
include: {relation: 'notification'},
|
include: {relation: 'notification'},
|
||||||
where: {
|
where: {
|
||||||
roleFk: {
|
roleFk: {
|
||||||
inq: roles.map(role => {
|
inq: roles.map(role => role.roleId),
|
||||||
return role.roleId;
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}, myOptions);
|
}, 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) {
|
for (acl of availableNotifications) {
|
||||||
const activeNotif = notifications.find(
|
notifications.set(acl.notificationFk, {
|
||||||
notif => notif.notificationFk === acl.notificationFk
|
|
||||||
);
|
|
||||||
if (!activeNotif) {
|
|
||||||
notifications.push({
|
|
||||||
id: null,
|
id: null,
|
||||||
notificationFk: acl.notificationFk,
|
notificationFk: acl.notificationFk,
|
||||||
name: acl.notification().name,
|
name: acl.notification().name,
|
||||||
|
@ -73,8 +52,15 @@ module.exports = Self => {
|
||||||
active: false,
|
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()];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,9 +30,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
const worker = await models.Worker.findById(workerId, {fields: ['id', 'bossFk']});
|
const worker = await models.Worker.findById(workerId, {fields: ['id', 'bossFk']});
|
||||||
const notificationsAvailables = await models.NotificationSubscription.getList(workerId);
|
const notificationsAvailables = await models.NotificationSubscription.getList(workerId);
|
||||||
const hasAcl = notificationsAvailables.some(function(available) {
|
const hasAcl = notificationsAvailables.some(available => available.notificationFk === notificationFk);
|
||||||
return available.notificationFk === notificationFk;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!hasAcl || (userId != worker.id && userId != worker.bossFk))
|
if (!hasAcl || (userId != worker.id && userId != worker.bossFk))
|
||||||
throw new UserError('The notification subscription of this worker cant be modified');
|
throw new UserError('The notification subscription of this worker cant be modified');
|
||||||
|
|
Loading…
Reference in New Issue