mirror of https://github.com/wekan/wekan
Merge branch 'improve-notify' of https://github.com/nztqa/wekan into nztqa-improve-notify
commit
510708d0e1
@ -0,0 +1,54 @@ |
||||
Integrations = new Mongo.Collection('integrations'); |
||||
|
||||
Integrations.attachSchema(new SimpleSchema({ |
||||
enabled: { |
||||
type: Boolean, |
||||
defaultValue: true, |
||||
}, |
||||
title: { |
||||
type: String, |
||||
optional: true, |
||||
}, |
||||
type: { |
||||
type: String, |
||||
}, |
||||
url: { // URL validation regex (https://mathiasbynens.be/demo/url-regex)
|
||||
type: String, |
||||
}, |
||||
token: { |
||||
type: String, |
||||
optional: true, |
||||
}, |
||||
boardId: { |
||||
type: String, |
||||
}, |
||||
createdAt: { |
||||
type: Date, |
||||
denyUpdate: false, |
||||
autoValue() { // eslint-disable-line consistent-return
|
||||
if (this.isInsert) { |
||||
return new Date(); |
||||
} else { |
||||
this.unset(); |
||||
} |
||||
}, |
||||
}, |
||||
userId: { |
||||
type: String, |
||||
autoValue() { // eslint-disable-line consistent-return
|
||||
if (this.isInsert || this.isUpdate) { |
||||
return this.userId; |
||||
} |
||||
}, |
||||
}, |
||||
})); |
||||
|
||||
Integrations.allow({ |
||||
insert(userId, doc) { |
||||
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); |
||||
}, |
||||
update(userId, doc) { |
||||
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); |
||||
}, |
||||
fetch: ['boardId'], |
||||
}); |
@ -0,0 +1,47 @@ |
||||
const postCatchError = Meteor.wrapAsync((url, options, resolve) => { |
||||
HTTP.post(url, options, (err, res) => { |
||||
if (err) { |
||||
resolve(null, err.response); |
||||
} else { |
||||
resolve(null, res); |
||||
} |
||||
}); |
||||
}); |
||||
|
||||
Meteor.methods({ |
||||
outgoingWebhooks(integration, description, params) { |
||||
check(integration, Object); |
||||
check(description, String); |
||||
check(params, Object); |
||||
|
||||
const quoteParams = _.clone(params); |
||||
['card', 'list', 'oldList', 'board', 'comment'].forEach((key) => { |
||||
if (quoteParams[key]) quoteParams[key] = `"${params[key]}"`; |
||||
}); |
||||
|
||||
const user = Users.findOne(integration.userId); |
||||
const text = `${params.user} ${TAPi18n.__(description, quoteParams, user.getLanguage())}\n${params.url}`; |
||||
|
||||
if (text.length === 0) return; |
||||
|
||||
const value = { |
||||
text: `${text}`, |
||||
}; |
||||
|
||||
const options = { |
||||
headers: { |
||||
// 'Content-Type': 'application/json',
|
||||
// 'X-Wekan-Activities-Token': 'Random.Id()',
|
||||
}, |
||||
data: value, |
||||
}; |
||||
|
||||
const response = postCatchError(integration.url, options); |
||||
|
||||
if (response && response.statusCode && response.statusCode === 200) { |
||||
return true; // eslint-disable-line consistent-return
|
||||
} else { |
||||
throw new Meteor.Error('error-invalid-webhook-response'); |
||||
} |
||||
}, |
||||
}); |
Loading…
Reference in new issue