refactor: 💡 remove route-action usage for session recordings (#2439)
* refactor: 💡 remove route-action usage for session recordings ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12620
This commit is contained in:
1 parent
79b06ee565
commit
a9d110a1b6
6 files changed
+107
-78
No files matched your search
+51
-2
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
-22
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-5
@@ -25,10 +25,7 @@
|
||||
|
||||
<dd.Interactive
|
||||
@text={{t 'resources.policy.actions.update'}}
|
||||
{{on
|
||||
'click'
|
||||
(route-action 'reapplyStoragepolicy' @model.sessionRecording)
|
||||
}}
|
||||
{{on 'click' (fn this.reapplyStoragePolicy @model.sessionRecording)}}
|
||||
/>
|
||||
{{#if (can 'delete session-recording' @model.sessionRecording)}}
|
||||
<dd.Separator />
|
||||
@@ -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}}
|
||||
</Hds::Dropdown>
|
||||
|
||||
@@ -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',
|
||||
|
||||
+53
-29
@@ -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);
|
||||
});
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user