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
@@ -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