* refactor: 💡 add-credential-sources to include credentials * refactor: 💡 update add-credential-sources template Update to how AddCredentialSources form is rendered in the template ✅ Closes: ICU-5253 * refactor: 💡 Update add-credential-sources method signatures * refactor: 💡 change how add-credential-source form is rendered * refactor: 💡 Remove duplicate add-credential-sources message Remove the duplicate No Credential Credential Sources message from add-credential-sources form * refactor: 💡 Move filter logic to controller Move credential source filter logic from route to controller for add-credential-sources * test: 💍 Verify all available credential sources are listed
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
import Controller from '@ember/controller';
|
|
import { inject as service } from '@ember/service';
|
|
import { computed } from '@ember/object';
|
|
|
|
export default class ScopesScopeTargetsTargetAddCredentialSourcesController extends Controller {
|
|
// =services
|
|
|
|
@service intl;
|
|
|
|
// =attributes
|
|
|
|
/**
|
|
* Checks for unassigned credential sources.
|
|
* @type {boolean}
|
|
*/
|
|
get hasAvailableCredentialSources() {
|
|
return this.filteredCredentialSources.length > 0;
|
|
}
|
|
|
|
/**
|
|
* Filter out credential sources not already added to the target.
|
|
* @type {[CredentialLibraryModel, CredentialModel]}
|
|
*/
|
|
@computed(
|
|
'model.{target.application_credential_source_ids.[],credentialLibraries.[],credentials.[]}'
|
|
)
|
|
get filteredCredentialSources() {
|
|
// Get IDs for credential sources already added to the current target
|
|
const currentCredentialSourceIDs =
|
|
this.model.target.application_credential_source_ids.map(
|
|
(source) => source.value
|
|
);
|
|
const notAddedCredentialLibraries = this.model.credentialLibraries.filter(
|
|
({ id }) => !currentCredentialSourceIDs.includes(id)
|
|
);
|
|
const notAddedCredentials = this.model.credentials.filter(
|
|
({ id }) => !currentCredentialSourceIDs.includes(id)
|
|
);
|
|
return [...notAddedCredentialLibraries, ...notAddedCredentials];
|
|
}
|
|
|
|
/**
|
|
* Translated roles breadcrumb
|
|
* @type {string}
|
|
*/
|
|
get breadCrumb() {
|
|
return this.intl.t('resources.target.actions.add-credential-sources');
|
|
}
|
|
}
|