Files
threshold-ui/addons/api/addon/serializers/managed-group.js
T

56 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import ApplicationSerializer from './application';
import {
TYPE_AUTH_METHOD_OIDC,
TYPE_AUTH_METHOD_LDAP,
} from 'api/models/auth-method';
2021-11-11 17:58:08 -05:00
export default class ManagedGroupSerializer extends ApplicationSerializer {
// =properties
/**
* @type {boolean}
*/
serializeScopeID = false;
2021-11-11 17:58:08 -05:00
/**
* Delegates to a type-specific serialization, or default.
* @override
* @param {Snapshot} snapshot
* @return {object}
2021-11-11 17:58:08 -05:00
*/
2022-12-02 13:44:11 -05:00
serialize(snapshot) {
switch (snapshot.record.type) {
case TYPE_AUTH_METHOD_OIDC:
return this.serializeOIDC(...arguments);
case TYPE_AUTH_METHOD_LDAP:
default:
return super.serialize(...arguments);
}
}
2022-12-02 13:44:11 -05:00
serializeOIDC() {
const serialized = super.serialize(...arguments);
2022-12-02 13:44:11 -05:00
if (serialized.attributes.filter_string !== undefined) {
serialized.attributes.filter = serialized.attributes.filter_string;
}
delete serialized.attributes.filter_string;
return serialized;
}
normalize(typeClass, hash, ...rest) {
const normalizedHash = structuredClone(hash);
2022-12-02 13:44:11 -05:00
if (normalizedHash?.attributes?.filter) {
normalizedHash.attributes.filter_string =
normalizedHash.attributes.filter;
delete normalizedHash.attributes.filter;
}
return super.normalize(typeClass, normalizedHash, ...rest);
}
2021-11-11 17:58:08 -05:00
}