mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-03 08:21:07 +00:00
Merge branch 'webhooks' into develop
Conflicts: src/controllers/user.js
This commit is contained in:
commit
21d6b71d37
4 changed files with 54 additions and 1 deletions
|
|
@ -162,5 +162,19 @@ habitrpg.controller('SettingsCtrl',
|
|||
User.user.ops.release2({});
|
||||
$rootScope.$state.go('tasks');
|
||||
}
|
||||
|
||||
//FIXME push this all to habitrpg-shared so we have API routes for this
|
||||
$scope.addWebhook = function(webhook) {
|
||||
User.set({'preferences.webhooks':User.user.preferences.webhooks.concat({url:webhook, enabled:true})});
|
||||
$scope._newWebhook = '';
|
||||
}
|
||||
$scope.saveWebhook = function(webhook){
|
||||
delete webhook._editing;
|
||||
User.set({'preferences.webhooks':User.user.preferences.webhooks});
|
||||
}
|
||||
$scope.deleteWebhook = function($index){
|
||||
User.user.preferences.webhooks.splice($index, 1);
|
||||
User.set({'preferences.webhooks':User.user.preferences.webhooks});
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ var logging = require('./../logging');
|
|||
var acceptablePUTPaths;
|
||||
var api = module.exports;
|
||||
var qs = require('qs');
|
||||
var request = require('request');
|
||||
|
||||
// api.purchase // Shared.ops
|
||||
|
||||
|
|
@ -108,6 +109,15 @@ api.score = function(req, res, next) {
|
|||
_tmp: user._tmp
|
||||
}, saved.toJSON().stats));
|
||||
|
||||
// Webhooks
|
||||
_.each(user.preferences.webhooks, function(h){
|
||||
request.post({
|
||||
url: h.url,
|
||||
//form: {task: task, delta: delta, user: _.pick(user, ['stats', '_tmp'])} // this is causing "Maximum Call Stack Exceeded"
|
||||
body: {direction:direction, task: task, delta: delta, user: _.pick(user, ['_id', 'stats', '_tmp'])}, json:true
|
||||
});
|
||||
});
|
||||
|
||||
if (
|
||||
(!task.challenge || !task.challenge.id || task.challenge.broken) // If it's a challenge task, sync the score. Do it in the background, we've already sent down a response and the user doesn't care what happens back there
|
||||
|| (task.type == 'reward') // we don't want to update the reward GP cost
|
||||
|
|
|
|||
|
|
@ -277,7 +277,8 @@ var UserSchema = new Schema({
|
|||
tagsCollapsed: {type: Boolean, 'default': false},
|
||||
advancedCollapsed: {type: Boolean, 'default': false},
|
||||
toolbarCollapsed: {type:Boolean, 'default':false},
|
||||
background: String
|
||||
background: String,
|
||||
webhooks: {type:Array, 'default': []}
|
||||
},
|
||||
profile: {
|
||||
blurb: String,
|
||||
|
|
|
|||
|
|
@ -151,6 +151,34 @@ script(type='text/ng-template', id='partials/options.settings.api.html')
|
|||
h6=env.t('qrCode')
|
||||
img(src='https://chart.googleapis.com/chart?cht=qr&chs=200x200&chl=%7B%22address%22%3A%22https%3A%2F%2Fhabitrpg.com%22%2C%22user%22%3A%22{{user.id}}%22%2C%22key%22%3A%22{{user.apiToken}}%22%7D&choe=UTF-8&chld=L', alt='qrcode')
|
||||
|
||||
hr
|
||||
|
||||
h2 Webhooks
|
||||
table.table.table-striped
|
||||
thead(ng-if='user.preferences.webhooks[0]')
|
||||
tr
|
||||
th Enabled
|
||||
th Webhook URL
|
||||
th
|
||||
tbody
|
||||
tr(ng-repeat='webhook in user.preferences.webhooks')
|
||||
td
|
||||
input(type='checkbox', ng-model='webhook.enabled', ng-change='saveWebhook(webhook)')
|
||||
td
|
||||
input.form-control(type='url', ng-model='webhook.url', ng-change='webhook._editing=true', ui-keyup="{13:'saveWebhook(webhook)'}")
|
||||
td
|
||||
span.pull-left(ng-show='webhook._editing') *
|
||||
a.checklist-icons(ng-click='deleteWebhook($index)')
|
||||
span.glyphicon.glyphicon-trash(tooltip=env.t('delete'))
|
||||
tr
|
||||
td(colspan=2)
|
||||
form.form-horizontal(ng-submit='addWebhook(_newWebhook)')
|
||||
.form-group.col-sm-10
|
||||
input.form-control(type='url', ng-model='_newWebhook', placeholder='Webhook URL')
|
||||
.col-sm-2
|
||||
button.btn.btn-sm.btn-primary(type='submit') Add
|
||||
|
||||
|
||||
script(id='partials/options.settings.export.html', type="text/ng-template")
|
||||
.container-fluid
|
||||
.row
|
||||
|
|
|
|||
Loading…
Reference in a new issue