Allow group name change (#795)

* fix bug on email separator

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

* allow group name change

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
2024-07-15 17:03:33 +02:00
committed by GitHub
parent 875730886d
commit cf56911e9f
8 changed files with 99 additions and 21 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-2024 code initially contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
const _ = require('lodash')
@@ -782,6 +782,35 @@ function updateGroup(req, res) {
const stop = new Date(req.body.stopTime || group.dates[0].stop)
let state, isActive
if (group.state !== apiutil.PENDING) {
// only name can be updated
state = typeof req.body.state === 'undefined' ? group.state : req.body.state
if (start.toISOString() !== group.dates[0].start.toISOString() ||
stop.toISOString() !== group.dates[0].stop.toISOString() ||
state !== group.state ||
_class !== group.class ||
repetitions !== group.repetitions) {
return apiutil.respond(res, 403, 'Forbidden (only name can be updated)')
}
if (name === group.name) {
return apiutil.respond(res, 200, 'Unchanged (group)', {group: {}})
}
return dbapi.updateGroup(group.id, {
name: name
})
.then(function(updatedGroup) {
if (updatedGroup) {
apiutil.respond(res, 200, 'Updated (group)', {group: apiutil.publishGroup(updatedGroup)})
}
else {
throw new Error(`Group not found: ${group.id}`)
}
})
}
if (apiutil.isOriginGroup(_class)) {
state = apiutil.READY
isActive = true
@@ -808,7 +837,8 @@ function updateGroup(req, res) {
repetitions === group.repetitions) {
return apiutil.respond(res, 200, 'Unchanged (group)', {group: {}})
}
const duration = group.devices.length * (stop - start) * (repetitions + 1)
const duration = apiutil.isOriginGroup(_class) ?
0 : group.devices.length * (stop - start) * (repetitions + 1)
const dates = apiutil.computeGroupDates({start: start, stop: stop}, _class, repetitions)
if (start < group.dates[0].start ||