fix: 🐛 target patch with_Aliases field (#2305)

This commit is contained in:
Dharini Jeeva authored and GitHub committed 2024-05-23 10:23:49 -07:00
1 parent 5c8e93f5e9
commit 1c65de4a80
1 file changed
+5 -3
+5 -3
View File
@@ -23,7 +23,7 @@ export default class TargetSerializer extends ApplicationSerializer {
*/
serialize(snapshot) {
let serialized = super.serialize(...arguments);
const { type } = snapshot.record;
const { type, isNew } = snapshot.record;
const hostSourceIDs = snapshot?.adapterOptions?.hostSetIDs;
if (hostSourceIDs) {
serialized = this.serializeWithHostSources(snapshot, hostSourceIDs);
@@ -44,14 +44,16 @@ export default class TargetSerializer extends ApplicationSerializer {
injectedApplicationCredentialSourceIDs,
);
if (serialized?.with_aliases) {
if (isNew && serialized?.with_aliases) {
// API expects scope id along with every alias value
serialized.with_aliases = serialized.with_aliases.map((item) => ({
...item,
scope_id: 'global',
}));
} else {
// This field can't be updated, it is used only during creation time
delete serialized.with_aliases;
}
// Delete session recording related fields from non-SSH targets
if (type !== TYPE_TARGET_SSH) {
delete serialized?.attributes?.storage_bucket_id;