From 713ffd8d1b3801629d655a1b000dd04016fcd684 Mon Sep 17 00:00:00 2001 From: Cameron Perera Date: Wed, 3 Apr 2024 14:56:55 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20add=20parentScope.id=20to?= =?UTF-8?q?=20refresh=20action=20for=20sessions=20(#2215)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 add parentScope.id to refresh action for sessions * refactor: 💡 remove scope_id from users and targets query --- .../app/routes/scopes/scope/sessions/index.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/ui/admin/app/routes/scopes/scope/sessions/index.js b/ui/admin/app/routes/scopes/scope/sessions/index.js index 7b516c272..76bfd4475 100644 --- a/ui/admin/app/routes/scopes/scope/sessions/index.js +++ b/ui/admin/app/routes/scopes/scope/sessions/index.js @@ -49,7 +49,7 @@ export default class ScopesScopeSessionsIndexRoute extends Route { * @return {Promise{[{sessions: [SessionModel], allSessions: [SessionModel], associatedUsers: [UserModel], associatedTargets: [TargetModel], totalItems: number}]}} */ async model({ search, users, targets, status, page, pageSize }) { - const { id: scope_id, scope: parentScope } = this.modelFor('scopes.scope'); + const { id: scope_id } = this.modelFor('scopes.scope'); const filters = { scope_id: [{ equals: scope_id }], status: [], @@ -80,10 +80,10 @@ export default class ScopesScopeSessionsIndexRoute extends Route { await this.getAllSessions(scope_id); } if (!this.associatedUsers) { - await this.getAssociatedUsers(parentScope.id); + await this.getAssociatedUsers(); } if (!this.associatedTargets) { - await this.getAssociatedTargets(scope_id); + await this.getAssociatedTargets(); } return { @@ -113,17 +113,14 @@ export default class ScopesScopeSessionsIndexRoute extends Route { * Get all the users but only load them once when entering the route. * @returns {Promise} */ - async getAssociatedUsers(parentScopeId) { + async getAssociatedUsers() { const uniqueSessionUserIds = new Set( this.allSessions .filter((session) => session.user_id) .map((session) => session.user_id), ); - // Users can belong to the global scope or the org scope - // the project is under so we need to query for both. const filters = { id: { values: [] }, - scope_id: [{ equals: 'global' }, { equals: parentScopeId }], }; uniqueSessionUserIds.forEach((userId) => { filters.id.values.push({ equals: userId }); @@ -136,16 +133,15 @@ export default class ScopesScopeSessionsIndexRoute extends Route { /** * Get all the targets but only load them once when entering the route. - * @param scope_id * @returns {Promise} */ - async getAssociatedTargets(scope_id) { + async getAssociatedTargets() { const uniqueSessionTargetIds = new Set( this.allSessions .filter((session) => session.target_id) .map((session) => session.target_id), ); - const filters = { id: { values: [] }, scope_id: [{ equals: scope_id }] }; + const filters = { id: { values: [] } }; uniqueSessionTargetIds.forEach((targetId) => { filters.id.values.push({ equals: targetId }); }); @@ -169,7 +165,7 @@ export default class ScopesScopeSessionsIndexRoute extends Route { await this.getAllSessions(scope_id); await this.getAssociatedUsers(); - await this.getAssociatedTargets(scope_id); + await this.getAssociatedTargets(); return super.refresh(...arguments); }