Merge branch 'develop'

pull/80/head
13621160019@163.com 2021-11-18 22:52:35 +08:00
commit faa10dfbb7
4 changed files with 94 additions and 34 deletions

View File

@ -1,18 +1,19 @@
'use strict'; 'use strict';
app.controller('CostFileController', function ( app.controller('CostFileController', function (
$scope, $scope,
$window, $window,
$translate, $translate,
$interval, $interval,
CostFileService, CostFileService,
toaster, toaster,
SweetAlert) { SweetAlert) {
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user")); $scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user"));
$scope.getAllCostFiles = function () { $scope.getAllCostFiles = function () {
CostFileService.getAllCostFiles(function (response) { let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
CostFileService.getAllCostFiles(headers, function (response) {
if (angular.isDefined(response.status) && response.status === 200) { if (angular.isDefined(response.status) && response.status === 200) {
$scope.costfiles = response.data; $scope.costfiles = response.data;
} else { } else {
@ -53,7 +54,8 @@ app.controller('CostFileController', function (
}; };
$scope.restoreCostFile = function (costfile) { $scope.restoreCostFile = function (costfile) {
CostFileService.restoreCostFile(costfile, function (response) { let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
CostFileService.restoreCostFile(costfile, 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",
@ -87,7 +89,8 @@ app.controller('CostFileController', function (
}, },
function (isConfirm) { function (isConfirm) {
if (isConfirm) { if (isConfirm) {
CostFileService.deleteCostFile(costfile, function (response) { let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
CostFileService.deleteCostFile(costfile, 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,38 +1,38 @@
'use strict'; 'use strict';
app.factory('CostFileService', function($http) { app.factory('CostFileService', function($http) {
return { return {
getAllCostFiles:function(callback){ getAllCostFiles:function(headers, callback){
$http.get(getAPI()+'costfiles') $http.get(getAPI()+'costfiles', {headers})
.then(function (response) { .then(function (response) {
callback(response); callback(response);
}, function (response) { }, function (response) {
callback(response); callback(response);
}); });
}, },
addCostFile: function(costfile, callback) { addCostFile: function(costfile, headers, callback) {
$http.post(getAPI()+'costfiles',{data:costfile}) $http.post(getAPI()+'costfiles', {data:costfile}, {headers})
.then(function (response) {
callback(response);
}, function (response) {
callback(response);
});
},
restoreCostFile: function (costfile, callback) {
$http.get(getAPI() + 'costfiles/' + costfile.id + '/restore')
.then(function (response) { .then(function (response) {
callback(response); callback(response);
}, function (response) { }, function (response) {
callback(response); callback(response);
}); });
}, },
deleteCostFile: function(costfile, callback) { restoreCostFile: function (costfile, headers, callback) {
$http.delete(getAPI()+'costfiles/'+costfile.id) $http.get(getAPI() + 'costfiles/' + costfile.id + '/restore', {headers})
.then(function (response) { .then(function (response) {
callback(response); callback(response);
}, function (response) { }, function (response) {
callback(response); callback(response);
}); });
},
deleteCostFile: function(costfile, headers, callback) {
$http.delete(getAPI()+'costfiles/' + costfile.id, {headers})
.then(function (response) {
callback(response);
}, function (response) {
callback(response);
});
} }
}; };
}); });

View File

@ -853,7 +853,20 @@
"name": "GET All Cost Files", "name": "GET All Cost Files",
"request": { "request": {
"method": "GET", "method": "GET",
"header": [], "header": [
{
"key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"description": "Any admin users' UUID",
"type": "text"
},
{
"key": "Token",
"value": "6ab593bb7e48f22da551572b444b2095b02f7fd717681215c16866b18846c9e0c7c9a10b612d26e262d2100223197a3804daec0ace179623dcb3d3e0a3213dbe",
"description": "Login to get a valid token",
"type": "text"
}
],
"url": { "url": {
"raw": "{{base_url}}/costfiles", "raw": "{{base_url}}/costfiles",
"host": [ "host": [
@ -870,7 +883,20 @@
"name": "GET a Cost File by ID", "name": "GET a Cost File by ID",
"request": { "request": {
"method": "GET", "method": "GET",
"header": [], "header": [
{
"key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"description": "Any admin users' UUID",
"type": "text"
},
{
"key": "Token",
"value": "6ab593bb7e48f22da551572b444b2095b02f7fd717681215c16866b18846c9e0c7c9a10b612d26e262d2100223197a3804daec0ace179623dcb3d3e0a3213dbe",
"description": "Login to get a valid token",
"type": "text"
}
],
"url": { "url": {
"raw": "{{base_url}}/costfiles/1", "raw": "{{base_url}}/costfiles/1",
"host": [ "host": [
@ -926,7 +952,20 @@
"name": "DELETE a Cost File by ID", "name": "DELETE a Cost File by ID",
"request": { "request": {
"method": "DELETE", "method": "DELETE",
"header": [], "header": [
{
"key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"description": "Any admin users' UUID",
"type": "text"
},
{
"key": "Token",
"value": "6ab593bb7e48f22da551572b444b2095b02f7fd717681215c16866b18846c9e0c7c9a10b612d26e262d2100223197a3804daec0ace179623dcb3d3e0a3213dbe",
"description": "Login to get a valid token",
"type": "text"
}
],
"url": { "url": {
"raw": "{{base_url}}/costfiles/1", "raw": "{{base_url}}/costfiles/1",
"host": [ "host": [
@ -944,15 +983,28 @@
"name": "Rstore a Cost File by ID", "name": "Rstore a Cost File by ID",
"request": { "request": {
"method": "GET", "method": "GET",
"header": [], "header": [
{
"key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4",
"description": "Any admin users' UUID",
"type": "text"
},
{
"key": "Token",
"value": "6ab593bb7e48f22da551572b444b2095b02f7fd717681215c16866b18846c9e0c7c9a10b612d26e262d2100223197a3804daec0ace179623dcb3d3e0a3213dbe",
"description": "Login to get a valid token",
"type": "text"
}
],
"url": { "url": {
"raw": "{{base_url}}/costfiles/1/restore", "raw": "{{base_url}}/costfiles/20/restore",
"host": [ "host": [
"{{base_url}}" "{{base_url}}"
], ],
"path": [ "path": [
"costfiles", "costfiles",
"1", "20",
"restore" "restore"
] ]
} }

View File

@ -5,7 +5,7 @@ import config
import uuid import uuid
from datetime import datetime, timezone, timedelta from datetime import datetime, timezone, timedelta
import os import os
from core.useractivity import user_logger from core.useractivity import user_logger, access_control
class CostFileCollection: class CostFileCollection:
@ -20,6 +20,7 @@ class CostFileCollection:
@staticmethod @staticmethod
def on_get(req, resp): def on_get(req, resp):
access_control(req)
cnx = mysql.connector.connect(**config.myems_historical_db) cnx = mysql.connector.connect(**config.myems_historical_db)
cursor = cnx.cursor() cursor = cnx.cursor()
@ -52,6 +53,7 @@ class CostFileCollection:
@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:
upload = req.get_param('file') upload = req.get_param('file')
# Read upload file as binary # Read upload file as binary
@ -157,6 +159,7 @@ class CostFileItem:
@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, raise falcon.HTTPError(falcon.HTTP_400,
title='API.BAD_REQUEST', title='API.BAD_REQUEST',
@ -191,6 +194,7 @@ class CostFileItem:
@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_COST_FILE_ID') description='API.INVALID_COST_FILE_ID')
@ -241,6 +245,7 @@ class CostFileRestore:
@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_COST_FILE_ID') description='API.INVALID_COST_FILE_ID')