Files
threshold-ui/addons/api/addon/models/session-recording.js
T
Dharini JeevaandLisbet Alvarez fb9a080d2e feat: reapply storage policies to session recording (#2095)
* refactor: 💡 add global settings link

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12257

* fix: 🐛 route

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12257

* fix: 🐛 comment

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12257

* feat: 🎸 add reapply sp to session recording page

* fix: 🐛 normalize

* feat: 🎸 upates

* fix: 🐛 logs

* fix: 🐛 comment

* test: 💍 add tests

* fix: 🐛 normalizer, style

* fix: 🐛 normalize

* fix: 🐛 normalizw

* fix: 🐛 normalize

* test: 💍 add tests for serializer n normalizer

* fix: 🐛 name

* fix: 🐛 do not delete, send null

* fix: 🐛 return

---------

Co-authored-by: Lisbet Alvarez <lisbet.alvarez@hashicorp.com>
2024-01-17 14:37:54 -05:00

92 lines
2.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
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,
]);
export const STATE_SESSION_RECORDING_STARTED = 'started';
export const STATE_SESSION_RECORDING_AVAILABLE = 'available';
export const STATE_SESSION_RECORDING_UNKNOWN = 'unknown';
export default class SessionRecordingModel extends GeneratedSessionRecordingModel {
@hasMany('connection-recording', {
async: false,
inverse: 'session_recording',
})
connection_recordings;
@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;
}
/**
* Returns scope name or scope id from the target that belongs to the session recording.
* @type {string}
*/
get targetScopeDisplayName() {
return (
this.create_time_values?.target?.scope?.name ||
this.create_time_values?.target?.scope?.id
);
}
/**
* Returns the user name or user id that belongs to the session recording.
* @type {string}
*/
get userDisplayName() {
return (
this.create_time_values?.user?.name || this.create_time_values?.user?.id
);
}
/**
* Reapply policy dates via the `reapply-staorage-policy` method.
* @param {object} options
* @param {object} options.adapterOptions
* @return {Promise}
*/
reapplyStoragePolicy(options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'reapply-storage-policy',
};
return this.save({
...options,
adapterOptions: {
...defaultAdapterOptions,
...options.adapterOptions,
},
});
}
}