added access control to sersor in api and admin
parent
b10cc91a3a
commit
3ec50fab0d
|
@ -1,6 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
app.controller('SensorController', function($scope, $window, $translate, $uibModal, SensorService, toaster, SweetAlert) {
|
||||
app.controller('SensorController', function(
|
||||
$scope,
|
||||
$window,
|
||||
$translate,
|
||||
$uibModal,
|
||||
SensorService,
|
||||
toaster,
|
||||
SweetAlert) {
|
||||
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user"));
|
||||
$scope.getAllSensors = function() {
|
||||
SensorService.getAllSensors(function (response) {
|
||||
|
@ -28,8 +35,7 @@ app.controller('SensorController', function($scope, $window, $translate, $uibMo
|
|||
});
|
||||
modalInstance.result.then(function(sensor) {
|
||||
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||
SensorService.addSensor(sensor, {headers},
|
||||
function (response) {
|
||||
SensorService.addSensor(sensor, headers, function (response) {
|
||||
if (angular.isDefined(response.status) && response.status === 201) {
|
||||
toaster.pop({
|
||||
type: "success",
|
||||
|
@ -70,7 +76,7 @@ app.controller('SensorController', function($scope, $window, $translate, $uibMo
|
|||
|
||||
modalInstance.result.then(function(modifiedSensor) {
|
||||
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||
SensorService.editSensor(modifiedSensor, {headers}, function (response) {
|
||||
SensorService.editSensor(modifiedSensor, headers, function (response) {
|
||||
if (angular.isDefined(response.status) && response.status === 200) {
|
||||
toaster.pop({
|
||||
type: "success",
|
||||
|
@ -109,7 +115,7 @@ app.controller('SensorController', function($scope, $window, $translate, $uibMo
|
|||
function(isConfirm) {
|
||||
if (isConfirm) {
|
||||
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||
SensorService.deleteSensor(sensor, {headers}, function (response) {
|
||||
SensorService.deleteSensor(sensor, headers, function (response) {
|
||||
if (angular.isDefined(response.status) && response.status === 204) {
|
||||
toaster.pop({
|
||||
type: "success",
|
||||
|
|
|
@ -81,7 +81,7 @@ app.controller('SensorPointController', function (
|
|||
var pointid = angular.element('#' + dragEl).scope().point.id;
|
||||
var sensorid = $scope.currentSensor.id;
|
||||
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||
SensorPointService.addPair(sensorid, pointid, {headers}, function (response) {
|
||||
SensorPointService.addPair(sensorid, pointid, headers, function (response) {
|
||||
if (angular.isDefined(response.status) && response.status === 201) {
|
||||
toaster.pop({
|
||||
type: "success",
|
||||
|
@ -108,7 +108,7 @@ app.controller('SensorPointController', function (
|
|||
var sensorpointid = angular.element('#' + dragEl).scope().sensorpoint.id;
|
||||
var sensorid = $scope.currentSensor.id;
|
||||
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||
SensorPointService.deletePair(sensorid, sensorpointid, {headers}, function (response) {
|
||||
SensorPointService.deletePair(sensorid, sensorpointid, headers, function (response) {
|
||||
if (angular.isDefined(response.status) && response.status === 204) {
|
||||
toaster.pop({
|
||||
type: "success",
|
||||
|
|
|
@ -4647,7 +4647,18 @@
|
|||
"name": "POST Create New Sensor",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"header": [
|
||||
{
|
||||
"key": "User-UUID",
|
||||
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"key": "Token",
|
||||
"value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\"data\":{\"name\":\"Sensor10\", \"description\":\"sensor description\"}}"
|
||||
|
@ -4668,19 +4679,30 @@
|
|||
"name": "PUT Update a Sensor",
|
||||
"request": {
|
||||
"method": "PUT",
|
||||
"header": [],
|
||||
"header": [
|
||||
{
|
||||
"key": "User-UUID",
|
||||
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"key": "Token",
|
||||
"value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\"data\":{\"name\":\"Sensor10\", \"description\":\"sensor description\"}}"
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{base_url}}/sensors/5",
|
||||
"raw": "{{base_url}}/sensors/3",
|
||||
"host": [
|
||||
"{{base_url}}"
|
||||
],
|
||||
"path": [
|
||||
"sensors",
|
||||
"5"
|
||||
"3"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -4690,28 +4712,50 @@
|
|||
"name": "DELETE Sensor by ID",
|
||||
"request": {
|
||||
"method": "DELETE",
|
||||
"header": [],
|
||||
"header": [
|
||||
{
|
||||
"key": "User-UUID",
|
||||
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"key": "Token",
|
||||
"value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"url": {
|
||||
"raw": "{{base_url}}/sensors/2",
|
||||
"raw": "{{base_url}}/sensors/3",
|
||||
"host": [
|
||||
"{{base_url}}"
|
||||
],
|
||||
"path": [
|
||||
"sensors",
|
||||
"2"
|
||||
"3"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "POST Sensor Point Relation",
|
||||
"name": "POST Bind Point to Sensor",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"header": [
|
||||
{
|
||||
"key": "User-UUID",
|
||||
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"key": "Token",
|
||||
"value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\"data\":{\"point_id\":\"2686\"}}"
|
||||
"raw": "{\"data\":{\"point_id\":\"2\"}}"
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{base_url}}/sensors/1/points",
|
||||
|
@ -4728,7 +4772,7 @@
|
|||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "GET All Points associated with Sensor ID",
|
||||
"name": "GET All Points associated with Sensor by ID",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
|
@ -4747,12 +4791,23 @@
|
|||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "DELETE Sensor Point Relation",
|
||||
"name": "DELETE Unbind Point from Sensor",
|
||||
"request": {
|
||||
"method": "DELETE",
|
||||
"header": [],
|
||||
"header": [
|
||||
{
|
||||
"key": "User-UUID",
|
||||
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"key": "Token",
|
||||
"value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"url": {
|
||||
"raw": "{{base_url}}/sensors/1/points/2686",
|
||||
"raw": "{{base_url}}/sensors/1/points/2",
|
||||
"host": [
|
||||
"{{base_url}}"
|
||||
],
|
||||
|
@ -4760,7 +4815,7 @@
|
|||
"sensors",
|
||||
"1",
|
||||
"points",
|
||||
"2686"
|
||||
"2"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1321,10 +1321,6 @@ Result
|
|||
```bash
|
||||
curl -i -X GET {{base_url}}/sensors
|
||||
```
|
||||
* DELETE a Sensor by ID
|
||||
```bash
|
||||
curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -X DELETE {{base_url}}/sensors/{id}
|
||||
```
|
||||
* POST Create New Sensor
|
||||
```bash
|
||||
curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -H "Content-Type: application/json" -X POST -d '{"data":{"name":"Sensor10", "description":"sensor description"}}' {{base_url}}/sensors
|
||||
|
@ -1333,15 +1329,19 @@ curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKE
|
|||
```bash
|
||||
curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -H "Content-Type: application/json" -X PUT -d '{"data":{"name":"Sensor10", "description":"sensor description"}}' {{base_url}}/sensors/{id}
|
||||
```
|
||||
* GET All Points associated with Sensor ID
|
||||
* DELETE Sensor by ID
|
||||
```bash
|
||||
curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -X DELETE {{base_url}}/sensors/{id}
|
||||
```
|
||||
* POST Bind Point to Sensor
|
||||
```bash
|
||||
curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -H "Content-Type: application/json" -X POST -d '{"data":{"point_id":"2"}}' {{base_url}}/sensors/{id}/points
|
||||
```
|
||||
* GET All Points associated with Sensor by ID
|
||||
```bash
|
||||
curl -i -X GET {{base_url}}/sensors/{id}/points
|
||||
```
|
||||
* POST Sensor Point Relation
|
||||
```bash
|
||||
curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -H "Content-Type: application/json" -X POST -d '{"data":{"point_id":"3"}}' {{base_url}}/sensors/{id}/points
|
||||
```
|
||||
* DELETE Sensor Point Relation
|
||||
* DELETE Unbind Point from Sensor
|
||||
```bash
|
||||
curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -X DELETE {{base_url}}/sensors/{id}/points/{pid}
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue