added access control to email message in api and admin

pull/90/head
13621160019@163.com 2021-12-04 19:52:12 +08:00
parent 3ec50fab0d
commit 3e536d503e
6 changed files with 125 additions and 41 deletions

View File

@ -1,9 +1,14 @@
'use strict'; 'use strict';
app.controller('EmailMessageController', function($scope, $timeout,$translate, app.controller('EmailMessageController', function(
$scope,
$window,
$timeout,
$translate,
EmailMessageAnalysisService, EmailMessageAnalysisService,
toaster, SweetAlert) { toaster,
SweetAlert) {
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user"));
$scope.$on('handleBroadcastEmailMessageOptionChanged', function (event, data) { $scope.$on('handleBroadcastEmailMessageOptionChanged', function (event, data) {
if (angular.isDefined(data.load)) { if (angular.isDefined(data.load)) {
$scope.tabledata = []; $scope.tabledata = [];
@ -34,7 +39,8 @@ app.controller('EmailMessageController', function($scope, $timeout,$translate,
}, },
function(isConfirm) { function(isConfirm) {
if (isConfirm) { if (isConfirm) {
EmailMessageAnalysisService.deleteEmailMessage(emailmessage, function(response) { let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
EmailMessageAnalysisService.deleteEmailMessage(emailmessage, 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",
@ -50,11 +56,11 @@ app.controller('EmailMessageController', function($scope, $timeout,$translate,
body: $translate.instant(response.data.description), body: $translate.instant(response.data.description),
showCloseButton: true, showCloseButton: true,
}); });
} }
}); });
} }
}); }
);
}; };
}); });

View File

