From c2c0b3818774d62973436db4d07a50568d23cdb2 Mon Sep 17 00:00:00 2001 From: Cameron Perera Date: Mon, 8 Apr 2024 11:42:20 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20move=20query=20inside=20l?= =?UTF-8?q?ist=20permission=20check=20(#2222)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13356 --- .../controllers/scopes/scope/credential-stores/index.js | 1 - .../app/routes/scopes/scope/credential-stores/index.js | 9 +++++---- ui/admin/app/routes/scopes/scope/groups/index.js | 4 ++-- ui/admin/app/routes/scopes/scope/host-catalogs/index.js | 7 ++----- ui/admin/app/routes/scopes/scope/roles/index.js | 3 ++- ui/admin/app/routes/scopes/scope/users/index.js | 3 ++- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ui/admin/app/controllers/scopes/scope/credential-stores/index.js b/ui/admin/app/controllers/scopes/scope/credential-stores/index.js index 1d0182c05..c55f82f7b 100644 --- a/ui/admin/app/controllers/scopes/scope/credential-stores/index.js +++ b/ui/admin/app/controllers/scopes/scope/credential-stores/index.js @@ -123,7 +123,6 @@ export default class ScopesScopeCredentialStoresIndexController extends Controll */ @action applyFilter(paramKey, selectedItems) { - console.log('appy filter', paramKey, selectedItems); this[paramKey] = [...selectedItems]; this.page = 1; } 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 0fb85eb97..d78dd23a4 100644 --- a/ui/admin/app/routes/scopes/scope/credential-stores/index.js +++ b/ui/admin/app/routes/scopes/scope/credential-stores/index.js @@ -51,6 +51,7 @@ export default class ScopesScopeCredentialStoresIndexRoute extends Route { let credentialStores; let totalItems = 0; + let credentialStoresExist = false; if ( this.can.can('list model', scope, { collection: 'credential-stores', @@ -62,11 +63,11 @@ export default class ScopesScopeCredentialStoresIndexRoute extends Route { pageSize, }); totalItems = credentialStores.meta?.totalItems; + credentialStoresExist = await this.getCredentialStoresExist( + scope_id, + totalItems, + ); } - const credentialStoresExist = await this.getCredentialStoresExist( - scope_id, - totalItems, - ); return { credentialStores, credentialStoresExist, totalItems }; } diff --git a/ui/admin/app/routes/scopes/scope/groups/index.js b/ui/admin/app/routes/scopes/scope/groups/index.js index 7a01679a0..d59b8d6f8 100644 --- a/ui/admin/app/routes/scopes/scope/groups/index.js +++ b/ui/admin/app/routes/scopes/scope/groups/index.js @@ -38,6 +38,7 @@ export default class ScopesScopeGroupsIndexRoute extends Route { const { id: scope_id } = scope; let groups = []; let totalItems = 0; + let groupsExist = false; const filters = { scope_id: [{ equals: scope_id }] }; if (this.can.can('list model', scope, { collection: 'groups' })) { @@ -47,10 +48,9 @@ export default class ScopesScopeGroupsIndexRoute extends Route { pageSize, }); totalItems = groups.meta?.totalItems; + groupsExist = await this.getGroupsExist(scope_id, totalItems); } - const groupsExist = await this.getGroupsExist(scope_id, totalItems); - return { groups, groupsExist, totalItems }; } 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 b7d302889..2fc327fca 100644 --- a/ui/admin/app/routes/scopes/scope/host-catalogs/index.js +++ b/ui/admin/app/routes/scopes/scope/host-catalogs/index.js @@ -45,6 +45,7 @@ export default class ScopesScopeHostCatalogsIndexRoute extends Route { let hostCatalogs; let totalItems = 0; + let hostCatalogsExist = false; if (this.can.can('list model', scope, { collection: 'host-catalogs' })) { hostCatalogs = await this.store.query('host-catalog', { query: { search, filters }, @@ -52,13 +53,9 @@ export default class ScopesScopeHostCatalogsIndexRoute extends Route { pageSize, }); totalItems = hostCatalogs.meta?.totalItems; + hostCatalogsExist = await this.getHostCatalogsExist(scope_id, totalItems); } - const hostCatalogsExist = await this.getHostCatalogsExist( - scope_id, - totalItems, - ); - return { hostCatalogs, totalItems, hostCatalogsExist }; } diff --git a/ui/admin/app/routes/scopes/scope/roles/index.js b/ui/admin/app/routes/scopes/scope/roles/index.js index 62bf916fe..2701f9aa5 100644 --- a/ui/admin/app/routes/scopes/scope/roles/index.js +++ b/ui/admin/app/routes/scopes/scope/roles/index.js @@ -42,6 +42,7 @@ export default class ScopesScopeRolesIndexRoute extends Route { let roles; let totalItems = 0; + let rolesExist = false; if (this.can.can('list model', scope, { collection: 'roles' })) { roles = await this.store.query('role', { query: { search, filters }, @@ -49,8 +50,8 @@ export default class ScopesScopeRolesIndexRoute extends Route { pageSize, }); totalItems = roles.meta?.totalItems; + rolesExist = await this.getRolesExist(scope_id, totalItems); } - const rolesExist = await this.getRolesExist(scope_id, totalItems); return { roles, rolesExist, totalItems }; } diff --git a/ui/admin/app/routes/scopes/scope/users/index.js b/ui/admin/app/routes/scopes/scope/users/index.js index f41ad10b8..3e39061e2 100644 --- a/ui/admin/app/routes/scopes/scope/users/index.js +++ b/ui/admin/app/routes/scopes/scope/users/index.js @@ -43,6 +43,7 @@ export default class ScopesScopeUsersIndexRoute extends Route { let users; let totalItems = 0; + let usersExist = false; if (this.can.can('list model', scope, { collection: 'users' })) { users = await this.store.query('user', { query: { search, filters }, @@ -50,8 +51,8 @@ export default class ScopesScopeUsersIndexRoute extends Route { pageSize, }); totalItems = users.meta?.totalItems; + usersExist = await this.getUsersExist(scope_id, totalItems); } - const usersExist = await this.getUsersExist(scope_id, totalItems); return { users, usersExist, totalItems }; }