Merge pull request #44 from hashicorp/oss/merge-main-da59684f254aafeba5cdd80575fdc69644bd4bf3

[main] OSS to ENT merge of (da59684)
This commit is contained in:
hc-github-team-secure-boundary authored and GitHub committed 2023-01-23 11:34:08 -08:00
commit 178a8a8187
4 files changed
+38 -44

No files matched your search

@@ -1,5 +1,5 @@
<Rose::Form
@onSubmit={{this.submit}}
@onSubmit={{@submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@showEditToggle={{if @model.isNew false true}}
@@ -1,10 +1,8 @@
import Component from '@glimmer/component';
import { TYPES_TARGET } from 'api/models/target';
import { loading } from 'ember-loading';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { notifyError } from 'core/decorators/notify';
import { tracked } from '@glimmer/tracking';
// NOTE: this is all a temporary solution till we have a resource type helper.
const types = [...TYPES_TARGET].reverse();
const icons = {
@@ -18,10 +16,6 @@ export default class FormTargetComponent extends Component {
this.args.model.egress_worker_filter?.length;
@tracked migrateWorkerFilter = false;
// =services
@service confirm;
@service intl;
// =properties
/**
@@ -78,39 +72,4 @@ export default class FormTargetComponent extends Component {
this.args.model.egress_worker_filter = this.args.model.worker_filter;
this.args.model.worker_filter = '';
}
@action
@loading
@notifyError(({ message }) => message)
async submit() {
const target = this.args.model;
const numHostSources = target.host_sources?.length;
const address = target.address;
if (address && numHostSources) {
try {
await this.confirm.confirm(
this.intl.t(
'resources.target.questions.delete-host-sources.message',
{ numHostSources }
),
{
title: 'resources.target.questions.delete-host-sources.title',
confirm: 'actions.remove-resources',
}
);
} catch (e) {
// if the user denies, do nothing and return
return;
}
await target.removeHostSources(
target.host_sources.map((hs) => hs.host_source_id)
);
// After saving the host sources, the model gets reset to an empty address,
// so we need to update the address with the previous value before saving
target.address = address;
}
await this.args.submit();
}
}
@@ -13,6 +13,7 @@ export default class ScopesScopeTargetsRoute extends Route {
@service session;
@service can;
@service router;
@service confirm;
// =methods
@@ -69,6 +70,40 @@ export default class ScopesScopeTargetsRoute extends Route {
this.refresh();
}
@action
@loading
@notifyError(({ message }) => message)
async saveWithAddress(target) {
const numHostSources = target.host_sources?.length;
const address = target.address;
if (address && numHostSources) {
try {
await this.confirm.confirm(
this.intl.t(
'resources.target.questions.delete-host-sources.message',
{ numHostSources }
),
{
title: 'resources.target.questions.delete-host-sources.title',
confirm: 'actions.remove-resources',
}
);
} catch (e) {
// if the user denies, do nothing and return
return;
}
await target.removeHostSources(
target.host_sources.map((hs) => hs.host_source_id)
);
// After saving the host sources, the model gets reset to an empty address,
// so we need to update the address with the previous value before saving
target.address = address;
}
await this.save(target);
}
/**
* Deletes a target and redirects to targets index.
* @param {TargetModel} target
@@ -19,7 +19,7 @@
<page.body>
<Form::Target
@model={{@model}}
@submit={{route-action 'save' @model}}
@submit={{route-action 'saveWithAddress' @model}}
@cancel={{route-action 'cancel' @model}}
/>
</page.body>