mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-27 08:15:19 +02:00
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:
@@ -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
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user