[ICU-10024] feat: Revise auth-method model (#1762)

* feat: 🎸 Revised auth-method model

Revised auth-method model to include LDAP attributes

✅ Closes: ICU-10024

* chore: 🤖 create transform for `account_attribute_maps`

Create transform to handle `account_attribute_maps` array

* refactor: 💡 Refactor transform and serializer

Refactor `account_claims_map` transforms overall name and logic to be
used for `account_attributes_map`.  Also refactored serializer to
serialize auth-method data, by type.

✅ Closes: ICU-100024

* refactor: 💡 refactor transform

Refactor `account_claim_maps` transform.

* Update addons/api/addon/serializers/auth-method.js

changing naming of serialize method

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>

* refactor: 💡 refactor serializer

Refactor naming convention for serializer methods and added comments for
attributes.

* refactor: 💡 quick refactor

fixed name for method call in serializer

* refactor: 💡 refactor attributes and serializer

Refactor attributes for `auth-methods` to use the `for` option to select
which attribute belongs to which auth-method.

* Update auth-method.js

comment change

* refactor: 💡 rebase

rebase

* Update addons/api/addon/serializers/auth-method.js

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>

* Update addons/api/addon/serializers/auth-method.js

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>

* Update addons/api/addon/serializers/auth-method.js

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>

* Update addons/api/addon/serializers/auth-method.js

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>

* Update addons/api/addon/serializers/auth-method.js

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>

* refactor: 💡 refactor serialize attribute method

refactor serialize attribute method not not include type for password,
and instead let `serializePassword` handle serialization

* refactor: 💡 refactor serializer

Refcator serializer to not include password type in attribute serializer
and added `for` to one missing attribute.

* Update addons/api/addon/serializers/auth-method.js

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>

---------

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>
This commit is contained in:
Devon AndersonandDharini Jeeva authored and GitHub committed 2023-07-13 09:19:38 -04:00
1 parent 5bf50eba79
commit d7b6eba2af
7 files changed
+253 -46

No files matched your search

+23 -8
View File
@@ -4,7 +4,7 @@
*/
import ApplicationSerializer from './application';
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
import { TYPE_AUTH_METHOD_PASSWORD } from 'api/models/auth-method';
export default class AuthMethodSerializer extends ApplicationSerializer {
// =methods
@@ -17,18 +17,33 @@ export default class AuthMethodSerializer extends ApplicationSerializer {
*/
serialize(snapshot) {
switch (snapshot.record.type) {
case TYPE_AUTH_METHOD_OIDC:
return this.serializeOIDC(...arguments);
case TYPE_AUTH_METHOD_PASSWORD:
return this.serializePassword(...arguments);
default:
return this.serializeDefault(...arguments);
}
}
serializeAttribute(snapshot, json, key, attribute) {
const { type } = snapshot.record;
super.serializeAttribute(...arguments);
const { options } = attribute;
// If an attribute has a `for` option, it must match the
// record's `type`, else the attribute is excluded
// from serialization.
if (options?.for && !options.for.includes(type)) {
if (options.isNestedAttribute) {
delete json?.attributes?.[key];
}
}
}
/**
* Default serialization omits `attributes`.
* Password serialization omits `attributes`.
* @return {object}
*/
serializeDefault() {
serializePassword() {
let serialized = super.serialize(...arguments);
delete serialized.attributes;
return serialized;
@@ -40,11 +55,11 @@ export default class AuthMethodSerializer extends ApplicationSerializer {
* @param {Snapshot} snapshot
* @return {object}
*/
serializeOIDC(snapshot) {
serializeDefault(snapshot) {
let serialized = super.serialize(...arguments);
const state = snapshot?.adapterOptions?.state;
if (state) {
serialized = this.serializeOIDCWithState(snapshot, state);
serialized = this.serializeWithState(snapshot, state);
} else {
delete serialized.attributes.state;
}
@@ -57,7 +72,7 @@ export default class AuthMethodSerializer extends ApplicationSerializer {
* @param {string} state
* @return {object}
*/
serializeOIDCWithState(snapshot, state) {
serializeWithState(snapshot, state) {
return {
version: snapshot.attr('version'),
attributes: { state },