fix bug on taking control of a device: set a lock for exclusive access (#650)

* fix bug on taking control of a device: set a lock for exclusive access

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>

* update the locking function

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>

---------

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>
This commit is contained in:
Denis Barbaron
2023-04-03 20:05:49 +02:00
committed by GitHub
parent 1997a7615f
commit 51b86a87ef
3 changed files with 51 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
/**
* Copyright © 2019 code initially contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
* Copyright © 2019,2023 code initially contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
const apiutil = require('./apiutil')
@@ -60,7 +60,9 @@ lockutil.unlockGroupAndDevice = function(lock) {
}
lockutil.lockGenericDevice = function(req, res, lock, lockDevice) {
return lockDevice(req.user.groups.subscribed, req.swagger.params.serial.value)
return lockDevice(req.user.groups.subscribed,
req.hasOwnProperty('body') ? req.body.serial : req.swagger.params.serial.value)
.then(function(stats) {
return apiutil.computeStats(res, stats, 'device', lock)
})