refactor: 💡 loading of buckets in recordings routes could fail (#208)

* 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 <dharini@hashicorp.com>

* Update ui/admin/app/controllers/scopes/scope/session-recordings/index.js

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>

---------

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>
This commit is contained in:
Randall MoreyandDharini Jeeva authored and GitHub committed 2023-04-19 14:06:18 -07:00
1 parent 26d676f134
commit c11aa3d4f2
3 files changed
+28 -13

No files matched your search

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