@ -1,7 +1,11 @@
'use strict'; 'use strict';
app.controller('EmailMessageOptionController', function($scope, $timeout, app.controller('EmailMessageOptionController', function(
$scope,
$window,
$timeout,
EmailMessageAnalysisService) { EmailMessageAnalysisService) {
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user"));
$scope.daterange = { $scope.daterange = {
startDate: moment().subtract(7,'days'), startDate: moment().subtract(7,'days'),
endDate: moment() endDate: moment()
@ -18,17 +22,15 @@ app.controller('EmailMessageOptionController', function($scope, $timeout,
applyLabel: "OK", applyLabel: "OK",
cancelLabel: "Cancel", cancelLabel: "Cancel",
}, },
eventHandlers:{ eventHandlers:{
'apply.daterangepicker':function(ev,picker){ 'apply.daterangepicker':function(ev,picker){
//$scope.execute(); //$scope.execute();
} }
} }
}; };
$scope.execute = function() { $scope.execute = function() {
var datestart,dateend; var datestart, dateend;
var query = { var query = {
datestart: $scope.daterange.startDate.format().slice(0, 10), datestart: $scope.daterange.startDate.format().slice(0, 10),
dateend: $scope.daterange.endDate.format().slice(0, 10) dateend: $scope.daterange.endDate.format().slice(0, 10)
@ -37,8 +39,8 @@ app.controller('EmailMessageOptionController', function($scope, $timeout,
load: true, load: true,
period:$scope.currentPeriod period:$scope.currentPeriod
}); });
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
EmailMessageAnalysisService.getAnalysisResult(query, function(response) { EmailMessageAnalysisService.getAnalysisResult(query, headers, function(response) {
if (angular.isDefined(response.status) && response.status === 200) { if (angular.isDefined(response.status) && response.status === 200) {
$scope.$emit('handleEmitEmailMessageOptionChanged', response.data); $scope.$emit('handleEmitEmailMessageOptionChanged', response.data);
} }

View File

@ -2,10 +2,8 @@
app.factory('EmailMessageAnalysisService', function($http) { app.factory('EmailMessageAnalysisService', function($http) {
return { return {
getAnalysisResult: function(query,callback) { getAnalysisResult: function(query, headers, callback) {
var base="emailmessages"; $http.get(getAPI()+"emailmessages"+"/from/"+query.datestart+"/to/"+query.dateend, {headers})
var url=base+"/from/"+query.datestart+"/to/"+query.dateend;
$http.get(getAPI()+url)
.then(function (response) { .then(function (response) {
callback(response); callback(response);
}, function (response) { }, function (response) {
@ -13,8 +11,8 @@ app.factory('EmailMessageAnalysisService', function($http) {
}); });
}, },
deleteEmailMessage: function(emailmessage, callback) { deleteEmailMessage: function(emailmessage, headers, callback) {
$http.delete(getAPI()+'emailmessages/'+emailmessage.id) $http.delete(getAPI()+'emailmessages/'+emailmessage.id, {headers})
.then(function (response) { .then(function (response) {
callback(response); callback(response);
}, function (response) { }, function (response) {

View File

@ -1816,21 +1816,34 @@
"name": "Email Message", "name": "Email Message",
"item": [ "item": [
{ {
"name": "GET Email Messages from Startdate to Enddate", "name": "GET Email Messages by Date Range",
"request": { "request": {
"method": "GET", "method": "GET",
"header": [], "header": [
{
"key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"type": "text",
"description": "Any admin users' UUID"
},
{
"key": "Token",
"value": "592641a558bc1724c4b75bd80d7d37b9b6a441b9b2231e3a5b2843b1f1e4f6864608ca97c4db00c94012b3406bf0c45cf231b789d2f551c1d420aa4de09f75cd",
"type": "text",
"description": "Login to get a valid token"
}
],
"url": { "url": {
"raw": "{{base_url}}/emailmessages/from/2020-04-01/to/2020-05-01", "raw": "{{base_url}}/emailmessages/from/2021-12-01/to/2021-12-31",
"host": [ "host": [
"{{base_url}}" "{{base_url}}"
], ],
"path": [ "path": [
"emailmessages", "emailmessages",
"from", "from",
"2020-04-01", "2021-12-01",
"to", "to",
"2020-05-01" "2021-12-31"
], ],
"query": [ "query": [
{ {
@ -1847,7 +1860,20 @@
"name": "GET an Email Message by ID", "name": "GET an Email Message by ID",
"request": { "request": {
"method": "GET", "method": "GET",
"header": [], "header": [
{
"key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"type": "text",
"description": "Any admin users' UUID"
},
{
"key": "Token",
"value": "592641a558bc1724c4b75bd80d7d37b9b6a441b9b2231e3a5b2843b1f1e4f6864608ca97c4db00c94012b3406bf0c45cf231b789d2f551c1d420aa4de09f75cd",
"type": "text",
"description": "Login to get a valid token"
}
],
"url": { "url": {
"raw": "{{base_url}}/emailmessages/1", "raw": "{{base_url}}/emailmessages/1",
"host": [ "host": [
@ -1865,7 +1891,20 @@
"name": "POST Create New Email Message TODO", "name": "POST Create New Email Message TODO",
"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": "592641a558bc1724c4b75bd80d7d37b9b6a441b9b2231e3a5b2843b1f1e4f6864608ca97c4db00c94012b3406bf0c45cf231b789d2f551c1d420aa4de09f75cd",
"type": "text",
"description": "Login to get a valid token"
}
],
"url": { "url": {
"raw": "{{base_url}}/emailmessages", "raw": "{{base_url}}/emailmessages",
"host": [ "host": [
@ -1882,7 +1921,20 @@
"name": "PUT Update an Email Message TODO", "name": "PUT Update an Email Message TODO",
"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": "592641a558bc1724c4b75bd80d7d37b9b6a441b9b2231e3a5b2843b1f1e4f6864608ca97c4db00c94012b3406bf0c45cf231b789d2f551c1d420aa4de09f75cd",
"type": "text",
"description": "Login to get a valid token"
}
],
"url": { "url": {
"raw": "" "raw": ""
} }
@ -1893,7 +1945,20 @@
"name": "DELETE an Email Message by ID", "name": "DELETE an Email Message by ID",
"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": "592641a558bc1724c4b75bd80d7d37b9b6a441b9b2231e3a5b2843b1f1e4f6864608ca97c4db00c94012b3406bf0c45cf231b789d2f551c1d420aa4de09f75cd",
"type": "text",
"description": "Login to get a valid token"
}
],
"url": { "url": {
"raw": "{{base_url}}/emailmessages/2", "raw": "{{base_url}}/emailmessages/2",
"host": [ "host": [
@ -4651,12 +4716,14 @@
{ {
"key": "User-UUID", "key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"type": "text" "type": "text",
"description": "Any admin users' UUID"
}, },
{ {
"key": "Token", "key": "Token",
"value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af", "value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af",
"type": "text" "type": "text",
"description": "Login to get a valid token"
} }
], ],
"body": { "body": {
@ -4683,12 +4750,14 @@
{ {
"key": "User-UUID", "key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"type": "text" "type": "text",
"description": "Any admin users' UUID"
}, },
{ {
"key": "Token", "key": "Token",
"value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af", "value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af",
"type": "text" "type": "text",
"description": "Login to get a valid token"
} }
], ],
"body": { "body": {
@ -4716,12 +4785,14 @@
{ {
"key": "User-UUID", "key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"type": "text" "type": "text",
"description": "Any admin users' UUID"
}, },
{ {
"key": "Token", "key": "Token",
"value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af", "value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af",
"type": "text" "type": "text",
"description": "Login to get a valid token"
} }
], ],
"url": { "url": {
@ -4745,12 +4816,14 @@
{ {
"key": "User-UUID", "key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"type": "text" "type": "text",
"description": "Any admin users' UUID"
}, },
{ {
"key": "Token", "key": "Token",
"value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af", "value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af",
"type": "text" "type": "text",
"description": "Login to get a valid token"
} }
], ],
"body": { "body": {
@ -4798,12 +4871,14 @@
{ {
"key": "User-UUID", "key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"type": "text" "type": "text",
"description": "Any admin users' UUID"
}, },
{ {
"key": "Token", "key": "Token",
"value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af", "value": "e713a4845a2f936eef1dca4314e7fad875b898854c56b4c5176d219f5ee19a0831d2ee67c63b17c2f2a49474d090cccb024f98a797d96571bc61027cbe1995af",
"type": "text" "type": "text",
"description": "Login to get a valid token"
} }
], ],
"url": { "url": {

View File

@ -504,11 +504,11 @@ Result in JSON
| status | string | Status ('new', 'sent', 'timeout' | | status | string | Status ('new', 'sent', 'timeout' |
```bash ```bash
curl -i -X GET {{base_url}}/emailmessages/{id} curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -X GET {{base_url}}/emailmessages/{id}
``` ```
* GET Email Messages from Startdate to Enddate * GET Email Messages by Date Range
```bash ```bash
curl -i -X GET {{base_url}}/emailmessages/from/{startdate}/to/{enddate} curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -X GET {{base_url}}/emailmessages/from/{startdate}/to/{enddate}
``` ```
* DELETE an Email Message by ID * DELETE an Email Message by ID
```bash ```bash

View File

@ -3,7 +3,7 @@ import json
import mysql.connector import mysql.connector
import config import config
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from core.useractivity import user_logger from core.useractivity import user_logger, access_control
class EmailMessageCollection: class EmailMessageCollection:
@ -18,6 +18,7 @@ class EmailMessageCollection:
@staticmethod @staticmethod
def on_get(req, resp, startdate, enddate): def on_get(req, resp, startdate, enddate):
access_control(req)
try: try:
start_datetime_local = datetime.strptime(startdate, '%Y-%m-%d') start_datetime_local = datetime.strptime(startdate, '%Y-%m-%d')
except Exception: except Exception:
@ -100,6 +101,7 @@ class EmailMessageItem:
@staticmethod @staticmethod
def on_get(req, resp, id_): def on_get(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_EMAIL_MESSAGE_ID') description='API.INVALID_EMAIL_MESSAGE_ID')
@ -149,6 +151,7 @@ class EmailMessageItem:
@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_EMAIL_MESSAGE_ID') description='API.INVALID_EMAIL_MESSAGE_ID')