diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/activities.js | 23 | ||||
-rw-r--r-- | models/integrations.js | 22 |
2 files changed, 35 insertions, 10 deletions
diff --git a/models/activities.js b/models/activities.js index 8f7e1285..a864e5e4 100644 --- a/models/activities.js +++ b/models/activities.js @@ -190,10 +190,11 @@ if (Meteor.isServer) { // it's person at himself, ignore it? continue; } - const user = Users.findOne(username) || Users.findOne({ username }); - const uid = user && user._id; + const atUser = + Users.findOne(username) || Users.findOne({ username }); + const uid = atUser && atUser._id; params.atUsername = username; - params.atEmails = user.emails; + params.atEmails = atUser.emails; if (board.hasMember(uid)) { title = 'act-atUserComment'; watchers = _.union(watchers, [uid]); @@ -274,13 +275,23 @@ if (Meteor.isServer) { }); const integrations = Integrations.find({ - boardId: board._id, - type: 'outgoing-webhooks', + boardId: { $in: [board._id, Integrations.Const.GLOBAL_WEBHOOK_ID] }, + // type: 'outgoing-webhooks', // all types enabled: true, activities: { $in: [description, 'all'] }, }).fetch(); if (integrations.length > 0) { - Meteor.call('outgoingWebhooks', integrations, description, params); + integrations.forEach(integration => { + Meteor.call( + 'outgoingWebhooks', + integration, + description, + params, + () => { + return; + }, + ); + }); } }); } diff --git a/models/integrations.js b/models/integrations.js index 41334744..dbf53b8e 100644 --- a/models/integrations.js +++ b/models/integrations.js @@ -90,16 +90,30 @@ Integrations.attachSchema( }, }), ); - +Integrations.Const = { + GLOBAL_WEBHOOK_ID: '_global', + ONEWAY: 'outgoing-webhooks', + TWOWAY: 'bidirectional-webhooks', + get WEBHOOK_TYPES() { + return [this.ONEWAY, this.TWOWAY]; + }, +}; +const permissionHelper = { + allow(userId, doc) { + const user = Users.findOne(userId); + const isAdmin = user && Meteor.user().isAdmin; + return isAdmin || allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); + }, +}; Integrations.allow({ insert(userId, doc) { - return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); + return permissionHelper.allow(userId, doc); }, update(userId, doc) { - return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); + return permissionHelper.allow(userId, doc); }, remove(userId, doc) { - return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); + return permissionHelper.allow(userId, doc); }, fetch: ['boardId'], }); |