Files
vault/ui/lib/sync/addon/routes/secrets/destinations/destination.ts
Jordan Reimer c1754f5f97 [UI] Types Linting (#29702)
* adds linting for types to scripts and lint staged

* fixes issue with AdapterError type

* moves lint-staged setup out of package.json and into config file

* fixes ember data store service type

* fixes route params types

* fixes model types

* fixes general type errors

* fixes ts declaration errors in js files

* adds missing copyright headers

* fixes issue accessing capabilities model properties

* ignores AdapterError import type error

* more updates to AdapterError type

* adds comment to lint-staged config

* moves ember data store type to @ember-data namespace

* updates store import

* moves AdapterError type to @ember-data namespace

* turns ember-data import eslint rule back on
2025-02-25 16:08:51 -07:00

45 lines
2.0 KiB
TypeScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Route from '@ember/routing/route';
import { service } from '@ember/service';
import type Store from '@ember-data/store';
import type RouterService from '@ember/routing/router-service';
import type FlashMessageService from 'vault/services/flash-messages';
import type Transition from '@ember/routing/transition';
import type SyncDestinationModel from 'vault/models/sync/destination';
interface RouteParams {
name?: string;
type?: string;
}
export default class SyncSecretsDestinationsDestinationRoute extends Route {
@service declare readonly store: Store;
@service('app-router') declare readonly router: RouterService;
@service declare readonly flashMessages: FlashMessageService;
model(params: RouteParams) {
const { name = '', type } = params;
return this.store.findRecord(`sync/destinations/${type}`, name);
}
afterModel(model: SyncDestinationModel, transition: Transition) {
// handles the case where the user attempts to perform actions on a destination when a purge has been initiated
// editing is available from the list view and syncing secrets is available from the overview
// the list endpoint does not return the full model so we don't have access to purgeInitiatedAt to disable or hide the actions
// if transitioning from either of the mentioned routes and a purge has been initiated redirect to the secrets view
const baseRoute = 'vault.cluster.sync.secrets.destinations.destination';
const routes = [`${baseRoute}.edit`, `${baseRoute}.sync`];
const toRoute = transition.to?.name;
if (toRoute && routes.includes(toRoute) && model.purgeInitiatedAt) {
const action = transition.to?.localName === 'edit' ? 'Editing a destination' : 'Syncing secrets';
this.flashMessages.info(`${action} is not permitted once a purge has been initiated.`);
this.router.replaceWith('vault.cluster.sync.secrets.destinations.destination.secrets');
}
}
}