Icu 5476 refactor target model serializer and mirage (#1235)
chore: 🤖 refactor target model to support credentials
This commit is contained in:
1 parent
2cda4f639e
commit
1f0baceb5e
12 files changed
+210
-66
No files matched your search
@@ -48,17 +48,21 @@ export default class TargetModel extends GeneratedTargetModel {
|
||||
}
|
||||
|
||||
/**
|
||||
* An array of resolved credential library instances. Model instances
|
||||
* An array of resolved credential library and credential instances. Model instances
|
||||
* must already be loaded into the store (this method will not load unloaded
|
||||
* instances). Unresolvable instances are excluded from the array.
|
||||
* @type {[CredentialLibraryModel]}
|
||||
* @type {[CredentialLibraryModel, CredentialModel]}
|
||||
*/
|
||||
@computed('application_credential_source_ids.[]', 'store')
|
||||
get credentialLibraries() {
|
||||
get credentialSources() {
|
||||
return this.application_credential_source_ids
|
||||
.map((source) =>
|
||||
this.store.peekRecord('credential-library', source.value)
|
||||
)
|
||||
.map((source) => {
|
||||
if (source.value.startsWith('cred')) {
|
||||
return this.store.peekRecord('credential', source.value);
|
||||
} else {
|
||||
return this.store.peekRecord('credential-library', source.value);
|
||||
}
|
||||
})
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
@@ -150,17 +154,17 @@ export default class TargetModel extends GeneratedTargetModel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds credential libraries via the `add-credential-sources` method.
|
||||
* Adds credential sources via the `add-credential-sources` method.
|
||||
* See serializer and adapter for more information.
|
||||
* @param {[string]} credentialLibraryIDs
|
||||
* @param {[string]} credentialSourceIDs
|
||||
* @param {object} options
|
||||
* @param {object} options.adapterOptions
|
||||
* @return {Promise}
|
||||
*/
|
||||
addCredentialSources(credentialLibraryIDs, options = { adapterOptions: {} }) {
|
||||
addCredentialSources(credentialSourceIDs, options = { adapterOptions: {} }) {
|
||||
const defaultAdapterOptions = {
|
||||
method: 'add-credential-sources',
|
||||
credentialLibraryIDs,
|
||||
credentialSourceIDs,
|
||||
};
|
||||
// There is no "deep merge" in ES.
|
||||
return this.save({
|
||||
@@ -173,20 +177,20 @@ export default class TargetModel extends GeneratedTargetModel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete credential libraries via the `remove-credential-sources` method.
|
||||
* Delete credential libraries and credentials via the `remove-credential-sources` method.
|
||||
* See serializer and adapter for more information.
|
||||
* @param {[string]} credentialLibraryIDs
|
||||
* @param {[string]} credentialSourceIDs
|
||||
* @param {object} options
|
||||
* @param {object} options.adapterOptions
|
||||
* @return {Promise}
|
||||
*/
|
||||
removeCredentialSources(
|
||||
credentialLibraryIDs,
|
||||
credentialSourceIDs,
|
||||
options = { adapterOptions: {} }
|
||||
) {
|
||||
const defaultAdapterOptions = {
|
||||
method: 'remove-credential-sources',
|
||||
credentialLibraryIDs,
|
||||
credentialSourceIDs,
|
||||
};
|
||||
// There is no "deep merge" in ES.
|
||||
return this.save({
|
||||
@@ -199,13 +203,13 @@ export default class TargetModel extends GeneratedTargetModel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a single credential library set via the `remove-credential-sources` method.
|
||||
* @param {number} credentialLibraryID
|
||||
* Delete a single credential library/credential set via the `remove-credential-sources` method.
|
||||
* @param {number} credentialSourceID
|
||||
* @param {object} options
|
||||
* @return {Promise}
|
||||
*/
|
||||
removeCredentialSource(credentialLibraryID, options) {
|
||||
return this.removeCredentialSources([credentialLibraryID], options);
|
||||
removeCredentialSource(credentialSourceID, options) {
|
||||
return this.removeCredentialSources([credentialSourceID], options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,10 +7,10 @@ export default class TargetSerializer extends ApplicationSerializer {
|
||||
* If `adapterOptions.hostSets` is set to an array of host set models,
|
||||
* the resulting target serialization should include **only host sets**
|
||||
* and the version.
|
||||
* If `adapterOptions.credentialLibraries` is set to an array of
|
||||
* credential library models, the resulting target serialization should
|
||||
* include **only credential libraries** and the version.
|
||||
* Normally, neither host sets or credential libraries are not serialized.
|
||||
* If `adapterOptions.credentialSources` is set to an array of
|
||||
* credential library and credential models, the resulting target serialization should
|
||||
* include **only credential libraries and crendentials** and the version.
|
||||
* Normally, neither host sets or credential libraries or credentials are not serialized.
|
||||
* @override
|
||||
* @param {Snapshot} snapshot
|
||||
* @return {object}
|
||||
@@ -21,7 +21,7 @@ export default class TargetSerializer extends ApplicationSerializer {
|
||||
if (hostSourceIDs) {
|
||||
serialized = this.serializeWithHostSources(snapshot, hostSourceIDs);
|
||||
}
|
||||
const credentialSourceIDs = snapshot?.adapterOptions?.credentialLibraryIDs;
|
||||
const credentialSourceIDs = snapshot?.adapterOptions?.credentialSourceIDs;
|
||||
if (credentialSourceIDs)
|
||||
serialized = this.serializeWithCredentialSources(
|
||||
snapshot,
|
||||
|
||||
Reference in new issue
Block a user