summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLauri Ojansivu <x@xet7.org>2019-09-04 21:11:41 +0300
committerGitHub <noreply@github.com>2019-09-04 21:11:41 +0300
commitbfbe32e1ec945e883a5d0dbf52c5554d8908d995 (patch)
tree5a938aed02c398b6b11a60505a3c85746ed54441 /models
parentccfaf879dd4ea0c24d2fed34131be5ad151bb28c (diff)
parent510407467c5245f13fb9508b6e95f6b490dcd36b (diff)
downloadwekan-bfbe32e1ec945e883a5d0dbf52c5554d8908d995.tar.gz
wekan-bfbe32e1ec945e883a5d0dbf52c5554d8908d995.tar.bz2
wekan-bfbe32e1ec945e883a5d0dbf52c5554d8908d995.zip
Merge pull request #2665 from whowillcare/master
Add Feature: complete the original author's webhook functions and add two-way webhook type
Diffstat (limited to 'models')
-rw-r--r--models/activities.js23
-rw-r--r--models/integrations.js22
2 files changed, 35 insertions, 10 deletions
diff --git a/models/activities.js b/models/activities.js
index 3ecd5c8c..f64fce10 100644
--- a/models/activities.js
+++ b/models/activities.js
@@ -184,10 +184,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]);
@@ -268,13 +269,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 0b2e08c6..ce843680 100644
--- a/models/integrations.js
+++ b/models/integrations.js
@@ -88,16 +88,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'],
});