equipment of access_control
parent
b9de4e3c43
commit
0bf0c829d0
|
@ -1,7 +1,15 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
app.controller('EquipmentController', function($scope, $translate, $uibModal, EquipmentService, CostCenterService, toaster,SweetAlert) {
|
app.controller('EquipmentController', function(
|
||||||
|
$scope,
|
||||||
|
$window,
|
||||||
|
$translate,
|
||||||
|
$uibModal,
|
||||||
|
EquipmentService,
|
||||||
|
CostCenterService,
|
||||||
|
toaster,
|
||||||
|
SweetAlert) {
|
||||||
|
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user"));
|
||||||
$scope.getAllEquipments = function() {
|
$scope.getAllEquipments = function() {
|
||||||
EquipmentService.getAllEquipments(function (response) {
|
EquipmentService.getAllEquipments(function (response) {
|
||||||
if (angular.isDefined(response.status) && response.status === 200) {
|
if (angular.isDefined(response.status) && response.status === 200) {
|
||||||
|
@ -36,7 +44,8 @@ app.controller('EquipmentController', function($scope, $translate, $uibModal, Eq
|
||||||
});
|
});
|
||||||
modalInstance.result.then(function(equipment) {
|
modalInstance.result.then(function(equipment) {
|
||||||
equipment.cost_center_id = equipment.cost_center.id;
|
equipment.cost_center_id = equipment.cost_center.id;
|
||||||
EquipmentService.addEquipment(equipment, function (response) {
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||||
|
EquipmentService.addEquipment(equipment, 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",
|
||||||
|
@ -77,7 +86,8 @@ app.controller('EquipmentController', function($scope, $translate, $uibModal, Eq
|
||||||
|
|
||||||
modalInstance.result.then(function(modifiedEquipment) {
|
modalInstance.result.then(function(modifiedEquipment) {
|
||||||
modifiedEquipment.cost_center_id = modifiedEquipment.cost_center.id;
|
modifiedEquipment.cost_center_id = modifiedEquipment.cost_center.id;
|
||||||
EquipmentService.editEquipment(modifiedEquipment, function (response) {
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||||
|
EquipmentService.editEquipment(modifiedEquipment, 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",
|
||||||
|
@ -114,7 +124,8 @@ app.controller('EquipmentController', function($scope, $translate, $uibModal, Eq
|
||||||
closeOnCancel: true },
|
closeOnCancel: true },
|
||||||
function (isConfirm) {
|
function (isConfirm) {
|
||||||
if (isConfirm) {
|
if (isConfirm) {
|
||||||
EquipmentService.deleteEquipment(equipment, function (response) {
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||||
|
EquipmentService.deleteEquipment(equipment, 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",
|
||||||
|
|
|
@ -1,6 +1,19 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
app.controller('EquipmentMeterController', function($scope,$timeout,$uibModal, $translate, MeterService, VirtualMeterService, OfflineMeterService, EquipmentMeterService, EquipmentService, toaster,SweetAlert) {
|
app.controller('EquipmentMeterController', function(
|
||||||
|
$scope,
|
||||||
|
$window,
|
||||||
|
$timeout,
|
||||||
|
$uibModal,
|
||||||
|
$translate,
|
||||||
|
MeterService,
|
||||||
|
VirtualMeterService,
|
||||||
|
OfflineMeterService,
|
||||||
|
EquipmentMeterService,
|
||||||
|
EquipmentService,
|
||||||
|
toaster,
|
||||||
|
SweetAlert) {
|
||||||
|
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user"));
|
||||||
$scope.currentEquipment = {selected:undefined};
|
$scope.currentEquipment = {selected:undefined};
|
||||||
|
|
||||||
$scope.getAllEquipments = function(id) {
|
$scope.getAllEquipments = function(id) {
|
||||||
|
@ -111,7 +124,8 @@ app.controller('EquipmentMeterController', function($scope,$timeout,$uibModal, $
|
||||||
modalInstance.result.then(function (is_output) {
|
modalInstance.result.then(function (is_output) {
|
||||||
var meterid=angular.element('#'+dragEl).scope().meter.id;
|
var meterid=angular.element('#'+dragEl).scope().meter.id;
|
||||||
var equipmentid=$scope.currentEquipment.id;
|
var equipmentid=$scope.currentEquipment.id;
|
||||||
EquipmentMeterService.addPair(equipmentid, meterid, $scope.currentMeterType, is_output, function (response) {
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||||
|
EquipmentMeterService.addPair(equipmentid, meterid, $scope.currentMeterType, is_output, 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",
|
||||||
|
@ -140,7 +154,8 @@ app.controller('EquipmentMeterController', function($scope,$timeout,$uibModal, $
|
||||||
var equipmentmeterid = angular.element('#' + dragEl).scope().equipmentmeter.id;
|
var equipmentmeterid = angular.element('#' + dragEl).scope().equipmentmeter.id;
|
||||||
var equipmentid = $scope.currentEquipment.id;
|
var equipmentid = $scope.currentEquipment.id;
|
||||||
var metertype = angular.element('#' + dragEl).scope().equipmentmeter.metertype;
|
var metertype = angular.element('#' + dragEl).scope().equipmentmeter.metertype;
|
||||||
EquipmentMeterService.deletePair(equipmentid, equipmentmeterid, metertype, function (response) {
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||||
|
EquipmentMeterService.deletePair(equipmentid, equipmentmeterid, metertype, 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",
|
||||||
|
|
|
@ -73,8 +73,8 @@ app.controller('EquipmentParameterController', function(
|
||||||
if (equipmentparameter.denominator_meter != null) {
|
if (equipmentparameter.denominator_meter != null) {
|
||||||
equipmentparameter.denominator_meter_uuid = equipmentparameter.denominator_meter.uuid;
|
equipmentparameter.denominator_meter_uuid = equipmentparameter.denominator_meter.uuid;
|
||||||
}
|
}
|
||||||
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||||
EquipmentParameterService.addEquipmentParameter(equipmentid, equipmentparameter, function (response) {
|
EquipmentParameterService.addEquipmentParameter(equipmentid, equipmentparameter, 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",
|
||||||
|
@ -123,7 +123,8 @@ app.controller('EquipmentParameterController', function(
|
||||||
if (modifiedEquipmentParameter.denominator_meter != null) {
|
if (modifiedEquipmentParameter.denominator_meter != null) {
|
||||||
modifiedEquipmentParameter.denominator_meter_uuid = modifiedEquipmentParameter.denominator_meter.uuid;
|
modifiedEquipmentParameter.denominator_meter_uuid = modifiedEquipmentParameter.denominator_meter.uuid;
|
||||||
}
|
}
|
||||||
EquipmentParameterService.editEquipmentParameter($scope.currentEquipment.id, modifiedEquipmentParameter, function (response) {
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||||
|
EquipmentParameterService.editEquipmentParameter($scope.currentEquipment.id, modifiedEquipmentParameter, 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",
|
||||||
|
@ -160,7 +161,8 @@ app.controller('EquipmentParameterController', function(
|
||||||
},
|
},
|
||||||
function(isConfirm) {
|
function(isConfirm) {
|
||||||
if (isConfirm) {
|
if (isConfirm) {
|
||||||
EquipmentParameterService.deleteEquipmentParameter($scope.currentEquipment.id, equipmentparameter.id, function (response) {
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||||
|
EquipmentParameterService.deleteEquipmentParameter($scope.currentEquipment.id, equipmentparameter.id, 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",
|
||||||
|
|
|
@ -17,24 +17,24 @@ app.factory('EquipmentService', function($http) {
|
||||||
callback(response);
|
callback(response);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
addEquipment: function(equipment, callback) {
|
addEquipment: function(equipment, headers, callback) {
|
||||||
$http.post(getAPI()+'equipments',{data:equipment})
|
$http.post(getAPI()+'equipments',{data:equipment}, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
editEquipment: function(equipment, callback) {
|
editEquipment: function(equipment, headers, callback) {
|
||||||
$http.put(getAPI()+'equipments/'+equipment.id,{data:equipment})
|
$http.put(getAPI()+'equipments/'+equipment.id,{data:equipment}, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
deleteEquipment: function(equipment, callback) {
|
deleteEquipment: function(equipment, headers, callback) {
|
||||||
$http.delete(getAPI()+'equipments/'+equipment.id)
|
$http.delete(getAPI()+'equipments/'+equipment.id, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
app.factory('EquipmentMeterService', function($http) {
|
app.factory('EquipmentMeterService', function($http) {
|
||||||
return {
|
return {
|
||||||
addPair: function(equipmentID,meterID,metertype,is_output,callback) {
|
addPair: function(equipmentID, meterID, metertype, is_output, headers, callback) {
|
||||||
var meter={};
|
var meter={};
|
||||||
if(metertype=='meters'){
|
if(metertype=='meters'){
|
||||||
meter={'meter_id':meterID,is_output:is_output};
|
meter={'meter_id':meterID,is_output:is_output};
|
||||||
|
@ -10,7 +10,7 @@ app.factory('EquipmentMeterService', function($http) {
|
||||||
}else{
|
}else{
|
||||||
meter={'offline_meter_id':meterID,is_output:is_output};
|
meter={'offline_meter_id':meterID,is_output:is_output};
|
||||||
}
|
}
|
||||||
$http.post(getAPI()+'equipments/'+equipmentID+'/'+metertype,{data:meter})
|
$http.post(getAPI()+'equipments/'+equipmentID+'/'+metertype,{data:meter}, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
|
@ -18,8 +18,8 @@ app.factory('EquipmentMeterService', function($http) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
deletePair: function(equipmentID,meterID,metertype, callback) {
|
deletePair: function(equipmentID,meterID,metertype, headers, callback) {
|
||||||
$http.delete(getAPI()+'equipments/'+equipmentID+'/'+metertype+'/'+meterID)
|
$http.delete(getAPI()+'equipments/'+equipmentID+'/'+metertype+'/'+meterID, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
|
|
|
@ -10,16 +10,16 @@ app.factory('EquipmentParameterService', function($http) {
|
||||||
callback(response);
|
callback(response);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
addEquipmentParameter: function(equipmentID, equipmentparameter,callback) {
|
addEquipmentParameter: function(equipmentID, equipmentparameter, headers, callback) {
|
||||||
$http.post(getAPI()+'equipments/'+equipmentID+'/parameters',{data:equipmentparameter})
|
$http.post(getAPI()+'equipments/'+equipmentID+'/parameters',{data:equipmentparameter}, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
editEquipmentParameter: function(equipmentID,equipmentparameter,callback) {
|
editEquipmentParameter: function(equipmentID, equipmentparameter, headers, callback) {
|
||||||
$http.put(getAPI()+'equipments/'+equipmentID+'/parameters/'+equipmentparameter.id,{data:equipmentparameter})
|
$http.put(getAPI()+'equipments/'+equipmentID+'/parameters/'+equipmentparameter.id,{data:equipmentparameter}, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
|
@ -27,8 +27,8 @@ app.factory('EquipmentParameterService', function($http) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteEquipmentParameter: function(equipmentID, parameterID, callback) {
|
deleteEquipmentParameter: function(equipmentID, parameterID, headers, callback) {
|
||||||
$http.delete(getAPI()+'equipments/'+equipmentID+'/parameters/'+parameterID)
|
$http.delete(getAPI()+'equipments/'+equipmentID+'/parameters/'+parameterID, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
import config
|
import config
|
||||||
import uuid
|
import uuid
|
||||||
from core.useractivity import user_logger
|
from core.useractivity import user_logger, access_control
|
||||||
|
|
||||||
|
|
||||||
class EquipmentCollection:
|
class EquipmentCollection:
|
||||||
|
@ -62,6 +62,7 @@ class EquipmentCollection:
|
||||||
@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')
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
@ -205,6 +206,7 @@ class EquipmentItem:
|
||||||
@user_logger
|
@user_logger
|
||||||
@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_EQUIPMENT_ID')
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
@ -293,6 +295,7 @@ class EquipmentItem:
|
||||||
@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)
|
||||||
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_EQUIPMENT_ID')
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
@ -667,6 +670,7 @@ class EquipmentParameterCollection:
|
||||||
@user_logger
|
@user_logger
|
||||||
def on_post(req, resp, id_):
|
def on_post(req, resp, id_):
|
||||||
"""Handles POST requests"""
|
"""Handles POST requests"""
|
||||||
|
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_EQUIPMENT_ID')
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
@ -976,6 +980,7 @@ class EquipmentParameterItem:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@user_logger
|
@user_logger
|
||||||
def on_delete(req, resp, id_, pid):
|
def on_delete(req, resp, id_, pid):
|
||||||
|
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_EQUIPMENT_ID')
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
@ -1024,6 +1029,7 @@ class EquipmentParameterItem:
|
||||||
@user_logger
|
@user_logger
|
||||||
def on_put(req, resp, id_, pid):
|
def on_put(req, resp, id_, pid):
|
||||||
"""Handles PUT requests"""
|
"""Handles PUT requests"""
|
||||||
|
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_EQUIPMENT_ID')
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
@ -1283,6 +1289,7 @@ class EquipmentMeterCollection:
|
||||||
@user_logger
|
@user_logger
|
||||||
def on_post(req, resp, id_):
|
def on_post(req, resp, id_):
|
||||||
"""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')
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
@ -1307,6 +1314,7 @@ class EquipmentMeterCollection:
|
||||||
description='API.INVALID_IS_OUTPUT_VALUE')
|
description='API.INVALID_IS_OUTPUT_VALUE')
|
||||||
is_output = new_values['data']['is_output']
|
is_output = new_values['data']['is_output']
|
||||||
|
|
||||||
|
cnx = mysql.connector.connect(**config.myems_system_db)
|
||||||
cnx = mysql.connector.connect(**config.myems_system_db)
|
cnx = mysql.connector.connect(**config.myems_system_db)
|
||||||
cursor = cnx.cursor()
|
cursor = cnx.cursor()
|
||||||
|
|
||||||
|
@ -1363,6 +1371,7 @@ class EquipmentMeterItem:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@user_logger
|
@user_logger
|
||||||
def on_delete(req, resp, id_, mid):
|
def on_delete(req, resp, id_, mid):
|
||||||
|
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_EQUIPMENT_ID')
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
Loading…
Reference in New Issue