Icu 6657 auth method model fragments refactor (#1507)

* refactor: 💡 Remove fragment usage for arrays in auth method
* chore: 🤖 Remove ember-data-model-fragments

✅ Closes: ICU-6657
This commit is contained in:
Zhihe Li authored and GitHub committed 2022-12-02 14:29:53 -05:00
1 parent f8429b15e9
commit c3d9fd8fc5
32 files changed
+161 -341

No files matched your search

@@ -2,6 +2,7 @@
{{component
(concat 'form/auth-method/' @model.type)
model=@model
edit=@edit
submit=@submit
cancel=@cancel
removeItemByIndex=@removeItemByIndex
@@ -1,4 +1,5 @@
<Rose::Form
@edit={{@edit}}
@onSubmit={{@submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@@ -165,8 +165,8 @@ export default class ScopesScopeAuthMethodsRoute extends Route {
*/
@action
async removeItemByIndex(authMethod, property, index) {
const array = authMethod.get(property);
array.removeAt(index);
const array = authMethod.get(property).filter((item, i) => i !== index);
authMethod.set(property, array);
}
/**
@@ -179,21 +179,22 @@ export default class ScopesScopeAuthMethodsRoute extends Route {
*/
@action
async addStringItem(authMethod, property, value) {
const array = authMethod.get(property);
array.addObject({ value });
const existingArray = authMethod[property] ?? [];
const array = [...existingArray, { value }];
authMethod.set(property, array);
}
/**
* Adds an account claim map fragment to the passed OIDC `authMethod`.
* @param {AuthMethodModel} authMethod
* @param {string} property
* @param {string} value
* @param {string} from
* @param {string} to
*/
@action
async addAccountClaimMapItem(authMethod, from, to) {
const array = authMethod.account_claim_maps;
const value = { from, to };
array.addObject(value);
const existingArray = authMethod.account_claim_maps ?? [];
const array = [...existingArray, { from, to }];
authMethod.set('account_claim_maps', array);
}
/**
@@ -2,6 +2,7 @@ import Route from '@ember/routing/route';
import { action } from '@ember/object';
import { notifySuccess, notifyError } from 'core/decorators/notify';
import { inject as service } from '@ember/service';
import { copy } from 'ember-copy';
export default class ScopesScopeAuthMethodsAuthMethodRoute extends Route {
// =services
@@ -22,6 +23,35 @@ export default class ScopesScopeAuthMethodsAuthMethodRoute extends Route {
// =actions
/**
* Copies the contents of string array fields in order to force the instance
* into a dirty state. This ensures that `model.rollbackAttributes()` reverts
* to the original expected array.
*
* The deep copy implemented here is required to ensure that both the
* array itself and its members are all new.
*
* @param {authMethodModel} authMethod
*/
@action
edit(authMethod) {
if (authMethod.claims_scopes) {
authMethod.claims_scopes = copy(authMethod.claims_scopes, true);
}
if (authMethod.signing_algorithms) {
authMethod.signing_algorithms = copy(authMethod.signing_algorithms, true);
}
if (authMethod.allowed_audiences) {
authMethod.allowed_audiences = copy(authMethod.allowed_audiences, true);
}
if (authMethod.idp_ca_certs) {
authMethod.idp_ca_certs = copy(authMethod.idp_ca_certs, true);
}
if (authMethod.account_claim_maps) {
authMethod.account_claim_maps = copy(authMethod.account_claim_maps, true);
}
}
/**
* Update state of OIDC auth method
* @param {string} state
@@ -32,7 +32,8 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsNewRoute extends
*/
@action
async addStringItem(hostSet, property, value) {
const array = [...(hostSet.get(property) ?? []), { value }];
const existingArray = hostSet[property] ?? [];
const array = [...existingArray, { value }];
hostSet.set(property, array);
}
/**
@@ -19,6 +19,7 @@
<page.body>
<Form::AuthMethod
@model={{@model}}
@edit={{route-action 'edit' @model}}
@submit={{route-action 'save' @model}}
@cancel={{route-action 'cancel' @model}}
@removeItemByIndex={{route-action 'removeItemByIndex' @model}}