fix(xo-server/subjects/addToArraySet): dont erase previous values (#5269)

Prior to this change, adding a value to an existing set that already contains
that value would replace the whole set with a new one containing only that
value.
This commit is contained in:
Pierre Donias 2020-09-21 12:14:50 +02:00 committed by GitHub
parent 626e2fcb12
commit 3a0cc0d6f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import createLogger from '@xen-orchestra/log'
import { filter, includes } from 'lodash'
import { filter } from 'lodash'
import { ignoreErrors } from 'promise-toolbox'
import { hash, needsRehash, verify } from 'hashy'
import { invalidCredentials, noSuchObject } from 'xo-common/api-errors'
@ -14,7 +14,7 @@ import { forEach, isEmpty, lightSet, mapToArray } from '../utils'
const log = createLogger('xo:xo-mixins:subjects')
const addToArraySet = (set, value) =>
set && !includes(set, value) ? set.concat(value) : [value]
set !== undefined ? (set.includes(value) ? set : set.concat(value)) : [value]
const removeFromArraySet = (set, value) =>
set && filter(set, current => current !== value)