Merge branch 'develop'
commit
d6c5d964dd
|
@ -1,11 +1,14 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
app.controller('PrivilegeController', function ($scope,
|
app.controller('PrivilegeController', function (
|
||||||
|
$scope,
|
||||||
|
$window,
|
||||||
$uibModal,
|
$uibModal,
|
||||||
PrivilegeService,
|
PrivilegeService,
|
||||||
toaster,
|
toaster,
|
||||||
$translate,
|
$translate,
|
||||||
SweetAlert) {
|
SweetAlert) {
|
||||||
|
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user"));
|
||||||
$scope.getAllPrivileges = function () {
|
$scope.getAllPrivileges = function () {
|
||||||
PrivilegeService.getAllPrivileges(function (response) {
|
PrivilegeService.getAllPrivileges(function (response) {
|
||||||
if (angular.isDefined(response.status) && response.status === 200) {
|
if (angular.isDefined(response.status) && response.status === 200) {
|
||||||
|
@ -31,7 +34,8 @@ app.controller('PrivilegeController', function ($scope,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
modalInstance.result.then(function (privilege) {
|
modalInstance.result.then(function (privilege) {
|
||||||
PrivilegeService.addPrivilege(privilege, function (response) {
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||||
|
PrivilegeService.addPrivilege(privilege, headers, function (response) {
|
||||||
if (angular.isDefined(response.status) && response.status === 201) {
|
if (angular.isDefined(response.status) && response.status === 201) {
|
||||||
toaster.pop({
|
toaster.pop({
|
||||||
type: "success",
|
type: "success",
|
||||||
|
@ -70,7 +74,8 @@ app.controller('PrivilegeController', function ($scope,
|
||||||
});
|
});
|
||||||
|
|
||||||
modalInstance.result.then(function (modifiedPrivilege) {
|
modalInstance.result.then(function (modifiedPrivilege) {
|
||||||
PrivilegeService.editPrivilege(modifiedPrivilege, function (response) {
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||||
|
PrivilegeService.editPrivilege(modifiedPrivilege, headers, function (response) {
|
||||||
if (angular.isDefined(response.status) && response.status === 200) {
|
if (angular.isDefined(response.status) && response.status === 200) {
|
||||||
toaster.pop({
|
toaster.pop({
|
||||||
type: "success",
|
type: "success",
|
||||||
|
@ -107,7 +112,8 @@ app.controller('PrivilegeController', function ($scope,
|
||||||
},
|
},
|
||||||
function (isConfirm) {
|
function (isConfirm) {
|
||||||
if (isConfirm) {
|
if (isConfirm) {
|
||||||
PrivilegeService.deletePrivilege(privilege, function (response) {
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||||
|
PrivilegeService.deletePrivilege(privilege, headers, function (response) {
|
||||||
if (angular.isDefined(response.status) && response.status === 204) {
|
if (angular.isDefined(response.status) && response.status === 204) {
|
||||||
toaster.pop({
|
toaster.pop({
|
||||||
type: "success",
|
type: "success",
|
||||||
|
|
|
@ -9,24 +9,24 @@ app.factory('PrivilegeService', function($http) {
|
||||||
callback(response);
|
callback(response);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
addPrivilege: function(privilege, callback) {
|
addPrivilege: function(privilege, headers, callback) {
|
||||||
$http.post(getAPI()+'privileges',{data:privilege})
|
$http.post(getAPI()+'privileges', {data:privilege}, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
editPrivilege: function(privilege, callback) {
|
editPrivilege: function(privilege, headers, callback) {
|
||||||
$http.put(getAPI()+'privileges/'+privilege.id,{data:privilege})
|
$http.put(getAPI()+'privileges/'+privilege.id, {data:privilege}, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
deletePrivilege: function(privilege, callback) {
|
deletePrivilege: function(privilege, headers, callback) {
|
||||||
$http.delete(getAPI()+'privileges/'+privilege.id)
|
$http.delete(getAPI()+'privileges/'+privilege.id, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
|
|
|
@ -4345,19 +4345,32 @@
|
||||||
"name": "PUT Update Privilege Data",
|
"name": "PUT Update Privilege Data",
|
||||||
"request": {
|
"request": {
|
||||||
"method": "PUT",
|
"method": "PUT",
|
||||||
"header": [],
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "User-UUID",
|
||||||
|
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
|
||||||
|
"type": "text",
|
||||||
|
"description": "Any admin users' UUID"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Token",
|
||||||
|
"value": "46a767c678fc3d1bcacda116c639ebac77dd1a8407956a0f244a7900dc9c9bf88bb0c8be668d4962bb98f0108ebfeda603a4a6cd0c2031c6a9e864d8052e279e",
|
||||||
|
"type": "text",
|
||||||
|
"description": "Login to get a valid token"
|
||||||
|
}
|
||||||
|
],
|
||||||
"body": {
|
"body": {
|
||||||
"mode": "raw",
|
"mode": "raw",
|
||||||
"raw": "{\"data\":{\"name\":\"privilege 1\", \"data\":\"{\\\"spaces\\\":[1, 3]}\"}}"
|
"raw": "{\"data\":{\"name\":\"privilege 1\", \"data\":\"{\\\"spaces\\\":[1, 3]}\"}}"
|
||||||
},
|
},
|
||||||
"url": {
|
"url": {
|
||||||
"raw": "{{base_url}}/privileges/2",
|
"raw": "{{base_url}}/privileges/1",
|
||||||
"host": [
|
"host": [
|
||||||
"{{base_url}}"
|
"{{base_url}}"
|
||||||
],
|
],
|
||||||
"path": [
|
"path": [
|
||||||
"privileges",
|
"privileges",
|
||||||
"2"
|
"1"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -4367,25 +4380,51 @@
|
||||||
"name": "DELETE Privilege",
|
"name": "DELETE Privilege",
|
||||||
"request": {
|
"request": {
|
||||||
"method": "DELETE",
|
"method": "DELETE",
|
||||||
"header": [],
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "User-UUID",
|
||||||
|
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
|
||||||
|
"type": "text",
|
||||||
|
"description": "Any admin users' UUID"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Token",
|
||||||
|
"value": "46a767c678fc3d1bcacda116c639ebac77dd1a8407956a0f244a7900dc9c9bf88bb0c8be668d4962bb98f0108ebfeda603a4a6cd0c2031c6a9e864d8052e279e",
|
||||||
|
"type": "text",
|
||||||
|
"description": "Login to get a valid token"
|
||||||
|
}
|
||||||
|
],
|
||||||
"url": {
|
"url": {
|
||||||
"raw": "{{base_url}}/privileges/2",
|
"raw": "{{base_url}}/privileges/1",
|
||||||
"host": [
|
"host": [
|
||||||
"{{base_url}}"
|
"{{base_url}}"
|
||||||
],
|
],
|
||||||
"path": [
|
"path": [
|
||||||
"privileges",
|
"privileges",
|
||||||
"2"
|
"1"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Create Privilege",
|
"name": "POST Create Privilege",
|
||||||
"request": {
|
"request": {
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"header": [],
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "User-UUID",
|
||||||
|
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
|
||||||
|
"type": "text",
|
||||||
|
"description": "Any admin users' UUID"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Token",
|
||||||
|
"value": "46a767c678fc3d1bcacda116c639ebac77dd1a8407956a0f244a7900dc9c9bf88bb0c8be668d4962bb98f0108ebfeda603a4a6cd0c2031c6a9e864d8052e279e",
|
||||||
|
"type": "text",
|
||||||
|
"description": "Login to get a valid token"
|
||||||
|
}
|
||||||
|
],
|
||||||
"body": {
|
"body": {
|
||||||
"mode": "raw",
|
"mode": "raw",
|
||||||
"raw": "{\"data\": {\"name\": \"privilege 1\", \"data\":\"{\\\"spaces\\\":[1, 3]}\"}}"
|
"raw": "{\"data\": {\"name\": \"privilege 1\", \"data\":\"{\\\"spaces\\\":[1, 3]}\"}}"
|
||||||
|
|
|
@ -1229,15 +1229,15 @@ curl -i -X GET {{base_url}}/points
|
||||||
```
|
```
|
||||||
* DELETE Point by ID
|
* DELETE Point by ID
|
||||||
```bash
|
```bash
|
||||||
curl -i -X DELETE {{base_url}}/points/{id}
|
curl -i -H "User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4" -H "Token: GET-TOKEN-AFTER-LOGIN" -X DELETE {{base_url}}/points/{id}
|
||||||
```
|
```
|
||||||
* POST Point
|
* POST Create Point
|
||||||
```bash
|
```bash
|
||||||
curl -i -H "Content-Type: application/json" -X POST -d '{"data":{"name":"ModbusPoint1", "data_source_id":1, "object_type": "ENERGY_VALUE", "units":"kWh", "low_limit":0, "high_limit":999999999, "is_trend":true, "is_virtual":false, "address":"{\"slave_id\":1, \"function_code\":3, \"offset\":1, \"number_of_registers\":2, \"data_format\":\"float\"}", "description":null}}' {{base_url}}/points
|
curl -i -H "User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4" -H "Token: GET-TOKEN-AFTER-LOGIN" -H "Content-Type: application/json" -X POST -d '{"data":{"name":"ModbusPoint1", "data_source_id":1, "object_type": "ENERGY_VALUE", "units":"kWh", "low_limit":0, "high_limit":999999999, "is_trend":true, "is_virtual":false, "address":"{\"slave_id\":1, \"function_code\":3, \"offset\":1, \"number_of_registers\":2, \"data_format\":\"float\"}", "description":null}}' {{base_url}}/points
|
||||||
```
|
```
|
||||||
* PUT Point
|
* PUT Update Point
|
||||||
```bash
|
```bash
|
||||||
curl -i -H "Content-Type: application/json" -X PUT -d '{"data":{"name":"ModbusPoint1", "data_source_id":1, "object_type": "ENERGY_VALUE", "units":"kWh", "low_limit":0, "high_limit":999999999, "is_trend":true, "is_virtual":false, "address":"{\"slave_id\":1, \"function_code\":3, \"offset\":1, \"number_of_registers\":2, \"data_format\":\"float\"}", "description":null}}' {{base_url}}/points/{id}
|
curl -i -H "User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4" -H "Token: GET-TOKEN-AFTER-LOGIN" -H "Content-Type: application/json" -X PUT -d '{"data":{"name":"ModbusPoint1", "data_source_id":1, "object_type": "ENERGY_VALUE", "units":"kWh", "low_limit":0, "high_limit":999999999, "is_trend":true, "is_virtual":false, "address":"{\"slave_id\":1, \"function_code\":3, \"offset\":1, \"number_of_registers\":2, \"data_format\":\"float\"}", "description":null}}' {{base_url}}/points/{id}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Privilege
|
### Privilege
|
||||||
|
@ -1251,15 +1251,15 @@ curl -i -X GET {{base_url}}/privileges
|
||||||
```
|
```
|
||||||
* DELETE Privilege by ID
|
* DELETE Privilege by ID
|
||||||
```bash
|
```bash
|
||||||
curl -i -X DELETE {{base_url}}/privileges/{id}
|
curl -i -H "User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4" -H "Token: GET-TOKEN-AFTER-LOGIN" -X DELETE {{base_url}}/privileges/{id}
|
||||||
```
|
```
|
||||||
* POST New Privilege
|
* POST Create New Privilege
|
||||||
```bash
|
```bash
|
||||||
curl -i -H "Content-Type: application/json" -X POST -d '{"data":{"name":"superusers","data":"{\"spaces\":[1,2,3,5]}"}}' {{base_url}}/privileges
|
curl -i -H "Content-Type: application/json" -H "User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4" -H "Token: GET-TOKEN-AFTER-LOGIN" -X POST -d '{"data":{"name":"superusers","data":"{\"spaces\":[1,2,3,5]}"}}' {{base_url}}/privileges
|
||||||
```
|
```
|
||||||
* PUT Privilege
|
* PUT Update Privilege
|
||||||
```bash
|
```bash
|
||||||
curl -i -H "Content-Type: application/json" -X PUT -d '{"data":{"name":"superusers", "data":"{\"spaces\":[1, 3]}"}}' {{base_url}}/privileges/{id}
|
curl -i -H "Content-Type: application/json" -H "User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4" -H "Token: GET-TOKEN-AFTER-LOGIN" -X PUT -d '{"data":{"name":"superusers", "data":"{\"spaces\":[1, 3]}"}}' {{base_url}}/privileges/{id}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Rule
|
### Rule
|
||||||
|
|
|
@ -2,7 +2,7 @@ import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
import config
|
import config
|
||||||
from core.useractivity import user_logger
|
from core.useractivity import user_logger, access_control
|
||||||
|
|
||||||
|
|
||||||
class PrivilegeCollection:
|
class PrivilegeCollection:
|
||||||
|
@ -42,6 +42,7 @@ class PrivilegeCollection:
|
||||||
@user_logger
|
@user_logger
|
||||||
def on_post(req, resp):
|
def on_post(req, resp):
|
||||||
"""Handles POST requests"""
|
"""Handles POST requests"""
|
||||||
|
access_control(req)
|
||||||
try:
|
try:
|
||||||
raw_json = req.stream.read().decode('utf-8')
|
raw_json = req.stream.read().decode('utf-8')
|
||||||
new_values = json.loads(raw_json)
|
new_values = json.loads(raw_json)
|
||||||
|
@ -101,6 +102,7 @@ class PrivilegeItem:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@user_logger
|
@user_logger
|
||||||
def on_delete(req, resp, id_):
|
def on_delete(req, resp, id_):
|
||||||
|
access_control(req)
|
||||||
if not id_.isdigit() or int(id_) <= 0:
|
if not id_.isdigit() or int(id_) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_PRIVILEGE_ID')
|
description='API.INVALID_PRIVILEGE_ID')
|
||||||
|
@ -142,6 +144,7 @@ class PrivilegeItem:
|
||||||
@user_logger
|
@user_logger
|
||||||
def on_put(req, resp, id_):
|
def on_put(req, resp, id_):
|
||||||
"""Handles PUT requests"""
|
"""Handles PUT requests"""
|
||||||
|
access_control(req)
|
||||||
try:
|
try:
|
||||||
raw_json = req.stream.read().decode('utf-8')
|
raw_json = req.stream.read().decode('utf-8')
|
||||||
new_values = json.loads(raw_json)
|
new_values = json.loads(raw_json)
|
||||||
|
|
Loading…
Reference in New Issue