feat: 🎸 allow session recording deletion (#2132)
* feat: 🎸 allow session recording deletion
This commit is contained in:
1 parent
4db8b8e1e7
commit
786e6130cd
9 files changed
+136
-4
No files matched your search
@@ -21,6 +21,14 @@ export default class SessionRecordingAbility extends ModelAbility {
|
||||
return !this.model.isUnknown && super.canRead;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only "known" session recording types may be deleted.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get canDelete() {
|
||||
return !this.model.isUnknown && super.canDelete && this.model.isAvailable;
|
||||
}
|
||||
|
||||
get canDownload() {
|
||||
return this.hasAuthorizedAction('download');
|
||||
}
|
||||
|
||||
@@ -798,6 +798,8 @@ function routes() {
|
||||
},
|
||||
);
|
||||
|
||||
this.del('/session-recordings/:id');
|
||||
|
||||
/* Uncomment the following line and the Response import above
|
||||
* Then change the response code to simulate error responses.
|
||||
* this.get('/scopes', () => new Response(505));
|
||||
|
||||
@@ -60,6 +60,7 @@ export default factory.extend({
|
||||
'read',
|
||||
'download',
|
||||
'reapply-storage-policy',
|
||||
'delete',
|
||||
],
|
||||
|
||||
withNonExistingUserAndTarget: trait({
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import {
|
||||
STATE_SESSION_RECORDING_AVAILABLE,
|
||||
STATE_SESSION_RECORDING_STARTED,
|
||||
TYPE_SESSION_RECORDING_SSH,
|
||||
} from 'api/models/session-recording';
|
||||
|
||||
module('Unit | Ability | session-recording', function (hooks) {
|
||||
setupTest(hooks);
|
||||
@@ -49,4 +54,36 @@ module('Unit | Ability | session-recording', function (hooks) {
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('can delete a session with proper authorization and in available state', function (assert) {
|
||||
const recordingNotinAvaialableState = store.createRecord(
|
||||
'session-recording',
|
||||
{
|
||||
authorized_actions: ['delete'],
|
||||
type: TYPE_SESSION_RECORDING_SSH,
|
||||
state: STATE_SESSION_RECORDING_STARTED,
|
||||
},
|
||||
);
|
||||
const recordingInAvailableState = store.createRecord('session-recording', {
|
||||
authorized_actions: ['delete'],
|
||||
type: TYPE_SESSION_RECORDING_SSH,
|
||||
state: STATE_SESSION_RECORDING_AVAILABLE,
|
||||
});
|
||||
assert.false(
|
||||
canService.can('delete session-recording', recordingNotinAvaialableState),
|
||||
);
|
||||
assert.true(
|
||||
canService.can('delete session-recording', recordingInAvailableState),
|
||||
);
|
||||
});
|
||||
|
||||
test('can re-apply Storage policy with proper authorization', function (assert) {
|
||||
const recording = store.createRecord('session', {
|
||||
authorized_actions: ['reapply-storage-policy'],
|
||||
});
|
||||
|
||||
assert.true(
|
||||
canService.can('reapplyStoragePolicy session-recording', recording),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -354,6 +354,8 @@ session-recording:
|
||||
up: '{bytes} up'
|
||||
down: '{bytes} down'
|
||||
duration: '{time} duration'
|
||||
questions:
|
||||
delete: Are you sure you want to delete this recording?
|
||||
connection:
|
||||
title: Connection
|
||||
title_index: Connection {index}
|
||||
@@ -949,6 +951,7 @@ policy:
|
||||
apply: Apply the storage policy to this scope and its children
|
||||
new: Add a new storage policy
|
||||
update: Re-apply storage policy
|
||||
delete_recording: Delete recording
|
||||
questions:
|
||||
detach: Are you sure you want to detach this storage policy?
|
||||
messages:
|
||||
|
||||
@@ -29,4 +29,14 @@ export default class OverrideSessionRecordingAbility extends SessionRecordingAbi
|
||||
? this.hasAuthorizedAction('reapply-storage-policy')
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This override ensures that session recordings may be deleted only if the
|
||||
* session-recording feature flag is enabled.
|
||||
*/
|
||||
get canDelete() {
|
||||
return this.features.isEnabled('ssh-session-recording')
|
||||
? super.canDelete
|
||||
: false;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,10 @@
|
||||
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
|
||||
@@ -68,4 +72,19 @@ 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();
|
||||
}
|
||||
}
|
||||
+15
-2
@@ -16,8 +16,12 @@
|
||||
{{#if
|
||||
(can 'reapplyStoragePolicy session-recording' @model.sessionRecording)
|
||||
}}
|
||||
<Hds::Dropdown data-test-manage-dropdown as |dd|>
|
||||
<dd.ToggleButton @text={{t 'actions.manage'}} @color='secondary' />
|
||||
<Hds::Dropdown as |dd|>
|
||||
<dd.ToggleButton
|
||||
data-test-manage-dropdown
|
||||
@text={{t 'actions.manage'}}
|
||||
@color='secondary'
|
||||
/>
|
||||
|
||||
<dd.Interactive
|
||||
@text={{t 'resources.policy.actions.update'}}
|
||||
@@ -26,6 +30,15 @@
|
||||
(route-action 'reapplyStoragepolicy' @model.sessionRecording)
|
||||
}}
|
||||
/>
|
||||
{{#if (can 'delete session-recording' @model.sessionRecording)}}
|
||||
<dd.Separator />
|
||||
<dd.Interactive
|
||||
data-test-manage-dropdown-delete
|
||||
@color='critical'
|
||||
@text={{t 'resources.policy.actions.delete_recording'}}
|
||||
{{on 'click' (route-action 'delete' @model.sessionRecording)}}
|
||||
/>
|
||||
{{/if}}
|
||||
</Hds::Dropdown>
|
||||
{{/if}}
|
||||
</page.actions>
|
||||
|
||||
+41
-2
@@ -17,7 +17,10 @@ module(
|
||||
setupMirage(hooks);
|
||||
|
||||
let featuresService;
|
||||
let getRecordingCount;
|
||||
|
||||
const DELETE_DROPDOWN_SELECTOR = '[data-test-manage-dropdown-delete]';
|
||||
const DROPDOWN_SELECTOR = '[data-test-manage-dropdown]';
|
||||
// Instances
|
||||
const instances = {
|
||||
scopes: {
|
||||
@@ -43,8 +46,14 @@ module(
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
});
|
||||
instances.scopes.targetModel = this.server.create('target', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
instances.sessionRecording = this.server.create('session-recording', {
|
||||
scope: instances.scopes.global,
|
||||
create_time_values: {
|
||||
target: instances.scopes.targetModel.attrs,
|
||||
},
|
||||
});
|
||||
instances.connectionRecording = this.server.create(
|
||||
'connection-recording',
|
||||
@@ -59,6 +68,9 @@ module(
|
||||
urls.sessionRecordings = `${urls.globalScope}/session-recordings`;
|
||||
urls.sessionRecording = `${urls.sessionRecordings}/${instances.sessionRecording.id}/channels-by-connection`;
|
||||
urls.channelRecording = `${urls.sessionRecording}/${instances.channelRecording.id}`;
|
||||
getRecordingCount = () =>
|
||||
this.server.schema.sessionRecordings.all().models.length;
|
||||
|
||||
featuresService = this.owner.lookup('service:features');
|
||||
authenticateSession({});
|
||||
});
|
||||
@@ -157,7 +169,7 @@ module(
|
||||
);
|
||||
await visit(urls.sessionRecording);
|
||||
|
||||
assert.dom('[data-test-manage-dropdown]').doesNotExist();
|
||||
assert.dom(DROPDOWN_SELECTOR).doesNotExist();
|
||||
});
|
||||
|
||||
test('user can view manage dropdown with proper authorization', async function (assert) {
|
||||
@@ -166,7 +178,34 @@ module(
|
||||
|
||||
await visit(urls.sessionRecording);
|
||||
|
||||
assert.dom('[data-test-manage-dropdown]').isVisible();
|
||||
assert.dom(DROPDOWN_SELECTOR).isVisible();
|
||||
});
|
||||
|
||||
test('user can delete a recording with proper authorization', async function (assert) {
|
||||
// Visit channel
|
||||
const count = getRecordingCount();
|
||||
featuresService.enable('ssh-session-recording');
|
||||
assert.true(
|
||||
instances.sessionRecording.authorized_actions.includes('delete'),
|
||||
);
|
||||
await visit(urls.sessionRecording);
|
||||
await click(DROPDOWN_SELECTOR);
|
||||
|
||||
await click(DELETE_DROPDOWN_SELECTOR);
|
||||
assert.strictEqual(currentURL(), urls.sessionRecordings);
|
||||
|
||||
assert.strictEqual(getRecordingCount(), count - 1);
|
||||
});
|
||||
|
||||
test('user cannot delete a recording without proper authorization', async function (assert) {
|
||||
// Visit channel
|
||||
featuresService.enable('ssh-session-recording');
|
||||
instances.sessionRecording.authorized_actions =
|
||||
instances.sessionRecording.authorized_actions.filter(
|
||||
(item) => item !== 'delete',
|
||||
);
|
||||
await visit(urls.sessionRecording);
|
||||
assert.dom(DELETE_DROPDOWN_SELECTOR).doesNotExist();
|
||||
});
|
||||
|
||||
test('both retain until and delete after can be seen with proper authorization', async function (assert) {
|
||||
|
||||
Reference in new issue
Block a user