From f2346e7c10af94fed9de86102c4905a09cf15b37 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 29 Jan 2021 22:40:24 +0000 Subject: [PATCH 01/11] chore(deps-dev): bump electron in /ui/desktop/electron-app Bumps [electron](https://github.com/electron/electron) from 10.1.5 to 10.2.0. - [Release notes](https://github.com/electron/electron/releases) - [Changelog](https://github.com/electron/electron/blob/master/docs/breaking-changes.md) - [Commits](https://github.com/electron/electron/compare/v10.1.5...v10.2.0) Signed-off-by: dependabot[bot] --- ui/desktop/electron-app/package.json | 2 +- ui/desktop/electron-app/yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/desktop/electron-app/package.json b/ui/desktop/electron-app/package.json index be09b0414..b7525d364 100644 --- a/ui/desktop/electron-app/package.json +++ b/ui/desktop/electron-app/package.json @@ -29,6 +29,6 @@ "@electron-forge/cli": "6.0.0-beta.53", "@electron-forge/maker-dmg": "^6.0.0-beta.54", "devtron": "^1.4.0", - "electron": "10.1.5" + "electron": "10.2.0" } } diff --git a/ui/desktop/electron-app/yarn.lock b/ui/desktop/electron-app/yarn.lock index 8fc7dfdd3..f45e1a0c4 100644 --- a/ui/desktop/electron-app/yarn.lock +++ b/ui/desktop/electron-app/yarn.lock @@ -1042,10 +1042,10 @@ electron-squirrel-startup@^1.0.0: dependencies: debug "^2.2.0" -electron@10.1.5: - version "10.1.5" - resolved "https://registry.yarnpkg.com/electron/-/electron-10.1.5.tgz#f2b161310f627063e73fbac44efcb35dece83a90" - integrity sha512-fys/KnEfJq05TtMij+lFvLuKkuVH030CHYx03iZrW5DNNLwjE6cW3pysJ420lB0FRSfPjTHBMu2eVCf5TG71zQ== +electron@10.2.0: + version "10.2.0" + resolved "https://registry.yarnpkg.com/electron/-/electron-10.2.0.tgz#4b00f0907b28aca4b93661bb53ce9a4f8ad32201" + integrity sha512-GBUyq8dwUqXPkCTkoID+eZ5Pm9GFlLUd2eSoGe8UOaHeW68SgCf5t75/uGHraQ1OIz/0qniyH5M4ebWEHGppyQ== dependencies: "@electron/get" "^1.0.1" "@types/node" "^12.0.12" From 0d2bb33876369cba61c72f0f00f70e5dd85559f2 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 2 Feb 2021 11:47:00 -0500 Subject: [PATCH 02/11] feat: Add /targets/:target_id route --- ui/desktop/app/router.js | 4 ++- .../scopes/scope/projects/targets/target.js | 35 +++++++++++++++++++ .../scope/projects/targets/target/index.js | 4 +++ .../scopes/scope/projects/targets/index.hbs | 7 +++- .../scopes/scope/projects/targets/target.hbs | 17 +++++++++ .../scope/projects/targets/target/-header.hbs | 4 +++ .../projects/targets/target/-navigation.hbs | 5 +++ .../scope/projects/targets/target/index.hbs | 1 + .../scope/projects/targets/target-test.js | 11 ++++++ .../projects/targets/target/index-test.js | 11 ++++++ 10 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 ui/desktop/app/routes/scopes/scope/projects/targets/target.js create mode 100644 ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js create mode 100644 ui/desktop/app/templates/scopes/scope/projects/targets/target.hbs create mode 100644 ui/desktop/app/templates/scopes/scope/projects/targets/target/-header.hbs create mode 100644 ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs create mode 100644 ui/desktop/app/templates/scopes/scope/projects/targets/target/index.hbs create mode 100644 ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target-test.js create mode 100644 ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/index-test.js diff --git a/ui/desktop/app/router.js b/ui/desktop/app/router.js index bcf4938e5..afd04e391 100644 --- a/ui/desktop/app/router.js +++ b/ui/desktop/app/router.js @@ -13,7 +13,9 @@ Router.map(function () { this.route('method', { path: ':auth_method_id' }); }); this.route('projects', function () { - this.route('targets', function () {}); + this.route('targets', function () { + this.route('target', { path: ':target_id' }, function() {}); + }); this.route('sessions', function() {}); }); }); diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target.js new file mode 100644 index 000000000..5031c8a4a --- /dev/null +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target.js @@ -0,0 +1,35 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeProjectsTargetsTargetRoute extends Route { + // =methods + + /** + * Load a target. + * @param {object} params + * @param {string} params.target_id + * @return {TargetModel} + */ + async model({ target_id }) { + return this.store.findRecord('target', target_id, { reload: true }); + } + + /** + * Renders the target-specific templates for header and navigation + * page sections. + * @override + */ + renderTemplate() { + super.renderTemplate(...arguments); + + this.render('scopes/scope/projects/targets/target/-header', { + into: 'scopes/scope/projects/targets/target', + outlet: 'header', + }); + + this.render('scopes/scope/projects/targets/target/-navigation', { + into: 'scopes/scope/projects/targets/target', + outlet: 'navigation', + }); + + } +} diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js new file mode 100644 index 000000000..2199146f8 --- /dev/null +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js @@ -0,0 +1,4 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeProjectsTargetsTargetIndexRoute extends Route { +} diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/index.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/index.hbs index 8c3c463e5..bee6e9d46 100644 --- a/ui/desktop/app/templates/scopes/scope/projects/targets/index.hbs +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/index.hbs @@ -21,7 +21,12 @@ {{#each @model as |model|}} - {{model.target.name}} + + {{model.target.displayName}} +

{{model.target.description}}

diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target.hbs new file mode 100644 index 000000000..0ca9acc68 --- /dev/null +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target.hbs @@ -0,0 +1,17 @@ +{{page-title @model.displayName}} + + + + + {{outlet "header"}} + + + + {{outlet "navigation"}} + + + + {{outlet}} + + + diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target/-header.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target/-header.hbs new file mode 100644 index 000000000..b6ddb6476 --- /dev/null +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target/-header.hbs @@ -0,0 +1,4 @@ +

+ {{model.displayName}} +

+

{{model.description}}

\ No newline at end of file diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs new file mode 100644 index 000000000..b27314ac2 --- /dev/null +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs @@ -0,0 +1,5 @@ + + + {{t 'resources.host-set.title_plural'}} + + diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target/index.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target/index.hbs new file mode 100644 index 000000000..c24cd6895 --- /dev/null +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target/index.hbs @@ -0,0 +1 @@ +{{outlet}} diff --git a/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target-test.js b/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target-test.js new file mode 100644 index 000000000..7794f4aa7 --- /dev/null +++ b/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects/targets/target', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects/targets/target'); + assert.ok(route); + }); +}); diff --git a/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/index-test.js b/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/index-test.js new file mode 100644 index 000000000..d097986e4 --- /dev/null +++ b/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/index-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects/targets/target/index', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects/targets/target/index'); + assert.ok(route); + }); +}); From 621c8ec2f1179a33e16a0373fd8305bb07255f73 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Wed, 3 Feb 2021 11:20:38 -0500 Subject: [PATCH 03/11] feat: Add hosts nav tab in a target view --- ui/desktop/app/router.js | 4 ++- .../scopes/scope/projects/targets/target.js | 8 +++++ .../scope/projects/targets/target/hosts.js | 35 +++++++++++++++++++ .../projects/targets/target/-navigation.hbs | 4 +-- .../scope/projects/targets/target/hosts.hbs | 23 ++++++++++++ .../projects/targets/target/hosts-test.js | 11 ++++++ 6 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js create mode 100644 ui/desktop/app/templates/scopes/scope/projects/targets/target/hosts.hbs create mode 100644 ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/hosts-test.js diff --git a/ui/desktop/app/router.js b/ui/desktop/app/router.js index afd04e391..8e4b8d71e 100644 --- a/ui/desktop/app/router.js +++ b/ui/desktop/app/router.js @@ -14,7 +14,9 @@ Router.map(function () { }); this.route('projects', function () { this.route('targets', function () { - this.route('target', { path: ':target_id' }, function() {}); + this.route('target', { path: ':target_id' }, function() { + this.route('hosts'); + }); }); this.route('sessions', function() {}); }); diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target.js index 5031c8a4a..29efcc413 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target.js @@ -13,6 +13,14 @@ export default class ScopesScopeProjectsTargetsTargetRoute extends Route { return this.store.findRecord('target', target_id, { reload: true }); } + /** + * Navigate to hostsets within a target. + * @param {TargetModel} model + */ + afterModel(model) { + this.transitionTo('scopes.scope.projects.targets.target.hosts', model); + } + /** * Renders the target-specific templates for header and navigation * page sections. diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js new file mode 100644 index 000000000..bfc76764c --- /dev/null +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js @@ -0,0 +1,35 @@ +import Route from '@ember/routing/route'; +import { all, hash } from 'rsvp'; +import { A } from '@ember/array'; + +export default class ScopesScopeProjectsTargetsTargetHostsRoute extends Route { + // =methods + + /** + * Loads all host-sets and associated hosts under the current target. + * @return {Promise{[HostModel]}} + */ + async model() { + const { host_sets } = this.modelFor('scopes.scope.projects.targets.target'); + const hostSetsPromises = await all( + host_sets.map(({ host_set_id }) => + this.store.findRecord('host-set', host_set_id) + ) + ); + + // Extract host ids from all host set + const hostIds = A(); + hostSetsPromises.map(({ host_ids }) => + host_ids.forEach(({ value }) => hostIds.push(value) ) + ); + + // Fetch all hosts + const hostPromises = await all( + hostIds.uniq().map((hostId) => + this.store.findRecord('host', hostId) + ) + ) + + return all(hostPromises); + } +} diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs index b27314ac2..bac5c17a3 100644 --- a/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs @@ -1,5 +1,5 @@ - - {{t 'resources.host-set.title_plural'}} + + {{t 'resources.host.title_plural'}} diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target/hosts.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target/hosts.hbs new file mode 100644 index 000000000..6cf921efd --- /dev/null +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target/hosts.hbs @@ -0,0 +1,23 @@ +{{page-title (t "resources.host-set.title_plural")}} + +{{#if @model}} + + + + {{#each @model as |host|}} + + + {{host.displayName}} +

{{host.description}}

+
+ {{host.id}} + {{host.attributes.address}} + + {{t (concat 'resources.host.types.' host.type)}} + +
+ {{/each}} +
+
+ +{{/if}} diff --git a/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/hosts-test.js b/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/hosts-test.js new file mode 100644 index 000000000..e28f35db7 --- /dev/null +++ b/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/hosts-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects/targets/target/hosts', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects/targets/target/hosts'); + assert.ok(route); + }); +}); From faa90a8be173c8eb3798ff0658789a3ed9eea66e Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Wed, 3 Feb 2021 14:39:24 -0500 Subject: [PATCH 04/11] chore: Fix eslint errors --- .../scope/projects/targets/target/hosts.js | 2 +- .../scope/projects/targets/target/-header.hbs | 4 +- .../scope/projects/targets/target/hosts.hbs | 38 +++++++++---------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js index bfc76764c..8b23f7025 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js @@ -1,5 +1,5 @@ import Route from '@ember/routing/route'; -import { all, hash } from 'rsvp'; +import { all } from 'rsvp'; import { A } from '@ember/array'; export default class ScopesScopeProjectsTargetsTargetHostsRoute extends Route { diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target/-header.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target/-header.hbs index b6ddb6476..695e13318 100644 --- a/ui/desktop/app/templates/scopes/scope/projects/targets/target/-header.hbs +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target/-header.hbs @@ -1,4 +1,4 @@

- {{model.displayName}} + {{@model.displayName}}

-

{{model.description}}

\ No newline at end of file +

{{@model.description}}

\ No newline at end of file diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target/hosts.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target/hosts.hbs index 6cf921efd..a925671d7 100644 --- a/ui/desktop/app/templates/scopes/scope/projects/targets/target/hosts.hbs +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target/hosts.hbs @@ -1,23 +1,19 @@ {{page-title (t "resources.host-set.title_plural")}} -{{#if @model}} - - - - {{#each @model as |host|}} - - - {{host.displayName}} -

{{host.description}}

-
- {{host.id}} - {{host.attributes.address}} - - {{t (concat 'resources.host.types.' host.type)}} - -
- {{/each}} -
-
- -{{/if}} + + + {{#each @model as |host|}} + + + {{host.displayName}} +

{{host.description}}

+
+ {{host.id}} + {{host.attributes.address}} + + {{t (concat 'resources.host.types.' host.type)}} + +
+ {{/each}} +
+
From fbdae2c532ba7302f95a81e039a5a91b85578613 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Thu, 4 Feb 2021 10:49:14 -0500 Subject: [PATCH 05/11] feat: Add /target/sessions route --- addons/core/translations/resources/en-us.yaml | 1 + ui/desktop/app/router.js | 1 + .../routes/scopes/scope/projects/targets/target.js | 7 +++---- .../scopes/scope/projects/targets/target/sessions.js | 12 ++++++++++++ .../scope/projects/targets/target/-navigation.hbs | 3 +++ .../scope/projects/targets/target/sessions.hbs | 1 + .../scope/projects/targets/target/sessions-test.js | 11 +++++++++++ 7 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 ui/desktop/app/routes/scopes/scope/projects/targets/target/sessions.js create mode 100644 ui/desktop/app/templates/scopes/scope/projects/targets/target/sessions.hbs create mode 100644 ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/sessions-test.js diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index 7ad5434d1..ff2dce9eb 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -104,6 +104,7 @@ host: session: title: Session title_plural: Sessions + active_plural: Active Sessions description: A session is a connection to a target initiated through Boundary. messages: none: diff --git a/ui/desktop/app/router.js b/ui/desktop/app/router.js index 8e4b8d71e..0af5b7e46 100644 --- a/ui/desktop/app/router.js +++ b/ui/desktop/app/router.js @@ -16,6 +16,7 @@ Router.map(function () { this.route('targets', function () { this.route('target', { path: ':target_id' }, function() { this.route('hosts'); + this.route('sessions'); }); }); this.route('sessions', function() {}); diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target.js index 29efcc413..3c2be903f 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target.js @@ -14,11 +14,10 @@ export default class ScopesScopeProjectsTargetsTargetRoute extends Route { } /** - * Navigate to hostsets within a target. - * @param {TargetModel} model + * Navigate to sessions within a target. */ - afterModel(model) { - this.transitionTo('scopes.scope.projects.targets.target.hosts', model); + afterModel() { + this.transitionTo('scopes.scope.projects.targets.target.sessions'); } /** diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target/sessions.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target/sessions.js new file mode 100644 index 000000000..2b071e3a7 --- /dev/null +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target/sessions.js @@ -0,0 +1,12 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeProjectsTargetsTargetSessionsRoute extends Route { + // =methods + + /** + * Loads all sessions and filter to current target. + * @return {Promise{[SessionModel]}} + */ + async model() { + } +} diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs index bac5c17a3..12bfe97f8 100644 --- a/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs @@ -1,4 +1,7 @@ + + {{t 'resources.session.active_plural'}} + {{t 'resources.host.title_plural'}} diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target/sessions.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target/sessions.hbs new file mode 100644 index 000000000..c24cd6895 --- /dev/null +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target/sessions.hbs @@ -0,0 +1 @@ +{{outlet}} diff --git a/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/sessions-test.js b/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/sessions-test.js new file mode 100644 index 000000000..2208beec8 --- /dev/null +++ b/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/sessions-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects/targets/target/sessions', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects/targets/target/sessions'); + assert.ok(route); + }); +}); From 6fd3a896eaf8468b7b8017b2d0780f84339d42c1 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Thu, 4 Feb 2021 10:54:18 -0500 Subject: [PATCH 06/11] refactor: Move /target/hosts redirection into /target/index --- .../app/routes/scopes/scope/projects/targets/target.js | 8 -------- .../routes/scopes/scope/projects/targets/target/index.js | 9 +++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target.js index 29efcc413..5031c8a4a 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target.js @@ -13,14 +13,6 @@ export default class ScopesScopeProjectsTargetsTargetRoute extends Route { return this.store.findRecord('target', target_id, { reload: true }); } - /** - * Navigate to hostsets within a target. - * @param {TargetModel} model - */ - afterModel(model) { - this.transitionTo('scopes.scope.projects.targets.target.hosts', model); - } - /** * Renders the target-specific templates for header and navigation * page sections. diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js index 2199146f8..dca9bcd77 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js @@ -1,4 +1,13 @@ import Route from '@ember/routing/route'; export default class ScopesScopeProjectsTargetsTargetIndexRoute extends Route { + // =methods + + /** + * Navigate to hosts within a target. + */ + afterModel() { + this.transitionTo('scopes.scope.projects.targets.target.hosts'); + } + } From adedc6e3eea8c6a6c83627edd27612564e4a2ef2 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Thu, 4 Feb 2021 12:03:57 -0500 Subject: [PATCH 07/11] refactor: Remove EmberArray use in /target/hosts to simplify --- .../scope/projects/targets/target/hosts.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js index 8b23f7025..fda131f12 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js @@ -1,6 +1,5 @@ import Route from '@ember/routing/route'; import { all } from 'rsvp'; -import { A } from '@ember/array'; export default class ScopesScopeProjectsTargetsTargetHostsRoute extends Route { // =methods @@ -11,25 +10,26 @@ export default class ScopesScopeProjectsTargetsTargetHostsRoute extends Route { */ async model() { const { host_sets } = this.modelFor('scopes.scope.projects.targets.target'); - const hostSetsPromises = await all( + // Load all host-sets + const hostSets = await all( host_sets.map(({ host_set_id }) => this.store.findRecord('host-set', host_set_id) ) ); - // Extract host ids from all host set - const hostIds = A(); - hostSetsPromises.map(({ host_ids }) => - host_ids.forEach(({ value }) => hostIds.push(value) ) - ); - - // Fetch all hosts - const hostPromises = await all( - hostIds.uniq().map((hostId) => - this.store.findRecord('host', hostId) - ) + // Extract host ids from all host sets + const hostIds = hostSets.map(({host_ids}) => + host_ids.content.map((hostId) => + hostId.value + ) ) - return all(hostPromises); + // Load unique hosts + const uniqueHostIds = new Set(hostIds.flat()); + return all( + [...uniqueHostIds].map((hostId) => + this.store.findRecord('host', hostId) + ) + ); } } From c90e4fa69a96c829b8550d7c6b1dd640acbc2d33 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Thu, 4 Feb 2021 16:18:04 -0500 Subject: [PATCH 08/11] feat: Show active sessions under /target/:target_id route --- .../app/routes/scopes/scope/projects.js | 15 +++++++++ .../routes/scopes/scope/projects/sessions.js | 1 + .../scopes/scope/projects/targets/target.js | 26 +++++++++++++-- .../scope/projects/targets/target/hosts.js | 4 +-- .../scope/projects/targets/target/index.js | 2 +- .../scope/projects/targets/target/sessions.js | 3 +- .../scopes/scope/projects/sessions/index.hbs | 8 +++++ .../scopes/scope/projects/targets/target.hbs | 2 +- .../scope/projects/targets/target/-header.hbs | 4 +-- .../projects/targets/target/sessions.hbs | 33 ++++++++++++++++++- 10 files changed, 87 insertions(+), 11 deletions(-) diff --git a/ui/desktop/app/routes/scopes/scope/projects.js b/ui/desktop/app/routes/scopes/scope/projects.js index fb77550fd..585a35ab6 100644 --- a/ui/desktop/app/routes/scopes/scope/projects.js +++ b/ui/desktop/app/routes/scopes/scope/projects.js @@ -1,5 +1,7 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; +import { notifySuccess, notifyError } from 'core/decorators/notify'; export default class ScopesScopeProjectsRoute extends Route { // =services @@ -25,4 +27,17 @@ export default class ScopesScopeProjectsRoute extends Route { scope_id: currentScope.id, }); } + + // =actions + + /** + * Cancels the specified session and notifies user of success or error. + * @param {SessionModel} + */ + @action + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.canceled-success') + async cancelSession(session) { + await session.cancelSession(); + } } diff --git a/ui/desktop/app/routes/scopes/scope/projects/sessions.js b/ui/desktop/app/routes/scopes/scope/projects/sessions.js index 83baf114b..ee013ee3c 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/sessions.js +++ b/ui/desktop/app/routes/scopes/scope/projects/sessions.js @@ -99,4 +99,5 @@ export default class ScopesScopeProjectsSessionsRoute extends Route { deactivate() { this.poller.cancelAll(); } + } diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target.js index 5031c8a4a..45d18cdd6 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target.js @@ -1,16 +1,36 @@ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; +import { A } from '@ember/array'; export default class ScopesScopeProjectsTargetsTargetRoute extends Route { + + // =services + + @service session; + // =methods /** - * Load a target. + * Load a target and it's active sessions * @param {object} params * @param {string} params.target_id - * @return {TargetModel} + * @return {{TargetModel, [SessionModel]}} */ async model({ target_id }) { - return this.store.findRecord('target', target_id, { reload: true }); + const userId = this.session.data.authenticated.user_id; + const target = await this.store.findRecord('target', target_id, { reload: true }); + const sessions = await this.store.query('session', { scope_id: target.scopeID }); + + // Filter to current user, current target, and active state + const filteredSessions = sessions.filter( + session => session.user_id === userId && + session.target_id === target.id && + session.isCancelable + ) + // Sort sessions by time created + const sortedSessions = + A(filteredSessions).sortBy('session.created_time').reverse(); + return { target, sessions: sortedSessions }; } /** diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js index fda131f12..349543f4c 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js @@ -9,10 +9,10 @@ export default class ScopesScopeProjectsTargetsTargetHostsRoute extends Route { * @return {Promise{[HostModel]}} */ async model() { - const { host_sets } = this.modelFor('scopes.scope.projects.targets.target'); + const { target } = this.modelFor('scopes.scope.projects.targets.target'); // Load all host-sets const hostSets = await all( - host_sets.map(({ host_set_id }) => + target.host_sets.map(({ host_set_id }) => this.store.findRecord('host-set', host_set_id) ) ); diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js index dca9bcd77..0f92ba860 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js @@ -7,7 +7,7 @@ export default class ScopesScopeProjectsTargetsTargetIndexRoute extends Route { * Navigate to hosts within a target. */ afterModel() { - this.transitionTo('scopes.scope.projects.targets.target.hosts'); + this.transitionTo('scopes.scope.projects.targets.target.sessions'); } } diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target/sessions.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target/sessions.js index 2b071e3a7..bf3f475f3 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target/sessions.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target/sessions.js @@ -4,9 +4,10 @@ export default class ScopesScopeProjectsTargetsTargetSessionsRoute extends Route // =methods /** - * Loads all sessions and filter to current target. + * Loads all sessions for current target. * @return {Promise{[SessionModel]}} */ async model() { + return this.modelFor('scopes.scope.projects.targets.target').sessions; } } diff --git a/ui/desktop/app/templates/scopes/scope/projects/sessions/index.hbs b/ui/desktop/app/templates/scopes/scope/projects/sessions/index.hbs index d0847dbb3..21f09f00c 100644 --- a/ui/desktop/app/templates/scopes/scope/projects/sessions/index.hbs +++ b/ui/desktop/app/templates/scopes/scope/projects/sessions/index.hbs @@ -15,6 +15,7 @@ {{t "resources.target.title"}} {{t "form.started.label"}} {{t "form.status.label"}} + @@ -36,6 +37,13 @@ {{sessionAggregate.session.status}} + + {{#if sessionAggregate.session.isCancelable}} + + {{t "actions.cancel"}} + + {{/if}} +
{{/each}} diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target.hbs index 0ca9acc68..525892043 100644 --- a/ui/desktop/app/templates/scopes/scope/projects/targets/target.hbs +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target.hbs @@ -1,4 +1,4 @@ -{{page-title @model.displayName}} +{{page-title @model.target.displayName}} diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target/-header.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target/-header.hbs index 695e13318..41f83d562 100644 --- a/ui/desktop/app/templates/scopes/scope/projects/targets/target/-header.hbs +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target/-header.hbs @@ -1,4 +1,4 @@

- {{@model.displayName}} + {{@model.target.displayName}}

-

{{@model.description}}

\ No newline at end of file +

{{@model.target.description}}

\ No newline at end of file diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target/sessions.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target/sessions.hbs index c24cd6895..84571556b 100644 --- a/ui/desktop/app/templates/scopes/scope/projects/targets/target/sessions.hbs +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target/sessions.hbs @@ -1 +1,32 @@ -{{outlet}} + + + {{#each @model as |session|}} + + + + {{session.id}} + + {{user.displayName}} + {{target.displayName}} + + + + + {{session.status}} + + + {{#if session.isCancelable}} + + {{t "actions.cancel"}} + + {{/if}} + + + {{/each}} + + From b0f450f8e96632049ab03c10fd31b59284ee279f Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Thu, 4 Feb 2021 16:36:43 -0500 Subject: [PATCH 09/11] chore: Fix lint errors --- .../templates/scopes/scope/projects/targets/target/sessions.hbs | 2 -- 1 file changed, 2 deletions(-) diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target/sessions.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target/sessions.hbs index 84571556b..49a8e2585 100644 --- a/ui/desktop/app/templates/scopes/scope/projects/targets/target/sessions.hbs +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target/sessions.hbs @@ -9,8 +9,6 @@ @size="medium" /> {{session.id}} - {{user.displayName}} - {{target.displayName}}