Files
threshold-ui/ui/admin/app/controllers/scopes/scope/targets/target/add-credential-sources.js
T
Cameron Perera 9f09f01f36 Icu 5253 add query to include credentials (#1227)
* 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
2022-08-02 11:55:26 -05:00

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');
}
}