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 wirerouter = require('../../../wire/router')
@@ -66,7 +66,6 @@ module.exports = function(push, pushdev, channelRouter) {
delete device.channel
delete device.owner
delete device.group.id
delete device.group.lifeTime
return device
}
@@ -117,7 +116,7 @@ module.exports = function(push, pushdev, channelRouter) {
, 'model'
, 'operator'
, 'manufacturer'
, {group: ['id', 'origin', 'originName', 'lifeTime']}
, {group: ['id', 'name', 'origin', 'originName', 'lifeTime', 'owner']}
, {provider: ['name']}
, {network: ['type', 'subtype']}
, {display: ['height', 'width']}
@@ -154,7 +153,9 @@ module.exports = function(push, pushdev, channelRouter) {
data.new_val.network.type !== data.old_val.network.type ||
data.new_val.network.subtype !== data.old_val.network.subtype
) ||
data.new_val.provider.name !== data.old_val.provider.name) {
data.new_val.provider.name !== data.old_val.provider.name ||
data.new_val.group.name !== data.old_val.group.name ||
data.new_val.group.originName !== data.old_val.group.originName) {
sendDeviceChange(data.new_val, data.old_val, 'updated')
}

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 wirerouter = require('../../../wire/router')
@@ -104,6 +104,12 @@ module.exports = function(push, pushdev, channelRouter) {
})
}
function doUpdateDevicesGroupName(group) {
return Promise.map(group.devices, function(serial) {
return dbapi.updateDeviceGroupName(serial, group)
})
}
function doUpdateDevicesCurrentGroup(group, devices) {
return Promise.map(devices, function(serial) {
return dbapi.updateDeviceCurrentGroup(serial, group)
@@ -235,7 +241,7 @@ module.exports = function(push, pushdev, channelRouter) {
.then(function(cursor) {
cursor.each(function(err, data) {
let users, devices, isBecomeActive, isBecomeUnactive, isActive
, isAddedUser, isAddedDevice, isUpdatedDeviceOriginGroup, isChangedDates
, isAddedUser, isAddedDevice, isUpdatedDeviceOriginGroup, isChangedDates, isChangedName
if (err) {
throw err
@@ -281,6 +287,7 @@ module.exports = function(push, pushdev, channelRouter) {
isBecomeActive = isBecomeUnactive = false
isAddedUser = isAddedDevice = false
isUpdatedDeviceOriginGroup = false
isChangedName = false
}
else {
users = _.xor(data.new_val.users, data.old_val.users)
@@ -300,6 +307,7 @@ module.exports = function(push, pushdev, channelRouter) {
data.new_val.ticket !== null &&
(data.old_val.ticket === null ||
data.new_val.ticket.signature !== data.old_val.ticket.signature)
isChangedName = data.old_val.name !== data.new_val.name
if (!isUpdatedDeviceOriginGroup) {
sendGroupChange(
@@ -337,6 +345,9 @@ module.exports = function(push, pushdev, channelRouter) {
else if (users.length) {
return treatGroupUsersChange(data.old_val, users, isActive, isAddedUser)
}
else if (isChangedName) {
return doUpdateDevicesGroupName(data.new_val)
}
return true
})
})