From b9cec8294185b7c070503e010ed85590e16bad38 Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Wed, 26 Feb 2014 19:18:25 +0900 Subject: [PATCH] Make sure we've invited the device when we go to the control page. Refuse to show the control page on failure. --- res/app/components/stf/user/group/group-service.js | 10 ++++++++-- res/app/device-control/device-control-controller.js | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/res/app/components/stf/user/group/group-service.js b/res/app/components/stf/user/group/group-service.js index 06a9adde..99ed270e 100644 --- a/res/app/components/stf/user/group/group-service.js +++ b/res/app/components/stf/user/group/group-service.js @@ -57,7 +57,10 @@ module.exports = function GroupServiceFactory($rootScope, $http, socket, UserSer } }) return tx.promise.then(function(results) { - return results[0].success + if (!results[0].success) { + throw new Error('Device refused to join the group') + } + return results[0].device }) }) } @@ -72,7 +75,10 @@ module.exports = function GroupServiceFactory($rootScope, $http, socket, UserSer } }) return tx.promise.then(function(results) { - return results[0].success + if (!results[0].success) { + throw new Error('Device refused to be kicked from the group') + } + return results[0].device }) }) } diff --git a/res/app/device-control/device-control-controller.js b/res/app/device-control/device-control-controller.js index 09668beb..0aeb10d2 100644 --- a/res/app/device-control/device-control-controller.js +++ b/res/app/device-control/device-control-controller.js @@ -1,11 +1,17 @@ -module.exports = function DeviceControlCtrl($scope, $routeParams, DeviceService, ControlService) { +module.exports = function DeviceControlCtrl($scope, $routeParams, $location, DeviceService, GroupService, ControlService) { $scope.control = null $scope.device = { promise: DeviceService.get($routeParams.serial) + .then(function(device) { + return GroupService.invite(device) + }) .then(function(device) { $scope.device.value = device $scope.control = ControlService.forOne(device, device.channel) return device }) + .catch(function(err) { + $location.path('/') + }) } }