Files
threshold-ui/addons/api/addon/models/session-recording.js
T

72 lines
1.8 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2023-03-16 13:49:04 -04:00
import GeneratedSessionRecordingModel from '../generated/models/session-recording';
import { hasMany } from '@ember-data/model';
import { inject as service } from '@ember/service';
export const TYPE_SESSION_RECORDING_SSH = 'ssh';
export const TYPES_SESSION_RECORDING = Object.freeze([
TYPE_SESSION_RECORDING_SSH,
]);
2023-05-17 12:01:34 -04:00
export const STATE_SESSION_RECORDING_STARTED = 'started';
export const STATE_SESSION_RECORDING_AVAILABLE = 'available';
export const STATE_SESSION_RECORDING_UNKNOWN = 'unknown';
2023-03-16 13:49:04 -04:00
export default class SessionRecordingModel extends GeneratedSessionRecordingModel {
@hasMany('connection-recording', {
async: false,
inverse: 'session_recording',
})
connection_recordings;
2023-03-16 13:49:04 -04:00
@service store;
/**
* True if the session recording type is `ssh`.
* @type {boolean}
*/
get isSSH() {
return this.type === TYPE_SESSION_RECORDING_SSH;
}
/**
* True if the session recording is an unknown type.
* @type {boolean}
*/
get isUnknown() {
return !TYPES_SESSION_RECORDING.includes(this.type);
}
/**
* True if the session recording is in an available state.
* @type {boolean}
*/
get isAvailable() {
return this.state === STATE_SESSION_RECORDING_AVAILABLE;
}
2023-03-30 18:31:30 -07:00
/**
* Returns scope name or scope id from the target that belongs to the session recording.
* @type {string}
*/
get targetScopeDisplayName() {
2023-05-08 14:05:01 -04:00
return (
this.create_time_values?.target?.scope?.name ||
this.create_time_values?.target?.scope?.id
);
}
2023-03-30 18:31:30 -07:00
/**
* Returns the user name or user id that belongs to the session recording.
* @type {string}
*/
get userDisplayName() {
2023-05-08 14:05:01 -04:00
return (
this.create_time_values?.user?.name || this.create_time_values?.user?.id
);
2023-03-30 18:31:30 -07:00
}
2023-03-16 13:49:04 -04:00
}