Merge branch 'develop'

pull/92/MERGE
13621160019@163.com 2021-12-05 18:08:16 +08:00
commit 150791963f
18 changed files with 480 additions and 161 deletions

9
admin/Dockerfile vendored
View File

@ -1,9 +1,12 @@
FROM nginx:1.21.1 FROM nginx:1.21.1
# remove the config # remove the default config
RUN rm /etc/nginx/conf.d/default.conf && \ RUN rm /etc/nginx/conf.d/default.conf && \
rm /etc/nginx/nginx.conf && \ rm /etc/nginx/nginx.conf
mkdir -p /var/www/html/admin
# create new root folder
# todo: share upload folder in admin with myems-api container on Docker
RUN mkdir -p /var/www/html/admin
# copy the config and web codes # copy the config and web codes
COPY nginx.conf /etc/nginx/ COPY nginx.conf /etc/nginx/

View File

@ -1,6 +1,15 @@
'use strict'; 'use strict';
app.controller('WebMessageController', function($scope, $timeout, $translate, $uibModal, WebMessageAnalysisService, toaster, SweetAlert) { app.controller('WebMessageController', function(
$scope,
$window,
$timeout,
$translate,
$uibModal,
WebMessageAnalysisService,
toaster,
SweetAlert) {
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user"));
$scope.$on('handleBroadcastWebMessageOptionChanged', function (event, data) { $scope.$on('handleBroadcastWebMessageOptionChanged', function (event, data) {
if (angular.isDefined(data.load)) { if (angular.isDefined(data.load)) {
$scope.tabledata = []; $scope.tabledata = [];
@ -32,7 +41,8 @@ app.controller('WebMessageController', function($scope, $timeout, $translate, $u
modalInstance.result.then(function(modifiedWebmessage) { modalInstance.result.then(function(modifiedWebmessage) {
modifiedWebmessage.status = "acknowledged"; modifiedWebmessage.status = "acknowledged";
WebMessageAnalysisService.editWebMessage(modifiedWebmessage, function (response) { let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
WebMessageAnalysisService.editWebMessage(modifiedWebmessage, 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",
@ -70,7 +80,8 @@ app.controller('WebMessageController', function($scope, $timeout, $translate, $u
}, },
function(isConfirm) { function(isConfirm) {
if (isConfirm) { if (isConfirm) {
WebMessageAnalysisService.deleteWebMessage(webmessage, function (response) { let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
WebMessageAnalysisService.deleteWebMessage(webmessage, 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",

View File

@ -1,7 +1,11 @@
'use strict'; 'use strict';
app.controller('WebMessageOptionController', function($scope, $timeout, app.controller('WebMessageOptionController', function(
$scope,
$window,
$timeout,
WebMessageAnalysisService) { WebMessageAnalysisService) {
$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()
@ -36,7 +40,8 @@ app.controller('WebMessageOptionController', function($scope, $timeout,
load: true, load: true,
period:$scope.currentPeriod period:$scope.currentPeriod
}); });
WebMessageAnalysisService.getAnalysisResult(query, function (response) { let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
WebMessageAnalysisService.getAnalysisResult(query, headers, function (response) {
if (angular.isDefined(response.status) && response.status === 200) { if (angular.isDefined(response.status) && response.status === 200) {
$scope.$emit('handleEmitWebMessageOptionChanged', response.data); $scope.$emit('handleEmitWebMessageOptionChanged', response.data);
} }

View File

@ -200,11 +200,14 @@ app.controller('LoginController', function (
// web message alarm section start // web message alarm section start
$scope.webmessages = []; $scope.webmessages = [];
$scope.getWebMessage = function () { $scope.getWebMessage = function () {
WebMessageAnalysisService.getStatusNewResult(function (response) { if ($scope.cur_user != null && $scope.cur_user.uuid != null && $scope.cur_user.token != null) {
if (angular.isDefined(response.status) && response.status === 200) { let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
$scope.webmessages = response.data; WebMessageAnalysisService.getStatusNewResult(headers, function (response) {
} if (angular.isDefined(response.status) && response.status === 200) {
}); $scope.webmessages = response.data;
}
});
}
}; };
// web message alarm section end // web message alarm section end

View File

@ -2,10 +2,8 @@
app.factory('WebMessageAnalysisService', function($http) { app.factory('WebMessageAnalysisService', function($http) {
return { return {
getAnalysisResult: function(query,callback) { getAnalysisResult: function(query, headers, callback) {
var base="webmessages"; $http.get(getAPI()+"webmessages"+"/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,9 +11,8 @@ app.factory('WebMessageAnalysisService', function($http) {
}); });
}, },
getStatusNewResult: function(callback) { getStatusNewResult: function(headers, callback) {
var base="webmessagesnew"; $http.get(getAPI()+"webmessagesnew", {headers})
$http.get(getAPI()+base)
.then(function (response) { .then(function (response) {
callback(response); callback(response);
}, function (response) { }, function (response) {
@ -23,8 +20,8 @@ app.factory('WebMessageAnalysisService', function($http) {
}); });
}, },
editWebMessage: function(webmessage, callback) { editWebMessage: function(webmessage, headers, callback) {
$http.put(getAPI()+'webmessages/'+webmessage.id, {data:webmessage}) $http.put(getAPI()+'webmessages/'+webmessage.id, {data:webmessage}, {headers})
.then(function (response) { .then(function (response) {
callback(response); callback(response);
}, function (response) { }, function (response) {
@ -32,8 +29,8 @@ app.factory('WebMessageAnalysisService', function($http) {
}); });
}, },
deleteWebMessage: function(webmessage, callback) { deleteWebMessage: function(webmessage, headers, callback) {
$http.delete(getAPI()+'webmessages/'+webmessage.id) $http.delete(getAPI()+'webmessages/'+webmessage.id, {headers})
.then(function (response) { .then(function (response) {
callback(response); callback(response);
}, function (response) { }, function (response) {

View File

@ -30,7 +30,6 @@
<thead> <thead>
<tr> <tr>
<th class="text-center">{{'FDD.ID' | translate}}</th> <th class="text-center">{{'FDD.ID' | translate}}</th>
<th class="text-center">{{'FDD.RECIPIENT_NAME' | translate}}</th>
<th class="text-center">{{'FDD.TOPIC' | translate}}</th> <th class="text-center">{{'FDD.TOPIC' | translate}}</th>
<th data-sort-ignore="true" class="text-center">{{'FDD.ALARM_MESSAGE' | translate}}</th> <th data-sort-ignore="true" class="text-center">{{'FDD.ALARM_MESSAGE' | translate}}</th>
<th class="text-center">{{'FDD.ALARM_TIME' | translate}}</th> <th class="text-center">{{'FDD.ALARM_TIME' | translate}}</th>
@ -42,7 +41,6 @@
<tbody> <tbody>
<tr ng-repeat="row in tabledata track by $index"> <tr ng-repeat="row in tabledata track by $index">
<td class="text-center sm">{{ row.id }}</td> <td class="text-center sm">{{ row.id }}</td>
<td class="text-center sm">{{ row.user_display_name }}</td>
<td class="text-center sm">{{ row.subject }}</td> <td class="text-center sm">{{ row.subject }}</td>
<td class="text-center sm col-lg-3 col-md-3" title="{{row.message}}">{{ row.message.slice(0,50) }} <td class="text-center sm col-lg-3 col-md-3" title="{{row.message}}">{{ row.message.slice(0,50) }}
<small ng-show="{{row.message.length > 50 }}">...</small> <small ng-show="{{row.message.length > 50 }}">...</small>

View File

@ -4,14 +4,6 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form role="form" name="form_webmessage" novalidate class="form-horizontal"> <form role="form" name="form_webmessage" novalidate class="form-horizontal">
<div class="form-group"><label class="col-sm-4 control-label">{{'FDD.RECIPIENT_NAME' | translate}}</label>
<div class="col-sm-8"><input ng-model="webmessage.user_display_name" type="text" name="webmessagename" class="form-control" disabled required="">
<div class="m-t-xs" ng-show="form_webmessage.webmessagename.$invalid && form_webmessage.webmessagename.$dirty">
<small class="text-danger" ng-show="form_webmessage.webmessagename.$error.required">{{'SETTING.NOT_NULLABLE' | translate}}</small>
</div>
</div>
</div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<div class="form-group"><label class="col-sm-4 control-label">{{'FDD.TOPIC' | translate}}</label> <div class="form-group"><label class="col-sm-4 control-label">{{'FDD.TOPIC' | translate}}</label>

View File

@ -1,6 +1,9 @@
FROM python:3.9.6 FROM python:3.9.6
WORKDIR /code WORKDIR /code
# todo: share upload folder with admin container on Docker
RUN mkdir -p /var/www/html/admin/upload
COPY . /code COPY . /code
RUN pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com RUN pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
EXPOSE 8000 EXPOSE 8000

View File

@ -910,7 +910,7 @@
}, },
{ {
"key": "Token", "key": "Token",
"value": "6ab593bb7e48f22da551572b444b2095b02f7fd717681215c16866b18846c9e0c7c9a10b612d26e262d2100223197a3804daec0ace179623dcb3d3e0a3213dbe", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"description": "Login to get a valid token", "description": "Login to get a valid token",
"type": "text" "type": "text"
} }
@ -940,7 +940,7 @@
}, },
{ {
"key": "Token", "key": "Token",
"value": "6ab593bb7e48f22da551572b444b2095b02f7fd717681215c16866b18846c9e0c7c9a10b612d26e262d2100223197a3804daec0ace179623dcb3d3e0a3213dbe", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"description": "Login to get a valid token", "description": "Login to get a valid token",
"type": "text" "type": "text"
} }
@ -966,12 +966,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": "6b0622f8974b2e6f2d7a7470baf073b78bddffd4", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"type": "text" "type": "text",
"description": "Login to get a valid token"
} }
], ],
"body": { "body": {
@ -980,7 +982,7 @@
{ {
"key": "file", "key": "file",
"type": "file", "type": "file",
"src": "/zh/myems/myems-doc/offlinemeters.xlsx" "src": "/D:/myems/myems/myems-normalization/offline_meter_data.xlsx"
} }
] ]
}, },
@ -1009,7 +1011,7 @@
}, },
{ {
"key": "Token", "key": "Token",
"value": "6ab593bb7e48f22da551572b444b2095b02f7fd717681215c16866b18846c9e0c7c9a10b612d26e262d2100223197a3804daec0ace179623dcb3d3e0a3213dbe", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"description": "Login to get a valid token", "description": "Login to get a valid token",
"type": "text" "type": "text"
} }
@ -1040,19 +1042,19 @@
}, },
{ {
"key": "Token", "key": "Token",
"value": "6ab593bb7e48f22da551572b444b2095b02f7fd717681215c16866b18846c9e0c7c9a10b612d26e262d2100223197a3804daec0ace179623dcb3d3e0a3213dbe", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"description": "Login to get a valid token", "description": "Login to get a valid token",
"type": "text" "type": "text"
} }
], ],
"url": { "url": {
"raw": "{{base_url}}/costfiles/20/restore", "raw": "{{base_url}}/costfiles/2/restore",
"host": [ "host": [
"{{base_url}}" "{{base_url}}"
], ],
"path": [ "path": [
"costfiles", "costfiles",
"20", "2",
"restore" "restore"
] ]
} }
@ -1828,7 +1830,7 @@
}, },
{ {
"key": "Token", "key": "Token",
"value": "592641a558bc1724c4b75bd80d7d37b9b6a441b9b2231e3a5b2843b1f1e4f6864608ca97c4db00c94012b3406bf0c45cf231b789d2f551c1d420aa4de09f75cd", "value": "14f2bb7378e6926c20b54bd48bd8618e4d78ece1f1658c946a7257eaa97d3149ecd6407a62a39f0f3a6ef6b65f19d63894f297ad5a58d7b597a547f8b8e2898c",
"type": "text", "type": "text",
"description": "Login to get a valid token" "description": "Login to get a valid token"
} }
@ -1900,7 +1902,7 @@
}, },
{ {
"key": "Token", "key": "Token",
"value": "592641a558bc1724c4b75bd80d7d37b9b6a441b9b2231e3a5b2843b1f1e4f6864608ca97c4db00c94012b3406bf0c45cf231b789d2f551c1d420aa4de09f75cd", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"type": "text", "type": "text",
"description": "Login to get a valid token" "description": "Login to get a valid token"
} }
@ -3408,7 +3410,7 @@
}, },
{ {
"key": "Token", "key": "Token",
"value": "d2506282920bd7f1fb5db68605324bd7b8c6c305d84dcd43d43edfba6908136c4e468eca553c72f0211b2ad44fedb71c2f5c901816e5de828fa21cfb88a2552e", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"type": "text", "type": "text",
"description": "Login to get a valid token" "description": "Login to get a valid token"
} }
@ -3419,7 +3421,7 @@
{ {
"key": "file", "key": "file",
"type": "file", "type": "file",
"src": "/zh/myems/myems-standards/ISO 50001-2018.pdf" "src": "/D:/myems/myems/myems-normalization/offline_meter_data.xlsx"
} }
] ]
}, },
@ -3448,7 +3450,7 @@
}, },
{ {
"key": "Token", "key": "Token",
"value": "d2506282920bd7f1fb5db68605324bd7b8c6c305d84dcd43d43edfba6908136c4e468eca553c72f0211b2ad44fedb71c2f5c901816e5de828fa21cfb88a2552e", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"description": "Login to get a valid token", "description": "Login to get a valid token",
"type": "text" "type": "text"
} }
@ -3479,7 +3481,7 @@
}, },
{ {
"key": "Token", "key": "Token",
"value": "d2506282920bd7f1fb5db68605324bd7b8c6c305d84dcd43d43edfba6908136c4e468eca553c72f0211b2ad44fedb71c2f5c901816e5de828fa21cfb88a2552e", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"description": "Login to get a valid token", "description": "Login to get a valid token",
"type": "text" "type": "text"
} }
@ -3870,13 +3872,13 @@
{ {
"key": "User-UUID", "key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"description": "Update this value after login", "description": "Any users' UUID",
"type": "text" "type": "text"
}, },
{ {
"key": "Token", "key": "Token",
"value": "02f93023a39c98e1d1bc9f5197a83dfc5ddc0d48", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"description": "Update this value after login", "description": "Login to get a valid token",
"type": "text" "type": "text"
} }
], ],
@ -3915,13 +3917,13 @@
{ {
"key": "User-UUID", "key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"description": "Update this value after login", "description": "Any users' UUID",
"type": "text" "type": "text"
}, },
{ {
"key": "Token", "key": "Token",
"value": "02f93023a39c98e1d1bc9f5197a83dfc5ddc0d48", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"description": "Update this value after login", "description": "Login to get a valid token",
"type": "text" "type": "text"
} }
], ],
@ -3946,13 +3948,13 @@
{ {
"key": "User-UUID", "key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"description": "Update this value after login", "description": "Any users' UUID",
"type": "text" "type": "text"
}, },
{ {
"key": "Token", "key": "Token",
"value": "02f93023a39c98e1d1bc9f5197a83dfc5ddc0d48", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"description": "Update this value after login", "description": "Login to get a valid token",
"type": "text" "type": "text"
} }
], ],
@ -3988,13 +3990,13 @@
{ {
"key": "User-UUID", "key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"description": "Update this value after login", "description": "Any users' UUID",
"type": "text" "type": "text"
}, },
{ {
"key": "Token", "key": "Token",
"value": "02f93023a39c98e1d1bc9f5197a83dfc5ddc0d48", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"description": "Update this value after login", "description": "Login to get a valid token",
"type": "text" "type": "text"
} }
], ],
@ -4130,7 +4132,7 @@
}, },
{ {
"key": "Token", "key": "Token",
"value": "d2506282920bd7f1fb5db68605324bd7b8c6c305d84dcd43d43edfba6908136c4e468eca553c72f0211b2ad44fedb71c2f5c901816e5de828fa21cfb88a2552e", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"description": "Login to get a valid token", "description": "Login to get a valid token",
"type": "text" "type": "text"
} }
@ -4160,7 +4162,7 @@
}, },
{ {
"key": "Token", "key": "Token",
"value": "d2506282920bd7f1fb5db68605324bd7b8c6c305d84dcd43d43edfba6908136c4e468eca553c72f0211b2ad44fedb71c2f5c901816e5de828fa21cfb88a2552e", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"type": "text", "type": "text",
"description": "Login to get a valid token" "description": "Login to get a valid token"
} }
@ -4186,12 +4188,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": "6b0622f8974b2e6f2d7a7470baf073b78bddffd4", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"type": "text" "type": "text",
"description": "Login to get a valid token"
} }
], ],
"body": { "body": {
@ -4200,7 +4204,7 @@
{ {
"key": "file", "key": "file",
"type": "file", "type": "file",
"src": "/zh/myems/myems-doc/offlinemeters.xlsx" "src": "/D:/myems/myems/myems-normalization/offline_meter_data.xlsx"
} }
] ]
}, },
@ -4229,7 +4233,7 @@
}, },
{ {
"key": "Token", "key": "Token",
"value": "d2506282920bd7f1fb5db68605324bd7b8c6c305d84dcd43d43edfba6908136c4e468eca553c72f0211b2ad44fedb71c2f5c901816e5de828fa21cfb88a2552e", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"type": "text", "type": "text",
"description": "Login to get a valid token" "description": "Login to get a valid token"
} }
@ -4260,7 +4264,7 @@
}, },
{ {
"key": "Token", "key": "Token",
"value": "d2506282920bd7f1fb5db68605324bd7b8c6c305d84dcd43d43edfba6908136c4e468eca553c72f0211b2ad44fedb71c2f5c901816e5de828fa21cfb88a2552e", "value": "aad10e8cd48a3b8719860fed577033098cbc6caeb1454986189b0018bb76c6abc3a0b0600d0bec2fefb2c9cc5147aab23f50c4a4c8a64aaad0b7e4a7054905b8",
"type": "text", "type": "text",
"description": "Login to get a valid token" "description": "Login to get a valid token"
} }
@ -7389,7 +7393,7 @@
}, },
{ {
"key": "Token", "key": "Token",
"value": "14f2bb7378e6926c20b54bd48bd8618e4d78ece1f1658c946a7257eaa97d3149ecd6407a62a39f0f3a6ef6b65f19d63894f297ad5a58d7b597a547f8b8e2898c", "value": "24bb236244f26784fb1397344d926b4871e87a90096eae926a0e448396dbd3ff4a2f70f727089f025238cb47bdbccdc877ef4a50fad8f05a4e5100c5d3eb0d3c",
"type": "text", "type": "text",
"description": "Login to get a valid token" "description": "Login to get a valid token"
} }
@ -8046,21 +8050,34 @@
"name": "Web Message", "name": "Web Message",
"item": [ "item": [
{ {
"name": "GET Web Messages from Startdate to Enddate", "name": "GET Web 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": "24bb236244f26784fb1397344d926b4871e87a90096eae926a0e448396dbd3ff4a2f70f727089f025238cb47bdbccdc877ef4a50fad8f05a4e5100c5d3eb0d3c",
"type": "text",
"description": "Login to get a valid token"
}
],
"url": { "url": {
"raw": "{{base_url}}/webmessages/from/2020-04-01/to/2020-05-01", "raw": "{{base_url}}/webmessages/from/2021-12-01/to/2021-12-31",
"host": [ "host": [
"{{base_url}}" "{{base_url}}"
], ],
"path": [ "path": [
"webmessages", "webmessages",
"from", "from",
"2020-04-01", "2021-12-01",
"to", "to",
"2020-05-01" "2021-12-31"
], ],
"query": [ "query": [
{ {
@ -8077,7 +8094,20 @@
"name": "GET All New Web Messages", "name": "GET All New Web Messages",
"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": "24bb236244f26784fb1397344d926b4871e87a90096eae926a0e448396dbd3ff4a2f70f727089f025238cb47bdbccdc877ef4a50fad8f05a4e5100c5d3eb0d3c",
"type": "text",
"description": "Login to get a valid token"
}
],
"url": { "url": {
"raw": "{{base_url}}/webmessagesnew", "raw": "{{base_url}}/webmessagesnew",
"host": [ "host": [
@ -8098,10 +8128,23 @@
"response": [] "response": []
}, },
{ {
"name": "GET an Web Message by ID", "name": "GET a Web 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": "24bb236244f26784fb1397344d926b4871e87a90096eae926a0e448396dbd3ff4a2f70f727089f025238cb47bdbccdc877ef4a50fad8f05a4e5100c5d3eb0d3c",
"type": "text",
"description": "Login to get a valid token"
}
],
"url": { "url": {
"raw": "{{base_url}}/webmessages/1", "raw": "{{base_url}}/webmessages/1",
"host": [ "host": [
@ -8119,7 +8162,20 @@
"name": "POST Create New Web Message TODO", "name": "POST Create New Web 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": "24bb236244f26784fb1397344d926b4871e87a90096eae926a0e448396dbd3ff4a2f70f727089f025238cb47bdbccdc877ef4a50fad8f05a4e5100c5d3eb0d3c",
"type": "text",
"description": "Login to get a valid token"
}
],
"url": { "url": {
"raw": "{{base_url}}/webmessages", "raw": "{{base_url}}/webmessages",
"host": [ "host": [
@ -8133,10 +8189,23 @@
"response": [] "response": []
}, },
{ {
"name": "PUT Update an Web Message", "name": "PUT Update an Web 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": "24bb236244f26784fb1397344d926b4871e87a90096eae926a0e448396dbd3ff4a2f70f727089f025238cb47bdbccdc877ef4a50fad8f05a4e5100c5d3eb0d3c",
"type": "text",
"description": "Login to get a valid token"
}
],
"body": { "body": {
"mode": "raw", "mode": "raw",
"raw": "{\"data\":{\"status\":\"acknowledged\", \"reply\":\"this is my reply\"}}" "raw": "{\"data\":{\"status\":\"acknowledged\", \"reply\":\"this is my reply\"}}"
@ -8155,18 +8224,31 @@
"response": [] "response": []
}, },
{ {
"name": "DELETE an Web Message by ID", "name": "DELETE a Web 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": "24bb236244f26784fb1397344d926b4871e87a90096eae926a0e448396dbd3ff4a2f70f727089f025238cb47bdbccdc877ef4a50fad8f05a4e5100c5d3eb0d3c",
"type": "text",
"description": "Login to get a valid token"
}
],
"url": { "url": {
"raw": "{{base_url}}/webmessages/2", "raw": "{{base_url}}/webmessages/1",
"host": [ "host": [
"{{base_url}}" "{{base_url}}"
], ],
"path": [ "path": [
"webmessages", "webmessages",
"2" "1"
] ]
} }
}, },

View File

@ -2082,15 +2082,15 @@ Result in JSON
| status | string | Status ('new', 'acknowledged', 'timeout') | | status | string | Status ('new', 'acknowledged', 'timeout') |
| reply | string | User's Reply text, allow null | | reply | string | User's Reply text, allow null |
```bash ```bash
curl -i -X GET {{base_url}}/webmessages/{id} curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -X GET {{base_url}}/webmessages/{id}
``` ```
* GET Web Messages from Startdate to Enddate * GET Web Messages from Startdate to Enddate
```bash ```bash
curl -i -X GET {{base_url}}/webmessages/from/{startdate}/to/{enddate} curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -X GET {{base_url}}/webmessages/from/{startdate}/to/{enddate}
``` ```
* GET New Web Messages * GET New Web Messages
```bash ```bash
curl -i -X GET {{base_url}}/webmessagesnew curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -X GET {{base_url}}/webmessagesnew
``` ```
* DELETE a Web Message by ID * DELETE a Web Message by ID
```bash ```bash

View File

@ -1,5 +1,5 @@
import falcon import falcon
import json import simplejson as json
import mysql.connector import mysql.connector
import config import config
import uuid import uuid

View File

@ -1,5 +1,5 @@
import falcon import falcon
import json import simplejson as json
import mysql.connector import mysql.connector
import config import config
import base64 import base64

View File

@ -1,5 +1,5 @@
import falcon import falcon
import json import simplejson as json
import mysql.connector import mysql.connector
import config import config
import uuid import uuid

View File

@ -1,5 +1,5 @@
import falcon import falcon
import json import simplejson as json
import mysql.connector import mysql.connector
import config import config
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone

View File

@ -1,5 +1,5 @@
import falcon import falcon
import json import simplejson as json
import mysql.connector import mysql.connector
import config import config
import uuid import uuid

View File

@ -1,5 +1,5 @@
import falcon import falcon
import json import simplejson as json
import mysql.connector import mysql.connector
import config import config
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
@ -46,35 +46,74 @@ class WebMessageCollection:
raise falcon.HTTPError(falcon.HTTP_400, raise falcon.HTTPError(falcon.HTTP_400,
title='API.BAD_REQUEST', title='API.BAD_REQUEST',
description='API.START_DATETIME_MUST_BE_EARLIER_THAN_END_DATETIME') description='API.START_DATETIME_MUST_BE_EARLIER_THAN_END_DATETIME')
# get user dict
# Verify User Session
token = req.headers.get('TOKEN')
user_uuid = req.headers.get('USER-UUID')
if token is None:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.TOKEN_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN')
if user_uuid is None:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.USER_UUID_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN')
cnx = mysql.connector.connect(**config.myems_user_db) cnx = mysql.connector.connect(**config.myems_user_db)
cursor = cnx.cursor(dictionary=True) cursor = cnx.cursor(dictionary=True)
query = (" SELECT id, display_name " query = (" SELECT utc_expires "
" FROM tbl_users ") " FROM tbl_sessions "
cursor.execute(query) " WHERE user_uuid = %s AND token = %s")
rows_users = cursor.fetchall() cursor.execute(query, (user_uuid, token,))
row = cursor.fetchone()
if row is None:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_SESSION_PLEASE_RE_LOGIN')
else:
utc_expires = row['utc_expires']
if datetime.utcnow() > utc_expires:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.USER_SESSION_TIMEOUT')
cursor.execute(" SELECT id "
" FROM tbl_users "
" WHERE uuid = %s ",
(user_uuid,))
row = cursor.fetchone()
if row is None:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_USER_PLEASE_RE_LOGIN')
else:
user_id = row['id']
if cursor: if cursor:
cursor.close() cursor.close()
if cnx: if cnx:
cnx.disconnect() cnx.disconnect()
user_dict = dict()
if rows_users is not None and len(rows_users) > 0:
for row in rows_users:
user_dict[row['id']] = row['display_name']
# get web messages # get web messages
cnx = mysql.connector.connect(**config.myems_fdd_db) cnx = mysql.connector.connect(**config.myems_fdd_db)
cursor = cnx.cursor() cursor = cnx.cursor()
query = (" SELECT id, user_id, subject, message, " query = (" SELECT id, subject, message, "
" created_datetime_utc, status, reply " " created_datetime_utc, status, reply "
" FROM tbl_web_messages " " FROM tbl_web_messages "
" WHERE created_datetime_utc >= %s AND created_datetime_utc < %s " " WHERE user_id = %s AND "
" created_datetime_utc >= %s AND created_datetime_utc < %s "
" ORDER BY created_datetime_utc DESC ") " ORDER BY created_datetime_utc DESC ")
cursor.execute(query, (start_datetime_utc, end_datetime_utc)) cursor.execute(query, (user_id, start_datetime_utc, end_datetime_utc))
rows = cursor.fetchall() rows = cursor.fetchall()
if cursor: if cursor:
@ -86,13 +125,11 @@ class WebMessageCollection:
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
meta_result = {"id": row[0], meta_result = {"id": row[0],
"user_id": row[1], "subject": row[1],
"user_display_name": user_dict.get(row[1], None), "message": row[2].replace("<br>", ""),
"subject": row[2], "created_datetime": row[3].timestamp() * 1000 if isinstance(row[4], datetime) else None,
"message": row[3].replace("<br>", ""), "status": row[4],
"created_datetime": row[4].timestamp() * 1000 if isinstance(row[4], datetime) else None, "reply": row[5]}
"status": row[5],
"reply": row[6]}
result.append(meta_result) result.append(meta_result)
resp.text = json.dumps(result) resp.text = json.dumps(result)
@ -110,36 +147,74 @@ class WebMessageStatusNewCollection:
@staticmethod @staticmethod
def on_get(req, resp): def on_get(req, resp):
"""Handles GET requests"""
# Verify User Session
token = req.headers.get('TOKEN')
user_uuid = req.headers.get('USER-UUID')
if token is None:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.TOKEN_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN')
if user_uuid is None:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.USER_UUID_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN')
# get user dict
cnx = mysql.connector.connect(**config.myems_user_db) cnx = mysql.connector.connect(**config.myems_user_db)
cursor = cnx.cursor(dictionary=True) cursor = cnx.cursor(dictionary=True)
query = (" SELECT id, display_name " query = (" SELECT utc_expires "
" FROM tbl_users ") " FROM tbl_sessions "
cursor.execute(query) " WHERE user_uuid = %s AND token = %s")
rows_users = cursor.fetchall() cursor.execute(query, (user_uuid, token,))
row = cursor.fetchone()
if row is None:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_SESSION_PLEASE_RE_LOGIN')
else:
utc_expires = row['utc_expires']
if datetime.utcnow() > utc_expires:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.USER_SESSION_TIMEOUT')
cursor.execute(" SELECT id "
" FROM tbl_users "
" WHERE uuid = %s ",
(user_uuid,))
row = cursor.fetchone()
if row is None:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_USER_PLEASE_RE_LOGIN')
else:
user_id = row['id']
if cursor: if cursor:
cursor.close() cursor.close()
if cnx: if cnx:
cnx.disconnect() cnx.disconnect()
user_dict = dict() # get 'new' web messages
if rows_users is not None and len(rows_users) > 0:
for row in rows_users:
user_dict[row['id']] = row['display_name']
# get new web messages
cnx = mysql.connector.connect(**config.myems_fdd_db) cnx = mysql.connector.connect(**config.myems_fdd_db)
cursor = cnx.cursor() cursor = cnx.cursor()
query = (" SELECT id, user_id, subject, message, " query = (" SELECT id, subject, message, "
" created_datetime_utc, status " " created_datetime_utc, status, reply "
" FROM tbl_web_messages " " FROM tbl_web_messages "
" WHERE status = %s " " WHERE user_id = %s AND "
" status = %s "
" ORDER BY created_datetime_utc DESC ") " ORDER BY created_datetime_utc DESC ")
cursor.execute(query, ("new", )) cursor.execute(query, (user_id, 'new'))
rows = cursor.fetchall() rows = cursor.fetchall()
if cursor: if cursor:
@ -151,12 +226,11 @@ class WebMessageStatusNewCollection:
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
meta_result = {"id": row[0], meta_result = {"id": row[0],
"user_id": row[1], "subject": row[1],
"user_display_name": user_dict.get(row[1], None), "message": row[2].replace("<br>", ""),
"subject": row[2], "created_datetime": row[3].timestamp() * 1000 if isinstance(row[4], datetime) else None,
"message": row[3].replace("<br>", ""), "status": row[4],
"created_datetime": row[4].timestamp() * 1000 if isinstance(row[4], datetime) else None, "reply": row[5]}
"status": row[5]}
result.append(meta_result) result.append(meta_result)
resp.text = json.dumps(result) resp.text = json.dumps(result)
@ -179,34 +253,72 @@ class WebMessageItem:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_WEB_MESSAGE_ID') description='API.INVALID_WEB_MESSAGE_ID')
# get user dict # Verify User Session
token = req.headers.get('TOKEN')
user_uuid = req.headers.get('USER-UUID')
if token is None:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.TOKEN_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN')
if user_uuid is None:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.USER_UUID_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN')
cnx = mysql.connector.connect(**config.myems_user_db) cnx = mysql.connector.connect(**config.myems_user_db)
cursor = cnx.cursor(dictionary=True) cursor = cnx.cursor(dictionary=True)
query = (" SELECT id, display_name " query = (" SELECT utc_expires "
" FROM tbl_users ") " FROM tbl_sessions "
cursor.execute(query) " WHERE user_uuid = %s AND token = %s")
rows_users = cursor.fetchall() cursor.execute(query, (user_uuid, token,))
row = cursor.fetchone()
if row is None:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_SESSION_PLEASE_RE_LOGIN')
else:
utc_expires = row['utc_expires']
if datetime.utcnow() > utc_expires:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.USER_SESSION_TIMEOUT')
cursor.execute(" SELECT id "
" FROM tbl_users "
" WHERE uuid = %s ",
(user_uuid,))
row = cursor.fetchone()
if row is None:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_USER_PLEASE_RE_LOGIN')
else:
user_id = row['id']
if cursor: if cursor:
cursor.close() cursor.close()
if cnx: if cnx:
cnx.disconnect() cnx.disconnect()
user_dict = dict() # get web message by id
if rows_users is not None and len(rows_users) > 0:
for row in rows_users:
user_dict[row['id']] = row['display_name']
# get web message
cnx = mysql.connector.connect(**config.myems_fdd_db) cnx = mysql.connector.connect(**config.myems_fdd_db)
cursor = cnx.cursor() cursor = cnx.cursor()
query = (" SELECT id, user_id, subject, message, " query = (" SELECT id, subject, message, "
" created_datetime_utc, status, reply " " created_datetime_utc, status, reply "
" FROM tbl_web_messages " " FROM tbl_web_messages "
" WHERE id = %s ") " WHERE id = %s AND user_id = %s "
cursor.execute(query, (id_,)) " ORDER BY created_datetime_utc DESC ")
cursor.execute(query, (id_, user_id))
row = cursor.fetchone() row = cursor.fetchone()
if cursor: if cursor:
@ -219,13 +331,11 @@ class WebMessageItem:
description='API.WEB_MESSAGE_NOT_FOUND') description='API.WEB_MESSAGE_NOT_FOUND')
meta_result = {"id": row[0], meta_result = {"id": row[0],
"user_id": row[1], "subject": row[1],
"user_display_name": user_dict.get(row[1], None), "message": row[2].replace("<br>", ""),
"subject": row[2], "created_datetime": row[3].timestamp() * 1000 if isinstance(row[4], datetime) else None,
"message": row[3].replace("<br>", ""), "status": row[4],
"created_datetime": row[4].timestamp() * 1000 if isinstance(row[4], datetime) else None, "reply": row[5]}
"status": row[5],
"reply": row[6]}
resp.text = json.dumps(meta_result) resp.text = json.dumps(meta_result)
@ -259,12 +369,68 @@ class WebMessageItem:
description='API.INVALID_REPLY') description='API.INVALID_REPLY')
reply = str.strip(new_values['data']['reply']) reply = str.strip(new_values['data']['reply'])
# Verify User Session
token = req.headers.get('TOKEN')
user_uuid = req.headers.get('USER-UUID')
if token is None:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.TOKEN_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN')
if user_uuid is None:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.USER_UUID_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN')
cnx = mysql.connector.connect(**config.myems_user_db)
cursor = cnx.cursor(dictionary=True)
query = (" SELECT utc_expires "
" FROM tbl_sessions "
" WHERE user_uuid = %s AND token = %s")
cursor.execute(query, (user_uuid, token,))
row = cursor.fetchone()
if row is None:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_SESSION_PLEASE_RE_LOGIN')
else:
utc_expires = row['utc_expires']
if datetime.utcnow() > utc_expires:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.USER_SESSION_TIMEOUT')
cursor.execute(" SELECT id "
" FROM tbl_users "
" WHERE uuid = %s ",
(user_uuid,))
row = cursor.fetchone()
if row is None:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_USER_PLEASE_RE_LOGIN')
else:
user_id = row['id']
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
cnx = mysql.connector.connect(**config.myems_fdd_db) cnx = mysql.connector.connect(**config.myems_fdd_db)
cursor = cnx.cursor() cursor = cnx.cursor()
cursor.execute(" SELECT user_id " cursor.execute(" SELECT user_id "
" FROM tbl_web_messages " " FROM tbl_web_messages "
" WHERE id = %s ", (id_,)) " WHERE id = %s AND user_id = %s ", (id_, user_id))
if cursor.fetchone() is None: if cursor.fetchone() is None:
cursor.close() cursor.close()
cnx.disconnect() cnx.disconnect()
@ -291,12 +457,68 @@ class WebMessageItem:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_WEB_MESSAGE_ID') description='API.INVALID_WEB_MESSAGE_ID')
# Verify User Session
token = req.headers.get('TOKEN')
user_uuid = req.headers.get('USER-UUID')
if token is None:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.TOKEN_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN')
if user_uuid is None:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.USER_UUID_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN')
cnx = mysql.connector.connect(**config.myems_user_db)
cursor = cnx.cursor(dictionary=True)
query = (" SELECT utc_expires "
" FROM tbl_sessions "
" WHERE user_uuid = %s AND token = %s")
cursor.execute(query, (user_uuid, token,))
row = cursor.fetchone()
if row is None:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_SESSION_PLEASE_RE_LOGIN')
else:
utc_expires = row['utc_expires']
if datetime.utcnow() > utc_expires:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.USER_SESSION_TIMEOUT')
cursor.execute(" SELECT id "
" FROM tbl_users "
" WHERE uuid = %s ",
(user_uuid,))
row = cursor.fetchone()
if row is None:
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_USER_PLEASE_RE_LOGIN')
else:
user_id = row['id']
if cursor:
cursor.close()
if cnx:
cnx.disconnect()
cnx = mysql.connector.connect(**config.myems_fdd_db) cnx = mysql.connector.connect(**config.myems_fdd_db)
cursor = cnx.cursor() cursor = cnx.cursor()
cursor.execute(" SELECT id " cursor.execute(" SELECT id "
" FROM tbl_web_messages " " FROM tbl_web_messages "
" WHERE id = %s ", (id_,)) " WHERE id = %s AND user_id = %s ", (id_, user_id))
row = cursor.fetchone() row = cursor.fetchone()
if row is None: if row is None:

View File

@ -76,6 +76,7 @@ WORKING_DAY_START_TIME_LOCAL=00:00:00
# must use the root folder of myems-admin web application # must use the root folder of myems-admin web application
# for example if you serve myems-admin at /var/www/html/admin # for example if you serve myems-admin at /var/www/html/admin
# you should set the upload_path as below # you should set the upload_path as below
# todo: share upload folder with admin container on Docker
UPLOAD_PATH=/var/www/html/admin/upload/ UPLOAD_PATH=/var/www/html/admin/upload/
# main currency unit # main currency unit

6
web/Dockerfile vendored
View File

@ -1,9 +1,11 @@
FROM nginx:1.21.1 FROM nginx:1.21.1
# remove the config # remove the default config
RUN rm /etc/nginx/conf.d/default.conf && \ RUN rm /etc/nginx/conf.d/default.conf && \
rm /etc/nginx/nginx.conf && \ rm /etc/nginx/nginx.conf && \
mkdir -p /var/www/html/web
# create new root folder
RUN mkdir -p /var/www/html/web
# Note: You should run 'npm run build' in the web direction to generate the production build. # Note: You should run 'npm run build' in the web direction to generate the production build.
COPY nginx.conf /etc/nginx/ COPY nginx.conf /etc/nginx/