From 91ffbfb3159c5e5aff515966170068639dba8da6 Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Date: Mon, 30 Sep 2024 13:07:13 -0700 Subject: [PATCH] icu-14735 add search & pagination to aliases (#2498) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 💡 add search & pagination to aliases ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-14735 --------- Co-authored-by: Dharini Jeeva Co-authored-by: Cameron Perera --- addons/api/addon/services/indexed-db.js | 2 + .../controllers/scopes/scope/aliases/index.js | 29 +- ui/admin/app/routes/scopes/scope/aliases.js | 33 -- .../app/routes/scopes/scope/aliases/index.js | 90 ++++++ .../routes/scopes/scope/auth-methods/index.js | 15 +- .../scopes/scope/credential-stores/index.js | 13 +- .../app/routes/scopes/scope/groups/index.js | 13 +- .../scopes/scope/host-catalogs/index.js | 15 +- .../app/routes/scopes/scope/roles/index.js | 12 +- .../app/routes/scopes/scope/scopes/index.js | 10 +- .../app/routes/scopes/scope/targets/index.js | 12 +- .../app/routes/scopes/scope/users/index.js | 12 +- .../templates/scopes/scope/aliases/index.hbs | 282 ++++++++++-------- .../scopes/scope/auth-methods/index.hbs | 2 +- .../scopes/scope/credential-stores/index.hbs | 6 +- .../templates/scopes/scope/groups/index.hbs | 6 +- .../scopes/scope/host-catalogs/index.hbs | 6 +- .../templates/scopes/scope/roles/index.hbs | 6 +- .../templates/scopes/scope/scopes/index.hbs | 8 +- .../templates/scopes/scope/targets/index.hbs | 6 +- .../templates/scopes/scope/users/index.hbs | 6 +- .../tests/acceptance/aliases/list-test.js | 76 ++++- .../scopes/scope/aliases/index-test.js | 94 +++++- 23 files changed, 508 insertions(+), 246 deletions(-) diff --git a/addons/api/addon/services/indexed-db.js b/addons/api/addon/services/indexed-db.js index 18ac4f356..ca067ba5c 100644 --- a/addons/api/addon/services/indexed-db.js +++ b/addons/api/addon/services/indexed-db.js @@ -29,6 +29,8 @@ export const modelIndexes = { '&id, attributes.created_time, attributes.type, attributes.name, attributes.description, attributes.scope.scope_id, attributes.plugin.name', 'auth-method': '&id, attributes.created_time, attributes.type, attributes.name, attributes.description, attributes.is_primary, attributes.scope.scope_id', + alias: + '&id, attributes.created_time, attributes.type, attributes.value, attributes.name, attributes.description, attributes.destination_id, attributes.scope.scope_id', }; export const formatDbName = (userId, clusterUrl) => diff --git a/ui/admin/app/controllers/scopes/scope/aliases/index.js b/ui/admin/app/controllers/scopes/scope/aliases/index.js index 0774c93b4..15e64ac61 100644 --- a/ui/admin/app/controllers/scopes/scope/aliases/index.js +++ b/ui/admin/app/controllers/scopes/scope/aliases/index.js @@ -6,15 +6,26 @@ import Controller from '@ember/controller'; import { inject as service } from '@ember/service'; import { action } from '@ember/object'; +import { tracked } from '@glimmer/tracking'; import { loading } from 'ember-loading'; +import { debounce } from 'core/decorators/debounce'; import { notifySuccess, notifyError } from 'core/decorators/notify'; import { confirm } from 'core/decorators/confirm'; export default class ScopesScopeAliasesIndexController extends Controller { // =services + @service can; @service router; + // =attributes + + queryParams = ['search', 'page', 'pageSize']; + + @tracked search; + @tracked page = 1; + @tracked pageSize = 10; + // =actions /** @@ -22,10 +33,10 @@ export default class ScopesScopeAliasesIndexController extends Controller { * @param {AliasModel} alias */ @action - async cancel(alias) { + cancel(alias) { const { isNew } = alias; alias.rollbackAttributes(); - if (isNew) await this.router.transitionTo('scopes.scope.aliases'); + if (isNew) this.router.transitionTo('scopes.scope.aliases'); } /** @@ -49,7 +60,7 @@ export default class ScopesScopeAliasesIndexController extends Controller { } /** - * Remove destaination_id from alias + * Remove destination_id from alias * @param {AliasModel} alias */ @action @@ -77,4 +88,16 @@ export default class ScopesScopeAliasesIndexController extends Controller { await this.router.replaceWith('scopes.scope.aliases'); await this.router.refresh(); } + + /** + * Handles input on each keystroke and the search queryParam + * @param {object} event + */ + @action + @debounce(250) + handleSearchInput(event) { + const { value } = event.target; + this.search = value; + this.page = 1; + } } diff --git a/ui/admin/app/routes/scopes/scope/aliases.js b/ui/admin/app/routes/scopes/scope/aliases.js index bf410903b..9fa8ae295 100644 --- a/ui/admin/app/routes/scopes/scope/aliases.js +++ b/ui/admin/app/routes/scopes/scope/aliases.js @@ -5,14 +5,11 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; -import { all, hash } from 'rsvp'; export default class ScopesScopeAliasesRoute extends Route { // =services - @service store; @service session; - @service can; @service router; // =methods @@ -23,34 +20,4 @@ export default class ScopesScopeAliasesRoute extends Route { beforeModel() { if (!this.session.isAuthenticated) this.router.transitionTo('index'); } - - /** - * Load all aliases in current scope - * @return {Promise<[AliasModel]>} - */ - async model() { - const scope = this.modelFor('scopes.scope'); - const { id: scope_id } = scope; - - if ( - this.can.can('list model', scope, { - collection: 'aliases', - }) - ) { - const aliases = await this.store.query('alias', { scope_id }); - // since we don't receive target info from aliases list API, - // we query the store to fetch target information based on the destination id - const aliasesWithResourceNames = await all( - aliases.map((alias) => - hash({ - alias, - target: alias.destination_id - ? this.store.findRecord('target', alias.destination_id) - : null, - }), - ), - ); - return aliasesWithResourceNames; - } - } } diff --git a/ui/admin/app/routes/scopes/scope/aliases/index.js b/ui/admin/app/routes/scopes/scope/aliases/index.js index 4b69d1742..d6249241e 100644 --- a/ui/admin/app/routes/scopes/scope/aliases/index.js +++ b/ui/admin/app/routes/scopes/scope/aliases/index.js @@ -4,10 +4,100 @@ */ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; +import { hash } from 'rsvp'; export default class ScopesScopeAliasesIndexRoute extends Route { + // =services + + @service store; + @service can; + + // =attributes + + queryParams = { + search: { + refreshModel: true, + replace: true, + }, + page: { + refreshModel: true, + }, + pageSize: { + refreshModel: true, + }, + }; + // =methods + /** + * Loads queried aliases and the number of aliases under current scope. + * @returns {Promise<{totalItems: number, aliases: [object], aliasesExist: boolean}>} + */ + async model({ search, page, pageSize }) { + const scope = this.modelFor('scopes.scope'); + const { id: scope_id } = scope; + + let aliases; + let doAliasesExist = false; + let totalItems = 0; + + if ( + this.can.can('list model', scope, { + collection: 'aliases', + }) + ) { + aliases = await this.store.query('alias', { + scope_id, + query: { search }, + page, + pageSize, + }); + totalItems = aliases.meta?.totalItems; + // since we don't receive target info from aliases list API, + // we query the store to fetch target information based on the destination id + aliases = await Promise.all( + aliases.map((alias) => + hash({ + alias, + target: alias.destination_id + ? this.store.findRecord('target', alias.destination_id, { + backgroundReload: false, + }) + : null, + }), + ), + ); + doAliasesExist = await this.getDoAliasesExist(scope_id, totalItems); + } + + return { aliases, doAliasesExist, totalItems }; + } + + /** + * Sets doAliasesExist to true if there are any aliases. + * @param {string} scope_id + * @param {number} totalItems + * @returns {Promise} + */ + async getDoAliasesExist(scope_id, totalItems) { + if (totalItems > 0) { + return true; + } + const options = { pushToStore: false, peekIndexedDB: true }; + const aliases = await this.store.query( + 'alias', + { + scope_id, + query: { filters: { scope_id: [{ equals: scope_id }] } }, + page: 1, + pageSize: 1, + }, + options, + ); + return aliases.length > 0; + } + setupController(controller) { const scope = this.modelFor('scopes.scope'); super.setupController(...arguments); diff --git a/ui/admin/app/routes/scopes/scope/auth-methods/index.js b/ui/admin/app/routes/scopes/scope/auth-methods/index.js index fd39a9724..1561492c8 100644 --- a/ui/admin/app/routes/scopes/scope/auth-methods/index.js +++ b/ui/admin/app/routes/scopes/scope/auth-methods/index.js @@ -40,7 +40,7 @@ export default class ScopesScopeAuthMethodsIndexRoute extends Route { /** * Loads queried auth-methods and the number of auth-methods under current scope. - * @returns {Promise<{totalItems: number, authMethods: [AuthMethodModel], authMethodsExist: boolean }> } + * @returns {Promise<{totalItems: number, authMethods: [AuthMethodModel], doAuthMethodsExist: boolean }> } */ async model({ search, types, primary, page, pageSize }) { const scope = this.modelFor('scopes.scope'); @@ -62,7 +62,7 @@ export default class ScopesScopeAuthMethodsIndexRoute extends Route { let authMethods; let totalItems = 0; - let authMethodsExist = false; + let doAuthMethodsExist = false; if (this.can.can('list model', scope, { collection: 'auth-methods' })) { // TODO: Remove storeToken option as this is a temporary fix for auth-methods. const options = { storeToken: false }; @@ -77,19 +77,22 @@ export default class ScopesScopeAuthMethodsIndexRoute extends Route { options, ); totalItems = authMethods.meta?.totalItems; - authMethodsExist = await this.getAuthMethodsExist(scope_id, totalItems); + doAuthMethodsExist = await this.getDoAuthMethodsExist( + scope_id, + totalItems, + ); } - return { authMethods, authMethodsExist, totalItems }; + return { authMethods, doAuthMethodsExist, totalItems }; } /** - * Sets authMethodsExist to true if there exists any auth methods. + * Sets doAuthMethodsExist to true if there exists any auth methods. * @param {string} scope_id * @param {number} totalItems * @returns {Promise} */ - async getAuthMethodsExist(scope_id, totalItems) { + async getDoAuthMethodsExist(scope_id, totalItems) { if (totalItems > 0) { return true; } diff --git a/ui/admin/app/routes/scopes/scope/credential-stores/index.js b/ui/admin/app/routes/scopes/scope/credential-stores/index.js index f699fa00d..b044ed867 100644 --- a/ui/admin/app/routes/scopes/scope/credential-stores/index.js +++ b/ui/admin/app/routes/scopes/scope/credential-stores/index.js @@ -35,7 +35,7 @@ export default class ScopesScopeCredentialStoresIndexRoute extends Route { /** * Loads queried credential-stores and the number of credential-stores under current scope. - * @returns {Promise<{totalItems: number, credentialStores: [CredentialStoreModel], credentialStoresExist: boolean }> } + * @returns {Promise<{totalItems: number, credentialStores: [CredentialStoreModel], doCredentialStoresExist: boolean }> } */ async model({ search, types, page, pageSize }) { const scope = this.modelFor('scopes.scope'); @@ -51,7 +51,7 @@ export default class ScopesScopeCredentialStoresIndexRoute extends Route { let credentialStores; let totalItems = 0; - let credentialStoresExist = false; + let doCredentialStoresExist = false; if ( this.can.can('list model', scope, { collection: 'credential-stores', @@ -64,22 +64,21 @@ export default class ScopesScopeCredentialStoresIndexRoute extends Route { pageSize, }); totalItems = credentialStores.meta?.totalItems; - credentialStoresExist = await this.getCredentialStoresExist( + doCredentialStoresExist = await this.getDoCredentialStoresExist( scope_id, totalItems, ); } - - return { credentialStores, credentialStoresExist, totalItems }; + return { credentialStores, doCredentialStoresExist, totalItems }; } /** - * Sets credentialStoresExist to true if there exists any credential-stores. + * Sets doCredentialStoresExist to true if there exists any credential-stores. * @param {string} scope_id * @param {number} totalItems * @returns {Promise} */ - async getCredentialStoresExist(scope_id, totalItems) { + async getDoCredentialStoresExist(scope_id, totalItems) { if (totalItems > 0) { return true; } diff --git a/ui/admin/app/routes/scopes/scope/groups/index.js b/ui/admin/app/routes/scopes/scope/groups/index.js index ba3ec44ba..4d00963ed 100644 --- a/ui/admin/app/routes/scopes/scope/groups/index.js +++ b/ui/admin/app/routes/scopes/scope/groups/index.js @@ -31,14 +31,14 @@ export default class ScopesScopeGroupsIndexRoute extends Route { /** * Loads queried groups and the number of groups under current scope. - * @returns {Promise<{totalItems: number, groups: [GroupModel], groupsExist: boolean }> } + * @returns {Promise<{totalItems: number, groups: [GroupModel], doGroupsExist: boolean }> } */ async model({ search, page, pageSize }) { const scope = this.modelFor('scopes.scope'); const { id: scope_id } = scope; let groups = []; let totalItems = 0; - let groupsExist = false; + let doGroupsExist = false; const filters = { scope_id: [{ equals: scope_id }] }; if (this.can.can('list model', scope, { collection: 'groups' })) { @@ -49,18 +49,19 @@ export default class ScopesScopeGroupsIndexRoute extends Route { pageSize, }); totalItems = groups.meta?.totalItems; - groupsExist = await this.getGroupsExist(scope_id, totalItems); + doGroupsExist = await this.getDoGroupsExist(scope_id, totalItems); } - return { groups, groupsExist, totalItems }; + return { groups, doGroupsExist, totalItems }; } /** - * Sets groupsExist to true if there exists any groups. + * Sets doGroupsExist to true if there exists any groups. * @param {string} scope_id * @param {number} totalItems + * @returns {Promise} */ - async getGroupsExist(scope_id, totalItems) { + async getDoGroupsExist(scope_id, totalItems) { if (totalItems > 0) { return true; } diff --git a/ui/admin/app/routes/scopes/scope/host-catalogs/index.js b/ui/admin/app/routes/scopes/scope/host-catalogs/index.js index 4fd26049c..26510acfc 100644 --- a/ui/admin/app/routes/scopes/scope/host-catalogs/index.js +++ b/ui/admin/app/routes/scopes/scope/host-catalogs/index.js @@ -31,7 +31,7 @@ export default class ScopesScopeHostCatalogsIndexRoute extends Route { /** * Loads all host catalogs under the current scope. - * @returns {Promise<{hostCatalogsExist: boolean, totalItems: number, hostCatalogs: [HostCatalogModel]}>} + * @returns {Promise<{doHostCatalogsExist: boolean, totalItems: number, hostCatalogs: [HostCatalogModel]}>} */ async model({ search, page, pageSize }) { const scope = this.modelFor('scopes.scope'); @@ -45,7 +45,7 @@ export default class ScopesScopeHostCatalogsIndexRoute extends Route { let hostCatalogs; let totalItems = 0; - let hostCatalogsExist = false; + let doHostCatalogsExist = false; if (this.can.can('list model', scope, { collection: 'host-catalogs' })) { hostCatalogs = await this.store.query('host-catalog', { scope_id, @@ -54,19 +54,22 @@ export default class ScopesScopeHostCatalogsIndexRoute extends Route { pageSize, }); totalItems = hostCatalogs.meta?.totalItems; - hostCatalogsExist = await this.getHostCatalogsExist(scope_id, totalItems); + doHostCatalogsExist = await this.getDoHostCatalogsExist( + scope_id, + totalItems, + ); } - return { hostCatalogs, totalItems, hostCatalogsExist }; + return { hostCatalogs, totalItems, doHostCatalogsExist }; } /** * Returns true if any host catalogs exist. * @param {string} scope_id * @param {number} totalItems - * @returns {boolean} + * @returns {Promise} */ - async getHostCatalogsExist(scope_id, totalItems) { + async getDoHostCatalogsExist(scope_id, totalItems) { if (totalItems > 0) { return true; } diff --git a/ui/admin/app/routes/scopes/scope/roles/index.js b/ui/admin/app/routes/scopes/scope/roles/index.js index d5a2995e9..33f9bfff5 100644 --- a/ui/admin/app/routes/scopes/scope/roles/index.js +++ b/ui/admin/app/routes/scopes/scope/roles/index.js @@ -31,7 +31,7 @@ export default class ScopesScopeRolesIndexRoute extends Route { /** * Loads queried roles and the number of roles under current scope. - * @returns {Promise<{totalItems: number, roles: [RoleModel], rolesExist: boolean }> } + * @returns {Promise<{totalItems: number, roles: [RoleModel], doRolesExist: boolean }> } */ async model({ search, page, pageSize }) { const scope = this.modelFor('scopes.scope'); @@ -42,7 +42,7 @@ export default class ScopesScopeRolesIndexRoute extends Route { let roles; let totalItems = 0; - let rolesExist = false; + let doRolesExist = false; if (this.can.can('list model', scope, { collection: 'roles' })) { roles = await this.store.query('role', { scope_id, @@ -51,19 +51,19 @@ export default class ScopesScopeRolesIndexRoute extends Route { pageSize, }); totalItems = roles.meta?.totalItems; - rolesExist = await this.getRolesExist(scope_id, totalItems); + doRolesExist = await this.getDoRolesExist(scope_id, totalItems); } - return { roles, rolesExist, totalItems }; + return { roles, doRolesExist, totalItems }; } /** - * Sets rolesExist to true if there exists any roles. + * Sets doRolesExist to true if there exists any roles. * @param {string} scope_id * @param {number} totalItems * @returns {Promise} */ - async getRolesExist(scope_id, totalItems) { + async getDoRolesExist(scope_id, totalItems) { if (totalItems > 0) { return true; } diff --git a/ui/admin/app/routes/scopes/scope/scopes/index.js b/ui/admin/app/routes/scopes/scope/scopes/index.js index 76dd6c33e..5222a0808 100644 --- a/ui/admin/app/routes/scopes/scope/scopes/index.js +++ b/ui/admin/app/routes/scopes/scope/scopes/index.js @@ -31,7 +31,7 @@ export default class ScopesScopeScopesIndexRoute extends Route { /** * Loads sub scopes for the current scope. - * @returns {Promise<{totalItems: number, currentScope: ScopeModel, subScopes: [ScopeModel], scopesExist: boolean }> } + * @returns {Promise<{totalItems: number, currentScope: ScopeModel, subScopes: [ScopeModel], doScopesExist: boolean }> } */ async model({ search, page, pageSize }) { const currentScope = this.modelFor('scopes.scope'); @@ -47,23 +47,23 @@ export default class ScopesScopeScopesIndexRoute extends Route { pageSize, }); const totalItems = subScopes.meta?.totalItems; - const scopesExist = await this.getScopesExist(scope_id, totalItems); + const doScopesExist = await this.getDoScopesExist(scope_id, totalItems); return { currentScope, subScopes, - scopesExist, + doScopesExist, totalItems, }; } /** - * Sets scopesExist to true if there exists any scopes. + * Sets doScopesExist to true if there exists any scopes. * @param {string} scope_id * @param {number} totalItems * @returns {Promise} */ - async getScopesExist(scope_id, totalItems) { + async getDoScopesExist(scope_id, totalItems) { if (totalItems > 0) { return true; } diff --git a/ui/admin/app/routes/scopes/scope/targets/index.js b/ui/admin/app/routes/scopes/scope/targets/index.js index afde0885d..2db2a13b1 100644 --- a/ui/admin/app/routes/scopes/scope/targets/index.js +++ b/ui/admin/app/routes/scopes/scope/targets/index.js @@ -45,7 +45,7 @@ export default class ScopesScopeTargetsIndexRoute extends Route { /** * Loads queried targets, the number of targets under current scope, and * active sessions filtering options. - * @returns {Promise<{totalItems: number, targets: [TargetModel], targetsExist: boolean }> } + * @returns {Promise<{totalItems: number, targets: [TargetModel], doTargetsExist: boolean }> } */ async model({ search, availableSessions, types, page, pageSize }) { const scope = this.modelFor('scopes.scope'); @@ -78,7 +78,7 @@ export default class ScopesScopeTargetsIndexRoute extends Route { let targets; let totalItems = 0; - let targetsExist = false; + let doTargetsExist = false; if (this.can.can('list model', scope, { collection: 'targets' })) { targets = await this.store.query('target', { scope_id, @@ -87,19 +87,19 @@ export default class ScopesScopeTargetsIndexRoute extends Route { pageSize, }); totalItems = targets.meta?.totalItems; - targetsExist = await this.getTargetsExist(scope_id, totalItems); + doTargetsExist = await this.getDoTargetsExist(scope_id, totalItems); } - return { targets, targetsExist, totalItems }; + return { targets, doTargetsExist, totalItems }; } /** - * Sets targetsExist to true if there exists any targets. + * Sets doTargetsExist to true if there exists any targets. * @param {string} scope_id * @param {number} totalItems * @returns {Promise} */ - async getTargetsExist(scope_id, totalItems) { + async getDoTargetsExist(scope_id, totalItems) { if (totalItems > 0) { return true; } diff --git a/ui/admin/app/routes/scopes/scope/users/index.js b/ui/admin/app/routes/scopes/scope/users/index.js index b681334e1..6c54ac6d7 100644 --- a/ui/admin/app/routes/scopes/scope/users/index.js +++ b/ui/admin/app/routes/scopes/scope/users/index.js @@ -31,7 +31,7 @@ export default class ScopesScopeUsersIndexRoute extends Route { /** * Loads queried users and the number of users under current scope. - * @returns {Promise<{totalItems: number, users: [UserModel], usersExist: boolean }> } + * @returns {Promise<{totalItems: number, users: [UserModel], doUsersExist: boolean }> } */ async model({ search, page, pageSize }) { const scope = this.modelFor('scopes.scope'); @@ -43,7 +43,7 @@ export default class ScopesScopeUsersIndexRoute extends Route { let users; let totalItems = 0; - let usersExist = false; + let doUsersExist = false; if (this.can.can('list model', scope, { collection: 'users' })) { users = await this.store.query('user', { scope_id, @@ -52,19 +52,19 @@ export default class ScopesScopeUsersIndexRoute extends Route { pageSize, }); totalItems = users.meta?.totalItems; - usersExist = await this.getUsersExist(scope_id, totalItems); + doUsersExist = await this.getDoUsersExist(scope_id, totalItems); } - return { users, usersExist, totalItems }; + return { users, doUsersExist, totalItems }; } /** - * Sets usersExist to true if there exists any users. + * Sets doUsersExist to true if there exists any users. * @param {string} scope_id * @param {number} totalItems * @returns {Promise} */ - async getUsersExist(scope_id, totalItems) { + async getDoUsersExist(scope_id, totalItems) { if (totalItems > 0) { return true; } diff --git a/ui/admin/app/templates/scopes/scope/aliases/index.hbs b/ui/admin/app/templates/scopes/scope/aliases/index.hbs index 7d54aa559..0517da88a 100644 --- a/ui/admin/app/templates/scopes/scope/aliases/index.hbs +++ b/ui/admin/app/templates/scopes/scope/aliases/index.hbs @@ -18,7 +18,7 @@ {{#if (can 'create model' this.scope collection='aliases')}} - {{#if @model}} + {{#if @model.doAliasesExist}} - - {{#if @model}} - - <:body as |B|> - - - {{#if (can 'read model' B.data.alias)}} - - {{B.data.alias.value}} - - {{else}} - - {{B.data.alias.value}} - - {{/if}} - {{#if B.data.alias.description}} - - {{B.data.alias.description}} - - {{/if}} - - - {{#if B.data.target.displayName}} -
- - {{B.data.target.displayName}} -
- {{else}} - - {{t 'titles.not-set'}} - - {{/if}} -
- - - - - {{#if B.data.alias.destination_id}} - - {{/if}} - - - {{#let - (hash - canUpdate=(can 'update model' B.data.alias) - canDelete=(can 'delete model' B.data.alias) - ) - as |perms| - }} - {{#if (or perms.canUpdate perms.canDelete)}} - + + {{#if @model.doAliasesExist}} + + + - - {{#if perms.canUpdate}} - + <:body as |B|> + + + {{#if (can 'read model' B.data.alias)}} + + {{B.data.alias.value}} + + {{else}} + + {{B.data.alias.value}} + + {{/if}} + {{#if B.data.alias.description}} + + {{B.data.alias.description}} + + {{/if}} + + + {{#if B.data.target.displayName}} +
+ + {{B.data.target.displayName}} +
+ {{else}} + + {{t 'titles.not-set'}} + + {{/if}} +
+ + + + + {{#if B.data.alias.destination_id}} + + {{/if}} + + + {{#let + (hash + canUpdate=(can 'update model' B.data.alias) + canDelete=(can 'delete model' B.data.alias) + ) + as |perms| + }} + {{#if (or perms.canUpdate perms.canDelete)}} + + + - {{#if B.data.alias.destination_id}} + {{#if perms.canUpdate}} + {{#if B.data.alias.destination_id}} + + {{/if}} + {{/if}} + + {{#if perms.canDelete}} + {{/if}} - {{/if}} + - {{#if perms.canDelete}} - - {{/if}} -
- - {{/if}} - {{/let}} -
-
- -
+ {{/if}} + {{/let}} + + + + + + {{else}} + + + + + {{/if}} {{else}} - - - - {{#if (can 'list model' this.scope collection='aliases')}} - {{t 'resources.alias.messages.none.description'}} - {{else if (can 'create model' this.scope collection='aliases')}} - {{t + + + - {{#if (can 'create model' this.scope collection='aliases')}} - + {{#if (can 'create model' this.scope collection='aliases')}} + + - {{/if}} - - + + {{/if}} + {{/if}}
diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/index.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/index.hbs index 6c3eb4f06..20b9e281d 100644 --- a/ui/admin/app/templates/scopes/scope/auth-methods/index.hbs +++ b/ui/admin/app/templates/scopes/scope/auth-methods/index.hbs @@ -42,7 +42,7 @@
- {{#if @model.authMethodsExist}} + {{#if @model.doAuthMethodsExist}} {{#unless this.hasPrimaryAuthMethod}} - {{#if @model.credentialStoresExist}} + {{#if @model.doCredentialStoresExist}}

{{t 'resources.credential-store.description'}}

{{/if}} @@ -21,7 +21,7 @@ {{#if (can 'create model' this.scope collection='credential-stores')}} - {{#if @model.credentialStoresExist}} + {{#if @model.doCredentialStoresExist}} - {{#if @model.credentialStoresExist}} + {{#if @model.doCredentialStoresExist}} - {{#if @model.groupsExist}} + {{#if @model.doGroupsExist}}

{{t 'resources.group.description'}}

{{/if}} {{#if (can 'create model' this.scope collection='groups')}} - {{#if @model.groupsExist}} + {{#if @model.doGroupsExist}} - {{#if @model.groupsExist}} + {{#if @model.doGroupsExist}} - {{#if @model.hostCatalogsExist}} + {{#if @model.doHostCatalogsExist}}

{{t 'resources.host-catalog.description'}}

{{/if}} {{#if (can 'create model' this.scope collection='host-catalogs')}} - {{#if @model.hostCatalogsExist}} + {{#if @model.doHostCatalogsExist}} - {{#if @model.hostCatalogsExist}} + {{#if @model.doHostCatalogsExist}} - {{#if @model.rolesExist}} + {{#if @model.doRolesExist}}

{{t 'resources.role.description'}}

{{/if}} {{#if (can 'create model' this.scope collection='roles')}} - {{#if @model.rolesExist}} + {{#if @model.doRolesExist}} - {{#if @model.rolesExist}} + {{#if @model.doRolesExist}} - {{#if @model.scopesExist}} + {{#if @model.doScopesExist}}

{{t 'resources.org.description'}}

{{/if}} {{else if @model.currentScope.isOrg}} @@ -23,7 +23,7 @@ {{t 'resources.project.title_plural'}} - {{#if @model.scopesExist}} + {{#if @model.doScopesExist}}

{{t 'resources.project.description'}}

{{/if}} {{/if}} @@ -31,7 +31,7 @@ {{#if (can 'create model' @model.currentScope collection='scopes')}} - {{#if @model.scopesExist}} + {{#if @model.doScopesExist}} - {{#if @model.scopesExist}} + {{#if @model.doScopesExist}} - {{#if @model.targetsExist}} + {{#if @model.doTargetsExist}}

{{t 'resources.target.description'}}

{{/if}} {{#if (can 'create model' this.scope collection='targets')}} - {{#if @model.targetsExist}} + {{#if @model.doTargetsExist}} - {{#if @model.targetsExist}} + {{#if @model.doTargetsExist}} - {{#if @model.usersExist}} + {{#if @model.doUsersExist}}

{{t 'resources.user.description'}}

{{/if}} {{#if (can 'create model' this.scope collection='users')}} - {{#if @model.usersExist}} + {{#if @model.doUsersExist}} - {{#if @model.usersExist}} + {{#if @model.doUsersExist}} + `tbody [data-test-alias-row="${id}"] td:last-child .hds-dropdown-toggle-icon`; const DROPDOWN_ITEM_SELECTOR = '.hds-dropdown-list-item a'; + const SEARCH_INPUT_SELECTOR = '.search-filtering [type="search"]'; + const NO_RESULTS_MSG_SELECTOR = '[data-test-no-alias-results]'; const instances = { scopes: { @@ -29,12 +33,15 @@ module('Acceptance | aliases | list', function (hooks) { org: null, }, alias: null, + target: null, + aliasWithTarget: null, }; const urls = { globalScope: null, aliases: null, alias: null, + aliasWithTarget: null, }; hooks.beforeEach(function () { @@ -43,15 +50,32 @@ module('Acceptance | aliases | list', function (hooks) { type: 'org', scope: { id: 'global', type: 'global' }, }); + instances.scopes.project = this.server.create('scope', { + type: 'project', + scope: { id: instances.scopes.org.id, type: 'org' }, + }); + instances.target = this.server.create('target', { + scope: instances.scopes.project, + }); + instances.alias = this.server.create('alias', { + scope: instances.scopes.global, + destination_id: null, + }); + instances.aliasWithTarget = this.server.create('alias', { + scope: instances.scopes.global, + destination_id: instances.target.id, + }); urls.globalScope = `/scopes/global`; urls.aliases = `${urls.globalScope}/aliases`; - + urls.alias = `${urls.aliases}/${instances.alias.id}`; + urls.aliasWithTarget = `${urls.aliases}/${instances.aliasWithTarget.id}`; intl = this.owner.lookup('service:intl'); authenticateSession({}); }); test('users can navigate to aliases with proper authorization', async function (assert) { + this.server.schema.aliases.all().destroy(); await visit(urls.globalScope); assert.ok( @@ -76,6 +100,7 @@ module('Acceptance | aliases | list', function (hooks) { }); test('user cannot navigate to index without either list or create actions', async function (assert) { + this.server.schema.aliases.all().destroy(); instances.scopes.global.authorized_collection_actions['aliases'] = []; await visit(urls.globalScope); @@ -105,6 +130,7 @@ module('Acceptance | aliases | list', function (hooks) { }); test('user can navigate to index with only create action', async function (assert) { + this.server.schema.aliases.all().destroy(); instances.scopes.global.authorized_collection_actions['aliases'] = instances.scopes.global.authorized_collection_actions['aliases'].filter( (item) => item !== 'list', @@ -135,6 +161,7 @@ module('Acceptance | aliases | list', function (hooks) { }); test('user can navigate to index with only list action', async function (assert) { + this.server.schema.aliases.all().destroy(); instances.scopes.global.authorized_collection_actions['aliases'] = instances.scopes.global.authorized_collection_actions['aliases'].filter( (item) => item !== 'create', @@ -164,17 +191,46 @@ module('Acceptance | aliases | list', function (hooks) { test('edit action in table directs user to appropriate page', async function (assert) { await visit(urls.globalScope); - instances.alias = this.server.create('alias', { - scope: instances.scopes.global, - }); - urls.alias = `${urls.aliases}/${instances.alias.id}`; await click(`[href="${urls.aliases}"]`); - await click(DROPDOWN_BUTTON_SELECTOR); + await click(DROPDOWN_BUTTON_SELECTOR(instances.alias.id)); assert.dom(DROPDOWN_ITEM_SELECTOR).exists(); assert.dom(DROPDOWN_ITEM_SELECTOR).hasText('Edit'); await click(DROPDOWN_ITEM_SELECTOR); assert.strictEqual(currentURL(), urls.alias); }); + + test('user can search for a specific alias by id', async function (assert) { + await visit(urls.globalScope); + + await click(`[href="${urls.aliases}"]`); + + assert.dom(`[href="${urls.alias}"]`).exists(); + assert.dom(`[href="${urls.aliasWithTarget}"]`).exists(); + + await fillIn(SEARCH_INPUT_SELECTOR, instances.alias.id); + await waitFor(`[href="${urls.aliasWithTarget}"]`, { count: 0 }); + + assert.dom(`[href="${urls.alias}"]`).exists(); + assert.dom(`[href="${urls.aliasWithTarget}"]`).doesNotExist(); + }); + + test('user can search for aliases and get no results', async function (assert) { + await visit(urls.globalScope); + + await click(`[href="${urls.aliases}"]`); + + assert.dom(`[href="${urls.alias}"]`).exists(); + assert.dom(`[href="${urls.aliasWithTarget}"]`).exists(); + + await fillIn(SEARCH_INPUT_SELECTOR, 'fake alias that does not exist'); + await waitFor(NO_RESULTS_MSG_SELECTOR, { count: 1 }); + + assert.dom(`[href="${urls.alias}"]`).doesNotExist(); + assert.dom(`[href="${urls.aliasWithTarget}"]`).doesNotExist(); + assert + .dom(NO_RESULTS_MSG_SELECTOR) + .includesText(intl.t('titles.no-results-found')); + }); }); diff --git a/ui/admin/tests/unit/controllers/scopes/scope/aliases/index-test.js b/ui/admin/tests/unit/controllers/scopes/scope/aliases/index-test.js index 0668fc521..983776c50 100644 --- a/ui/admin/tests/unit/controllers/scopes/scope/aliases/index-test.js +++ b/ui/admin/tests/unit/controllers/scopes/scope/aliases/index-test.js @@ -4,13 +4,103 @@ */ import { module, test } from 'qunit'; -import { setupTest } from 'admin/tests/helpers'; +import { setupTest } from 'ember-qunit'; +import { waitUntil, visit } from '@ember/test-helpers'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { setupIndexedDb } from 'api/test-support/helpers/indexed-db'; +import { setupIntl } from 'ember-intl/test-support'; +import { authenticateSession } from 'ember-simple-auth/test-support'; module('Unit | Controller | scopes/scope/aliases/index', function (hooks) { setupTest(hooks); + setupMirage(hooks); + setupIndexedDb(hooks); + setupIntl(hooks, 'en-us'); + + let store; + let controller; + let getAliasCount; + + const instances = { + scopes: { + global: null, + }, + alias: null, + }; + + const urls = { + globalScope: null, + aliases: null, + }; + + hooks.beforeEach(function () { + authenticateSession({}); + store = this.owner.lookup('service:store'); + controller = this.owner.lookup('controller:scopes/scope/aliases/index'); + + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.alias = this.server.create('alias', { + scope: instances.scopes.global, + }); + + urls.globalScope = `/scopes/global`; + urls.aliases = `${urls.globalScope}/aliases`; + + getAliasCount = () => this.server.schema.aliases.all().models.length; + }); test('it exists', function (assert) { - let controller = this.owner.lookup('controller:scopes/scope/aliases/index'); assert.ok(controller); }); + + test('handleSearchInput action sets expected values correctly', async function (assert) { + const searchValue = 'test'; + controller.handleSearchInput({ target: { value: searchValue } }); + await waitUntil(() => controller.search === searchValue); + + assert.strictEqual(controller.page, 1); + assert.strictEqual(controller.search, searchValue); + }); + + test('cancel action rolls-back changes on the specified model', async function (assert) { + await visit(urls.aliases); + const alias = await store.findRecord('alias', instances.alias.id); + alias.name = 'test'; + + assert.strictEqual(alias.name, 'test'); + + await controller.cancel(alias); + + assert.notEqual(alias.name, 'test'); + }); + + test('save action saves changes on the specified model', async function (assert) { + await visit(urls.aliases); + const alias = await store.findRecord('alias', instances.alias.id); + alias.name = 'test'; + + await controller.save(alias); + + assert.strictEqual(alias.name, 'test'); + }); + + test('deleteAlias action destroys specified model', async function (assert) { + const alias = await store.findRecord('alias', instances.alias.id); + const aliasCount = getAliasCount(); + + await controller.deleteAlias(alias); + + assert.strictEqual(getAliasCount(), aliasCount - 1); + }); + + test('clearAlias action removes destination_id on the specified model', async function (assert) { + const targetId = 't_1234567'; + instances.alias.update({ destination_id: targetId }); + const alias = await store.findRecord('alias', instances.alias.id); + assert.strictEqual(alias.destination_id, targetId); + + await controller.clearAlias(alias); + + assert.notOk(alias.destination_id); + }); });