mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-01 19:50:37 +00:00
feat(webhooks): move webhooks from array to object (everything should
really be stored as objects). Add to API routes (see HabitRPG/habitrpg-shared#83a22b8). Note, sorting doesn't work. Meh.
This commit is contained in:
parent
21d6b71d37
commit
6ef838cf1a
4 changed files with 53 additions and 20 deletions
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
// Make user and settings available for everyone through root scope.
|
||||
habitrpg.controller('SettingsCtrl',
|
||||
['$scope', 'User', '$rootScope', '$http', 'ApiUrlService', 'Guide', '$location', '$timeout', 'Notification',
|
||||
function($scope, User, $rootScope, $http, ApiUrlService, Guide, $location, $timeout, Notification) {
|
||||
['$scope', 'User', '$rootScope', '$http', 'ApiUrlService', 'Guide', '$location', '$timeout', 'Notification', 'Shared',
|
||||
function($scope, User, $rootScope, $http, ApiUrlService, Guide, $location, $timeout, Notification, Shared) {
|
||||
|
||||
// FIXME we have this re-declared everywhere, figure which is the canonical version and delete the rest
|
||||
// $scope.auth = function (id, token) {
|
||||
|
|
@ -163,18 +163,21 @@ habitrpg.controller('SettingsCtrl',
|
|||
$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 = '';
|
||||
// ---- Webhooks ------
|
||||
$scope._newWebhook = {url:''};
|
||||
$scope.$watch('user.preferences.webhooks',function(webhooks){
|
||||
$scope.hasWebhooks = _.size(webhooks);
|
||||
})
|
||||
$scope.addWebhook = function(url) {
|
||||
User.user.ops.addWebhook({body:{url:url, id:Shared.uuid()}});
|
||||
$scope._newWebhook.url = '';
|
||||
}
|
||||
$scope.saveWebhook = function(webhook){
|
||||
$scope.saveWebhook = function(id,webhook) {
|
||||
delete webhook._editing;
|
||||
User.set({'preferences.webhooks':User.user.preferences.webhooks});
|
||||
User.user.ops.updateWebhook({params:{id:id}, body:webhook});
|
||||
}
|
||||
$scope.deleteWebhook = function($index){
|
||||
User.user.preferences.webhooks.splice($index, 1);
|
||||
User.set({'preferences.webhooks':User.user.preferences.webhooks});
|
||||
$scope.deleteWebhook = function(id) {
|
||||
User.user.ops.deleteWebhook({params:{id:id}});
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -278,7 +278,7 @@ var UserSchema = new Schema({
|
|||
advancedCollapsed: {type: Boolean, 'default': false},
|
||||
toolbarCollapsed: {type:Boolean, 'default':false},
|
||||
background: String,
|
||||
webhooks: {type:Array, 'default': []}
|
||||
webhooks: {type: Schema.Types.Mixed, 'default': {}}
|
||||
},
|
||||
profile: {
|
||||
blurb: String,
|
||||
|
|
|
|||
|
|
@ -373,6 +373,37 @@ module.exports = (swagger, v2) ->
|
|||
]
|
||||
action: user.inviteFriends
|
||||
|
||||
# Webhooks
|
||||
"/user/webhooks":
|
||||
spec:
|
||||
method: 'POST'
|
||||
description: 'Create a new webhook'
|
||||
parameters: [
|
||||
body '','New Webhook {url:"webhook endpoint (required)", id:"id of webhook (shared.uuid(), optional)", enabled:"whether webhook is enabled (true by default, optional)"}','object'
|
||||
]
|
||||
action: user.addWebhook
|
||||
|
||||
"/user/webhooks/{id}:PUT":
|
||||
spec:
|
||||
path: '/user/webhooks/{id}'
|
||||
method: 'PUT'
|
||||
description: "Edit a webhook"
|
||||
parameters: [
|
||||
path 'id','The id of the webhook to edit','string'
|
||||
body '','New Webhook {url:"webhook endpoint (required)", id:"id of webhook (shared.uuid(), optional)", enabled:"whether webhook is enabled (true by default, optional)"}','object'
|
||||
]
|
||||
action: user.updateWebhook
|
||||
|
||||
"/user/webhooks/{id}:DELETE":
|
||||
spec:
|
||||
path: '/user/webhooks/{id}'
|
||||
method: 'DELETE'
|
||||
description: 'Delete a webhook'
|
||||
parameters: [
|
||||
path 'id','Id of webhook to delete','string'
|
||||
]
|
||||
action: user.deleteWebhook
|
||||
|
||||
# ---------------------------------
|
||||
# Groups
|
||||
# ---------------------------------
|
||||
|
|
|
|||
|
|
@ -155,30 +155,29 @@ script(type='text/ng-template', id='partials/options.settings.api.html')
|
|||
|
||||
h2 Webhooks
|
||||
table.table.table-striped
|
||||
thead(ng-if='user.preferences.webhooks[0]')
|
||||
thead(ng-if='hasWebhooks')
|
||||
tr
|
||||
th Enabled
|
||||
th Webhook URL
|
||||
th
|
||||
tbody
|
||||
tr(ng-repeat='webhook in user.preferences.webhooks')
|
||||
tr(ng-repeat="(id,webhook) in user.preferences.webhooks | orderBy:'sort'")
|
||||
td
|
||||
input(type='checkbox', ng-model='webhook.enabled', ng-change='saveWebhook(webhook)')
|
||||
input(type='checkbox', ng-model='webhook.enabled', ng-change='saveWebhook(id,webhook)')
|
||||
td
|
||||
input.form-control(type='url', ng-model='webhook.url', ng-change='webhook._editing=true', ui-keyup="{13:'saveWebhook(webhook)'}")
|
||||
input.form-control(type='url', ng-model='webhook.url', ng-change='webhook._editing=true', ui-keyup="{13:'saveWebhook(id,webhook)'}")
|
||||
td
|
||||
span.pull-left(ng-show='webhook._editing') *
|
||||
a.checklist-icons(ng-click='deleteWebhook($index)')
|
||||
a.checklist-icons(ng-click='deleteWebhook(id)')
|
||||
span.glyphicon.glyphicon-trash(tooltip=env.t('delete'))
|
||||
tr
|
||||
td(colspan=2)
|
||||
form.form-horizontal(ng-submit='addWebhook(_newWebhook)')
|
||||
form.form-horizontal(ng-submit='addWebhook(_newWebhook.url)')
|
||||
.form-group.col-sm-10
|
||||
input.form-control(type='url', ng-model='_newWebhook', placeholder='Webhook URL')
|
||||
input.form-control(type='url', ng-model='_newWebhook.url', 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