From fb8284ca521d21c364d5fff270842481655582ad Mon Sep 17 00:00:00 2001 From: "13621160019@163.com" <13621160019@163.com> Date: Fri, 3 Dec 2021 14:16:51 +0800 Subject: [PATCH] added access control to privilege in api and admin --- .../users/privilege/privilege.controller.js | 3 +- myems-api/MyEMS.postman_collection.json | 55 ++++++++++++++++--- myems-api/README.md | 14 ++--- 3 files changed, 56 insertions(+), 16 deletions(-) diff --git a/admin/app/controllers/users/privilege/privilege.controller.js b/admin/app/controllers/users/privilege/privilege.controller.js index 30bfca59..cd2df729 100644 --- a/admin/app/controllers/users/privilege/privilege.controller.js +++ b/admin/app/controllers/users/privilege/privilege.controller.js @@ -1,6 +1,7 @@ 'use strict'; -app.controller('PrivilegeController', function ($scope, +app.controller('PrivilegeController', function ( + $scope, $window, $uibModal, PrivilegeService, diff --git a/myems-api/MyEMS.postman_collection.json b/myems-api/MyEMS.postman_collection.json index e97d0f14..2b93ff88 100644 --- a/myems-api/MyEMS.postman_collection.json +++ b/myems-api/MyEMS.postman_collection.json @@ -4345,19 +4345,32 @@ "name": "PUT Update Privilege Data", "request": { "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": { "mode": "raw", "raw": "{\"data\":{\"name\":\"privilege 1\", \"data\":\"{\\\"spaces\\\":[1, 3]}\"}}" }, "url": { - "raw": "{{base_url}}/privileges/2", + "raw": "{{base_url}}/privileges/1", "host": [ "{{base_url}}" ], "path": [ "privileges", - "2" + "1" ] } }, @@ -4367,25 +4380,51 @@ "name": "DELETE Privilege", "request": { "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": { - "raw": "{{base_url}}/privileges/2", + "raw": "{{base_url}}/privileges/1", "host": [ "{{base_url}}" ], "path": [ "privileges", - "2" + "1" ] } }, "response": [] }, { - "name": "Create Privilege", + "name": "POST Create Privilege", "request": { "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": { "mode": "raw", "raw": "{\"data\": {\"name\": \"privilege 1\", \"data\":\"{\\\"spaces\\\":[1, 3]}\"}}" diff --git a/myems-api/README.md b/myems-api/README.md index aa28f3dc..915199ae 100644 --- a/myems-api/README.md +++ b/myems-api/README.md @@ -1229,15 +1229,15 @@ curl -i -X GET {{base_url}}/points ``` * DELETE Point by ID ```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 -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 -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 @@ -1253,11 +1253,11 @@ curl -i -X GET {{base_url}}/privileges ```bash 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 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 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} ```