refactor: 💡 Add channel ability for asciicasts (#174)
This commit is contained in:
1 parent
3bf2620b2c
commit
62ec3fe914
14 files changed
+1783
-860
No files matched your search
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import ModelAbility from './model';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
/**
|
||||
* Provides abilities for channel recordings.
|
||||
*/
|
||||
export default class ChannelRecordingAbility extends ModelAbility {
|
||||
// =services
|
||||
@service abilities;
|
||||
|
||||
// =permissions
|
||||
get canDownloadAsciicast() {
|
||||
const sessionRecording = this.model.connection_recording.session_recording;
|
||||
const sessionRecordingAbility = this.abilities.abilityFor(
|
||||
'session-recording',
|
||||
sessionRecording
|
||||
);
|
||||
|
||||
return this.model.isAsciicast && sessionRecordingAbility.canDownload;
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ export default class SessionRecordingAbility extends ModelAbility {
|
||||
);
|
||||
}
|
||||
|
||||
get canDownloadAsciiCast() {
|
||||
get canDownload() {
|
||||
return this.model.isSSH && this.hasAuthorizedAction('download');
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import ApplicationAdapter from './application';
|
||||
import { MIME_TYPE_ASCIICAST } from 'api/models/channel-recording';
|
||||
|
||||
export default class SessionRecordingAdapter extends ApplicationAdapter {
|
||||
/**
|
||||
@@ -49,7 +50,7 @@ export default class SessionRecordingAdapter extends ApplicationAdapter {
|
||||
getAsciicast(id) {
|
||||
return this.getRecordingDownload({
|
||||
id,
|
||||
mimeType: 'application/x-asciicast',
|
||||
mimeType: MIME_TYPE_ASCIICAST,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,18 @@
|
||||
import GeneratedChannelRecordingModel from '../generated/models/channel-recording';
|
||||
import { belongsTo } from '@ember-data/model';
|
||||
|
||||
export const MIME_TYPE_ASCIICAST = 'application/x-asciicast';
|
||||
|
||||
export default class ChannelRecordingModel extends GeneratedChannelRecordingModel {
|
||||
@belongsTo('connection-recording') connection_recording;
|
||||
@belongsTo('connection-recording', { async: false }) connection_recording;
|
||||
|
||||
/**
|
||||
* True if the channel supports asciicast.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isAsciicast() {
|
||||
return this.mime_types.includes(MIME_TYPE_ASCIICAST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the ascii cast recording for this channel.
|
||||
|
||||
@@ -2,6 +2,6 @@ import GeneratedConnectionRecordingModel from '../generated/models/connection-re
|
||||
import { belongsTo, hasMany } from '@ember-data/model';
|
||||
|
||||
export default class ConnectionRecordingModel extends GeneratedConnectionRecordingModel {
|
||||
@belongsTo('session-recording') session_recording;
|
||||
@hasMany('channel-recording') channel_recordings;
|
||||
@belongsTo('session-recording', { async: false }) session_recording;
|
||||
@hasMany('channel-recording', { async: false }) channel_recordings;
|
||||
}
|
||||
@@ -8,7 +8,7 @@ export const TYPES_SESSION_RECORDING = Object.freeze([
|
||||
]);
|
||||
|
||||
export default class SessionRecordingModel extends GeneratedSessionRecordingModel {
|
||||
@hasMany('connection-recording') connection_recordings;
|
||||
@hasMany('connection-recording', { async: false }) connection_recordings;
|
||||
|
||||
@service store;
|
||||
|
||||
|
||||
Reference in new issue
Block a user