From c11aa3d4f2176d54fc029091c2a5f0d4db57b897 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 19 Apr 2023 14:06:18 -0700 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20loading=20of=20bucke?= =?UTF-8?q?ts=20in=20recordings=20routes=20could=20fail=20(#208)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 💡 loading of buckets in recordings routes could fail * Update ui/admin/app/controllers/scopes/scope/session-recordings/index.js Co-authored-by: Dharini Jeeva * Update ui/admin/app/controllers/scopes/scope/session-recordings/index.js Co-authored-by: Dharini Jeeva --------- Co-authored-by: Dharini Jeeva --- .../scopes/scope/session-recordings/index.js | 4 ++-- .../routes/scopes/scope/session-recordings.js | 20 ++++++++++++++----- .../session-recordings/session-recording.js | 17 ++++++++++------ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/ui/admin/app/controllers/scopes/scope/session-recordings/index.js b/ui/admin/app/controllers/scopes/scope/session-recordings/index.js index ee4b8092b..6d9f05688 100644 --- a/ui/admin/app/controllers/scopes/scope/session-recordings/index.js +++ b/ui/admin/app/controllers/scopes/scope/session-recordings/index.js @@ -6,7 +6,7 @@ export default class ScopesScopeSessionRecordingsIndexController extends Control * @type {boolean} */ get hasSessionRecordings() { - return this.model.sessionRecordings.length > 0; + return this.model?.sessionRecordings?.length; } /** @@ -14,6 +14,6 @@ export default class ScopesScopeSessionRecordingsIndexController extends Control * @type {boolean} */ get hasSessionRecordingsConfigured() { - return this.model.storageBuckets.length > 0; + return this.model?.storageBuckets?.length; } } diff --git a/ui/admin/app/routes/scopes/scope/session-recordings.js b/ui/admin/app/routes/scopes/scope/session-recordings.js index e18a61020..4715a8a71 100644 --- a/ui/admin/app/routes/scopes/scope/session-recordings.js +++ b/ui/admin/app/routes/scopes/scope/session-recordings.js @@ -23,18 +23,28 @@ export default class ScopesScopeSessionRecordingsRoute extends Route { * @return {{sessionRecordings: Array, storageBuckets: Array}} */ async model() { + let storageBuckets; + const scope = this.modelFor('scopes.scope'); - // if (this.can.can('list session-recording', scope, { collection: 'session-recordings' })) { const { id: scope_id } = scope; + // if (this.can.can('list session-recording', scope, { collection: 'session-recordings' })) { const sessionRecordings = await this.store.query('session-recording', { scope_id, recursive: true, }); - const storageBuckets = await this.store.query('storage-bucket', { - scope_id, - recursive: true, - }); + + // Storage buckets could fail for a number of reasons, including that + // the user isn't authorized to access them. + try { + storageBuckets = await this.store.query('storage-bucket', { + scope_id, + recursive: true, + }); + } catch (e) { + // no op + } + return { sessionRecordings, storageBuckets, diff --git a/ui/admin/app/routes/scopes/scope/session-recordings/session-recording.js b/ui/admin/app/routes/scopes/scope/session-recordings/session-recording.js index 7945ba9d1..8e28a9802 100644 --- a/ui/admin/app/routes/scopes/scope/session-recordings/session-recording.js +++ b/ui/admin/app/routes/scopes/scope/session-recordings/session-recording.js @@ -26,12 +26,17 @@ export default class ScopesScopeSessionRecordingsSessionRecordingRoute extends R 'session-recording', session_recording_id ); - if (sessionRecording.target?.storage_bucket_id) { - const { storage_bucket_id } = sessionRecording.target; - storageBucket = await this.store.findRecord( - 'storage-bucket', - storage_bucket_id - ); + + try { + if (sessionRecording.target?.storage_bucket_id) { + const { storage_bucket_id } = sessionRecording.target; + storageBucket = await this.store.findRecord( + 'storage-bucket', + storage_bucket_id + ); + } + } catch (e) { + // no op } const sortedConnections = sessionRecording.connection_recordings .sortBy('start_time')