diff --git a/addons/api/addon/models/session.js b/addons/api/addon/models/session.js
index b37f08fc2..bde91cf3c 100644
--- a/addons/api/addon/models/session.js
+++ b/addons/api/addon/models/session.js
@@ -1,7 +1,18 @@
import GeneratedSessionModel from '../generated/models/session';
+import { computed } from '@ember/object';
export default class SessionModel extends GeneratedSessionModel {
+ // =attributes
+
+ /**
+ * @type {boolean}
+ */
+ @computed('status')
+ get isCancelable() {
+ return this.status?.match(/(active)|(pending)/i);
+ }
+
// =methods
/**
diff --git a/addons/api/tests/unit/models/session-test.js b/addons/api/tests/unit/models/session-test.js
index 2d373a2f6..4100aeac2 100644
--- a/addons/api/tests/unit/models/session-test.js
+++ b/addons/api/tests/unit/models/session-test.js
@@ -4,10 +4,26 @@ import { setupTest } from 'ember-qunit';
module('Unit | Model | session', function(hooks) {
setupTest(hooks);
- // Replace this with your real tests.
test('it exists', function(assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('session', {});
assert.ok(model);
+ assert.notOk(model.isCancelable);
+ });
+
+ test('it allows cancellation of an active session', function(assert) {
+ let store = this.owner.lookup('service:store');
+ let model = store.createRecord('session', {
+ status: 'active'
+ });
+ assert.ok(model.isCancelable);
+ });
+
+ test('it allows cancellation of a pending session', function(assert) {
+ let store = this.owner.lookup('service:store');
+ let model = store.createRecord('session', {
+ status: 'pending'
+ });
+ assert.ok(model.isCancelable);
});
});
diff --git a/ui/core/app/templates/scopes/scope/projects/project/sessions/index.hbs b/ui/core/app/templates/scopes/scope/projects/project/sessions/index.hbs
index 16fc16a1c..1d69ecf7b 100644
--- a/ui/core/app/templates/scopes/scope/projects/project/sessions/index.hbs
+++ b/ui/core/app/templates/scopes/scope/projects/project/sessions/index.hbs
@@ -47,9 +47,11 @@
{{sessionAggregate.session.status}}
-
- {{t "actions.cancel"}}
-
+ {{#if sessionAggregate.session.isCancelable}}
+
+ {{t "actions.cancel"}}
+
+ {{/if}}
{{/each}}