diff --git a/ui/admin/app/controllers/scopes/scope/session-recordings/session-recording/channels-by-connection/index.js b/ui/admin/app/controllers/scopes/scope/session-recordings/session-recording/channels-by-connection/index.js index e730af33b..8706e63d9 100644 --- a/ui/admin/app/controllers/scopes/scope/session-recordings/session-recording/channels-by-connection/index.js +++ b/ui/admin/app/controllers/scopes/scope/session-recordings/session-recording/channels-by-connection/index.js @@ -4,15 +4,26 @@ */ import Controller from '@ember/controller'; +import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; +import { loading } from 'ember-loading'; +import { confirm } from 'core/decorators/confirm'; +import { notifySuccess, notifyError } from 'core/decorators/notify'; import { STATE_SESSION_RECORDING_STARTED, STATE_SESSION_RECORDING_UNKNOWN, } from 'api/models/session-recording'; export default class ScopesScopeSessionRecordingsSessionRecordingChannelsByConnectionIndexController extends Controller { + // =services + + @service router; + + // =attributes + /** * Returns true if the session recording has started - * but has not started any connections + * but has not started any connections. * @type {boolean} */ get isSessionInprogressWithNoConnections() { @@ -24,7 +35,7 @@ export default class ScopesScopeSessionRecordingsSessionRecordingChannelsByConne /** * Returns true if the session recording state is unknown - * and has no connections + * and has no connections. * @type {boolean} */ get isSessionUnknownWithNoConnections() { @@ -33,4 +44,42 @@ export default class ScopesScopeSessionRecordingsSessionRecordingChannelsByConne this.model?.sessionRecording?.state === STATE_SESSION_RECORDING_UNKNOWN ); } + + // =actions + + /** + * Reapplies storage policy dates to session recording. + * @param {SessionRecordingModel} + */ + @action + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess(({ end_time }) => + !end_time + ? 'resources.policy.messages.later' + : 'resources.policy.messages.reapply', + ) + async reapplyStoragePolicy(sessionRecording) { + try { + await sessionRecording.reapplyStoragePolicy(); + } catch (e) { + await this.router.replaceWith('scopes.scope.session-recordings'); + this.router.refresh(); + throw new Error(e); + } + } + + /** + * Deletes the session recording. + * @param {SessionRecording} recording + */ + @action + @loading + @confirm('resources.session-recording.questions.delete') + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.delete-success') + async delete(sessionRecording) { + await sessionRecording.destroyRecord(); + await this.router.replaceWith('scopes.scope.session-recordings'); + this.router.refresh(); + } } diff --git a/ui/admin/app/routes/scopes/scope/session-recordings.js b/ui/admin/app/routes/scopes/scope/session-recordings.js index 7218479b1..717c74c85 100644 --- a/ui/admin/app/routes/scopes/scope/session-recordings.js +++ b/ui/admin/app/routes/scopes/scope/session-recordings.js @@ -6,10 +6,6 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; import orderBy from 'lodash/orderBy'; -import { loading } from 'ember-loading'; -import { confirm } from 'core/decorators/confirm'; -import { action } from '@ember/object'; -import { notifySuccess, notifyError } from 'core/decorators/notify'; export default class ScopesScopeSessionRecordingsRoute extends Route { // =services @@ -72,19 +68,4 @@ export default class ScopesScopeSessionRecordingsRoute extends Route { }; } } - - /** - * Deletes the session recording - * @param {SessionRecording} recording - */ - @action - @loading - @confirm('resources.session-recording.questions.delete') - @notifyError(({ message }) => message, { catch: true }) - @notifySuccess('notifications.delete-success') - async delete(recording) { - await recording.destroyRecord(); - await this.router.replaceWith('scopes.scope.session-recordings'); - this.router.refresh(); - } } diff --git a/ui/admin/app/routes/scopes/scope/session-recordings/session-recording/channels-by-connection.js b/ui/admin/app/routes/scopes/scope/session-recordings/session-recording/channels-by-connection.js index c0d9b9313..094e1b979 100644 --- a/ui/admin/app/routes/scopes/scope/session-recordings/session-recording/channels-by-connection.js +++ b/ui/admin/app/routes/scopes/scope/session-recordings/session-recording/channels-by-connection.js @@ -5,8 +5,6 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; -import { action } from '@ember/object'; -import { notifySuccess, notifyError } from 'core/decorators/notify'; export default class ScopesScopeSessionRecordingsSessionRecordingChannelsByConnectionRoute extends Route { // =services @@ -50,24 +48,4 @@ export default class ScopesScopeSessionRecordingsSessionRecordingChannelsByConne storageBucket, }; } - /** - * Reapplies storage policy dates to session recording - * @param {SessionRecordingModel} - */ - @action - @notifyError(({ message }) => message, { catch: true }) - @notifySuccess(({ end_time }) => - !end_time - ? 'resources.policy.messages.later' - : 'resources.policy.messages.reapply', - ) - async reapplyStoragepolicy(sessionRecording) { - try { - await sessionRecording.reapplyStoragePolicy(); - } catch (e) { - await this.router.replaceWith('scopes.scope.session-recordings'); - this.router.refresh(); - throw new Error(e); - } - } } diff --git a/ui/admin/app/templates/scopes/scope/session-recordings/session-recording/channels-by-connection/index.hbs b/ui/admin/app/templates/scopes/scope/session-recordings/session-recording/channels-by-connection/index.hbs index aa19d71fd..70e76c213 100644 --- a/ui/admin/app/templates/scopes/scope/session-recordings/session-recording/channels-by-connection/index.hbs +++ b/ui/admin/app/templates/scopes/scope/session-recordings/session-recording/channels-by-connection/index.hbs @@ -25,10 +25,7 @@ {{#if (can 'delete session-recording' @model.sessionRecording)}} @@ -36,7 +33,7 @@ data-test-manage-dropdown-delete @color='critical' @text={{t 'resources.policy.actions.delete_recording'}} - {{on 'click' (route-action 'delete' @model.sessionRecording)}} + {{on 'click' (fn this.delete @model.sessionRecording)}} /> {{/if}} diff --git a/ui/admin/tests/unit/controllers/scopes/scope/session-recordings/index-test.js b/ui/admin/tests/unit/controllers/scopes/scope/session-recordings/index-test.js index 636c15d38..84215df6b 100644 --- a/ui/admin/tests/unit/controllers/scopes/scope/session-recordings/index-test.js +++ b/ui/admin/tests/unit/controllers/scopes/scope/session-recordings/index-test.js @@ -4,7 +4,7 @@ */ import { module, test } from 'qunit'; -import { setupTest } from 'admin/tests/helpers'; +import { setupTest } from 'ember-qunit'; module( 'Unit | Controller | scopes/scope/session-recordings/index', diff --git a/ui/admin/tests/unit/controllers/scopes/scope/session-recordings/session-recording/channels-by-connection/index-test.js b/ui/admin/tests/unit/controllers/scopes/scope/session-recordings/session-recording/channels-by-connection/index-test.js index d12826bd2..a8e983d76 100644 --- a/ui/admin/tests/unit/controllers/scopes/scope/session-recordings/session-recording/channels-by-connection/index-test.js +++ b/ui/admin/tests/unit/controllers/scopes/scope/session-recordings/session-recording/channels-by-connection/index-test.js @@ -4,7 +4,9 @@ */ import { module, test } from 'qunit'; -import { setupTest } from 'admin/tests/helpers'; +import { setupTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { authenticateSession } from 'ember-simple-auth/test-support'; import { STATE_SESSION_RECORDING_AVAILABLE, STATE_SESSION_RECORDING_STARTED, @@ -15,13 +17,36 @@ module( 'Unit | Controller | scopes/scope/session-recordings/session-recording/channels-by-connection/index', function (hooks) { setupTest(hooks); + setupMirage(hooks); - test('isSessionInprogressWithNoConnections returns true if session has started with no connections', function (assert) { - const store = this.owner.lookup('service:store'); - const controller = this.owner.lookup( + let store; + let controller; + let getSessionRecordingCount; + + const instances = { + scopes: { + global: null, + }, + sessionRecording: null, + }; + + hooks.beforeEach(function () { + authenticateSession({}); + store = this.owner.lookup('service:store'); + controller = this.owner.lookup( 'controller:scopes/scope/session-recordings/session-recording/channels-by-connection/index', ); + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.sessionRecording = this.server.create('session-recording', { + scope: instances.scopes.global, + }); + + getSessionRecordingCount = () => + this.server.schema.sessionRecordings.all().models.length; + }); + + test('isSessionInprogressWithNoConnections returns true if session has started with no connections', function (assert) { const sessionRecording = store.createRecord('session-recording', { state: STATE_SESSION_RECORDING_STARTED, connection_recordings: [], @@ -32,11 +57,6 @@ module( }); test('isSessionInprogressWithNoConnections returns false if session has started and has connections', function (assert) { - const store = this.owner.lookup('service:store'); - const controller = this.owner.lookup( - 'controller:scopes/scope/session-recordings/session-recording/channels-by-connection/index', - ); - const sessionRecording = store.createRecord('session-recording', { state: STATE_SESSION_RECORDING_STARTED, connection_recordings: [store.createRecord('connection-recording')], @@ -47,11 +67,6 @@ module( }); test('isSessionInprogressWithNoConnections returns false if session is complete and has connections', function (assert) { - const store = this.owner.lookup('service:store'); - const controller = this.owner.lookup( - 'controller:scopes/scope/session-recordings/session-recording/channels-by-connection/index', - ); - const sessionRecording = store.createRecord('session-recording', { state: STATE_SESSION_RECORDING_AVAILABLE, connection_recordings: [store.createRecord('connection-recording')], @@ -62,11 +77,6 @@ module( }); test('isSessionUnknownWithNoConnections returns true if session is unknown with no connections', function (assert) { - const store = this.owner.lookup('service:store'); - const controller = this.owner.lookup( - 'controller:scopes/scope/session-recordings/session-recording/channels-by-connection/index', - ); - const sessionRecording = store.createRecord('session-recording', { state: STATE_SESSION_RECORDING_UNKNOWN, connection_recordings: [], @@ -77,11 +87,6 @@ module( }); test('isSessionUnknownWithNoConnections returns false if session is unknown and has connections', function (assert) { - const store = this.owner.lookup('service:store'); - const controller = this.owner.lookup( - 'controller:scopes/scope/session-recordings/session-recording/channels-by-connection/index', - ); - const sessionRecording = store.createRecord('session-recording', { state: STATE_SESSION_RECORDING_UNKNOWN, connection_recordings: [store.createRecord('connection-recording')], @@ -92,11 +97,6 @@ module( }); test('isSessionUnknownWithNoConnections returns false if session is complete and has connections', function (assert) { - const store = this.owner.lookup('service:store'); - const controller = this.owner.lookup( - 'controller:scopes/scope/session-recordings/session-recording/channels-by-connection/index', - ); - const sessionRecording = store.createRecord('session-recording', { state: STATE_SESSION_RECORDING_AVAILABLE, connection_recordings: [store.createRecord('connection-recording')], @@ -105,5 +105,29 @@ module( assert.false(controller.isSessionUnknownWithNoConnections); }); + + test('delete action destroys specified model', async function (assert) { + const sessionRecording = await store.findRecord( + 'session-recording', + instances.sessionRecording.id, + ); + const sessionRecordingCount = getSessionRecordingCount(); + + await controller.delete(sessionRecording); + + assert.strictEqual(getSessionRecordingCount(), sessionRecordingCount - 1); + }); + + test('reapplyStoragePolicy action applies storage policy to session recording', async function (assert) { + const sessionRecording = await store.findRecord( + 'session-recording', + instances.sessionRecording.id, + ); + const deleteAfter = sessionRecording.delete_after; + + await controller.reapplyStoragePolicy(sessionRecording); + + assert.notEqual(sessionRecording.delete_after, deleteAfter); + }); }, );