feat: 🎸 add getAsciicast permission to channel route & template (#221)

✅ Closes: ICU-8695
This commit is contained in:
Cameron Perera authored and GitHub committed 2023-04-26 13:41:41 -05:00
1 parent 2d5323b07a
commit 451fcdbfeb
5 files changed
+98 -6

No files matched your search

+1
View File
@@ -43,6 +43,7 @@ descriptions:
cluster-url-initialization: To get started, please enter your cluster URL
create-but-not-list: You do not have permission to list {resource}, but you can create new instances.
neither-list-nor-create: You do not have permission to list or create {resource}.
cannot-download: You do not have permission to download and playback {resource}.
no-results: We found no matching records.
choose-a-provider: There are several built-in plugins for the most common providers. You can choose from one of the included plugins or use a custom plugin.
provider: This is the provider for this host catalog. The format of the host set filters are specific to each provider.
@@ -231,6 +231,13 @@ session-recording:
title: Channel
title_plural: Channels
details: Channel details
messages:
none:
title: Channel Playback
missing:
title: We can't play back this channel because the file is missing
description: This likely means the connected storage bucket is misconfigured or the file was deleted.
link: Retrieving lost session recordings
player:
back-navigation: Back to channels
session:
@@ -4,9 +4,11 @@ import { inject as service } from '@ember/service';
export default class ScopesScopeSessionRecordingsSessionRecordingChannelsByConnectionChannelRoute extends Route {
// =services
@service store;
@service can;
// =methods
async model({ channel_id }) {
let asciicast;
const { sessionRecording, storageBucket } = await this.modelFor(
'scopes.scope.session-recordings.session-recording'
);
@@ -14,7 +16,10 @@ export default class ScopesScopeSessionRecordingsSessionRecordingChannelsByConne
'channel-recording',
channel_id
);
const asciicast = await channelRecording.getAsciicast();
if (this.can.can('getAsciicast channel-recording', channelRecording)) {
asciicast = await channelRecording.getAsciicast();
}
return {
channelRecording,
@@ -13,11 +13,55 @@
<page.body>
<Layout::Sidebar as |sb|>
<sb.Body>
<SessionRecording::Player
@asciiCast={{@model.asciicast}}
@route='scopes.scope.session-recordings.session-recording'
@model={{@model.sessionRecording.id}}
/>
{{#if @model.asciicast}}
<SessionRecording::Player
@asciiCast={{@model.asciicast}}
@route='scopes.scope.session-recordings.session-recording'
@model={{@model.sessionRecording.id}}
/>
{{else}}
<Hds::ApplicationState as |A|>
{{#if
(can 'getAsciicast channel-recording' @model.channelRecording)
}}
{{! Was not able to downlaod asciicast }}
<A.Header
@title={{t
'resources.session-recording.channel.messages.missing.title'
}}
/>
<A.Body
@text={{t
'resources.session-recording.channel.messages.missing.description'
}}
/>
<A.Footer as |F|>
<F.Link::Standalone
@icon='learn-link'
@text={{t
'resources.session-recording.channel.messages.missing.link'
}}
@href='/'
/>
</A.Footer>
{{else}}
{{! Not authorized to downlaod asciicast }}
<A.Header
@title={{t
'resources.session-recording.channel.messages.none.title'
}}
/>
<A.Body
@text={{t
'descriptions.cannot-download'
resource=(t
'resources.session-recording.channel.title_plural'
)
}}
/>
{{/if}}
</Hds::ApplicationState>
{{/if}}
</sb.Body>
<sb.Sidebar>
@@ -60,6 +60,41 @@ module(
assert.strictEqual(currentURL(), urls.connectionRecording);
});
test('user can view recording with proper authorization', async function (assert) {
assert.expect(1);
// Visit channel
await visit(urls.connectionRecording);
// if authorized player will render
assert.dom('.session-recording-player').exists();
});
test('user cannot view recording without proper authorization: channel mime_types', async function (assert) {
assert.expect(1);
instances.channelRecording.mime_types = [];
// Visit channel
await visit(urls.connectionRecording);
// if unauthorized player will not render
assert.dom('.session-recording-player').doesNotExist();
});
test('user cannot view recording without proper authorization: session recording download action', async function (assert) {
assert.expect(1);
instances.sessionRecording.authorized_actions =
instances.sessionRecording.authorized_actions.filter(
(item) => item !== 'download'
);
// Visit channel
await visit(urls.connectionRecording);
// if unauthorized player will not render
assert.dom('.session-recording-player').doesNotExist();
});
test('user can navigate back to session recording screen', async function (assert) {
assert.expect(1);
// Visit channel