From 998abaad67041ba0a8c6e6f3bce85204bbfc2811 Mon Sep 17 00:00:00 2001 From: David Leek Date: Wed, 29 May 2024 11:01:33 +0200 Subject: [PATCH] chore: remove unused and deprecated methods in feature toggle legacy controller and in feature toggle service (#7199) --- .../feature-toggle/feature-toggle-service.ts | 63 ------ .../feature-toggle-legacy-controller.ts | 189 +----------------- 2 files changed, 1 insertion(+), 251 deletions(-) diff --git a/src/lib/features/feature-toggle/feature-toggle-service.ts b/src/lib/features/feature-toggle/feature-toggle-service.ts index 3db086704b..4477cf3334 100644 --- a/src/lib/features/feature-toggle/feature-toggle-service.ts +++ b/src/lib/features/feature-toggle/feature-toggle-service.ts @@ -14,10 +14,8 @@ import { FeatureStrategyUpdateEvent, type FeatureToggle, type FeatureToggleDTO, - type FeatureToggleLegacy, type FeatureToggleView, type FeatureToggleWithEnvironment, - FeatureUpdatedEvent, FeatureVariantEvent, type IAuditUser, type IConstraint, @@ -1815,67 +1813,6 @@ class FeatureToggleService { return feature; } - // @deprecated - async storeFeatureUpdatedEventLegacy( - featureName: string, - auditUser: IAuditUser, - ): Promise { - const feature = await this.getFeatureToggleLegacy(featureName); - - // Legacy event. Will not be used from v4.3. - // We do not include 'preData' on purpose. - await this.eventService.storeEvent( - new FeatureUpdatedEvent({ - featureName, - data: feature, - project: feature.project, - auditUser, - }), - ); - return feature; - } - - // @deprecated - async toggle( - projectId: string, - featureName: string, - environment: string, - auditUser: IAuditUser, - ): Promise { - await this.featureToggleStore.get(featureName); - const isEnabled = - await this.featureEnvironmentStore.isEnvironmentEnabled( - featureName, - environment, - ); - return this.updateEnabled( - projectId, - featureName, - environment, - !isEnabled, - auditUser, - ); - } - - // @deprecated - async getFeatureToggleLegacy( - featureName: string, - ): Promise { - const feature = - await this.featureStrategiesStore.getFeatureToggleWithEnvs( - featureName, - ); - const { environments, ...legacyFeature } = feature; - const defaultEnv = environments.find((e) => e.name === DEFAULT_ENV); - const strategies = defaultEnv?.strategies || []; - const enabled = defaultEnv?.enabled || false; - return { - ...legacyFeature, - enabled, - strategies, - }; - } - async changeProject( featureName: string, newProject: string, diff --git a/src/lib/features/feature-toggle/legacy/feature-toggle-legacy-controller.ts b/src/lib/features/feature-toggle/legacy/feature-toggle-legacy-controller.ts index 0c46f7c70d..32669a7917 100644 --- a/src/lib/features/feature-toggle/legacy/feature-toggle-legacy-controller.ts +++ b/src/lib/features/feature-toggle/legacy/feature-toggle-legacy-controller.ts @@ -5,11 +5,10 @@ import { NONE, UPDATE_FEATURE } from '../../../types/permissions'; import type { IUnleashConfig } from '../../../types/option'; import type { IUnleashServices } from '../../../types'; import type FeatureToggleService from '../feature-toggle-service'; -import { featureSchema, querySchema } from '../../../schema/feature-schema'; +import { querySchema } from '../../../schema/feature-schema'; import type { IFeatureToggleQuery } from '../../../types/model'; import type FeatureTagService from '../../../services/feature-tag-service'; import type { IAuthRequest } from '../../../routes/unleash-types'; -import { DEFAULT_ENV } from '../../../util/constants'; import type { TagSchema } from '../../../openapi/spec/tag-schema'; import type { TagsSchema } from '../../../openapi/spec/tags-schema'; import type { OpenApiService } from '../../../services/openapi-service'; @@ -184,15 +183,6 @@ class FeatureController extends Controller { return query; } - async getToggle( - req: Request<{ featureName: string }, any, any, any>, - res: Response, - ): Promise { - const name = req.params.featureName; - const feature = await this.service.getFeatureToggleLegacy(name); - res.json(feature).end(); - } - async listTags( req: Request<{ featureName: string }, any, any, any>, res: Response, @@ -274,182 +264,5 @@ class FeatureController extends Controller { ); res.status(200).end(); } - - async createToggle(req: IAuthRequest, res: Response): Promise { - const toggle = req.body; - - const validatedToggle = await featureSchema.validateAsync(toggle); - const { enabled, project, name, variants = [] } = validatedToggle; - const createdFeature = await this.service.createFeatureToggle( - project, - validatedToggle, - req.audit, - true, - ); - const strategies = await Promise.all( - (toggle.strategies ?? []).map(async (s) => - this.service.createStrategy( - s, - { - projectId: project, - featureName: name, - environment: DEFAULT_ENV, - }, - req.audit, - req.user, - ), - ), - ); - await this.service.updateEnabled( - project, - name, - DEFAULT_ENV, - enabled, - req.audit, - ); - await this.service.saveVariants(name, project, variants, req.audit); - - res.status(201).json({ - ...createdFeature, - variants, - enabled, - strategies, - }); - } - - async updateToggle(req: IAuthRequest, res: Response): Promise { - const { featureName } = req.params; - const updatedFeature = req.body; - - updatedFeature.name = featureName; - - const projectId = await this.service.getProjectId(featureName); - const value = await featureSchema.validateAsync(updatedFeature); - - await this.service.updateFeatureToggle( - projectId, - value, - featureName, - req.audit, - ); - - await this.service.removeAllStrategiesForEnv(featureName); - - if (updatedFeature.strategies) { - await Promise.all( - updatedFeature.strategies.map(async (s) => - this.service.createStrategy( - s, - { - projectId: projectId!!, - featureName, - environment: DEFAULT_ENV, - }, - req.audit, - req.user, - ), - ), - ); - } - await this.service.updateEnabled( - projectId!!, - featureName, - DEFAULT_ENV, - updatedFeature.enabled, - req.audit, - req.user, - ); - await this.service.saveVariants( - featureName, - projectId!!, - value.variants || [], - req.audit, - ); - - const feature = await this.service.storeFeatureUpdatedEventLegacy( - featureName, - req.audit, - ); - - res.status(200).json(feature); - } - - /** - * @deprecated TODO: remove? - * - * Kept to keep backward compatibility - */ - async toggle(req: IAuthRequest, res: Response): Promise { - const { featureName } = req.params; - const projectId = await this.service.getProjectId(featureName); - const feature = await this.service.toggle( - projectId, - featureName, - DEFAULT_ENV, - req.audit, - ); - await this.service.storeFeatureUpdatedEventLegacy( - featureName, - req.audit, - ); - res.status(200).json(feature); - } - - async toggleOn(req: IAuthRequest, res: Response): Promise { - const { featureName } = req.params; - const projectId = await this.service.getProjectId(featureName); - const feature = await this.service.updateEnabled( - projectId, - featureName, - DEFAULT_ENV, - true, - req.audit, - req.user, - ); - await this.service.storeFeatureUpdatedEventLegacy( - featureName, - req.audit, - ); - res.json(feature); - } - - async toggleOff(req: IAuthRequest, res: Response): Promise { - const { featureName } = req.params; - const projectId = await this.service.getProjectId(featureName); - const feature = await this.service.updateEnabled( - projectId, - featureName, - DEFAULT_ENV, - false, - req.audit, - req.user, - ); - await this.service.storeFeatureUpdatedEventLegacy( - featureName, - req.audit, - ); - res.json(feature); - } - - async staleOn(req: IAuthRequest, res: Response): Promise { - const { featureName } = req.params; - await this.service.updateStale(featureName, true, req.audit); - const feature = await this.service.getFeatureToggleLegacy(featureName); - res.json(feature); - } - - async staleOff(req: IAuthRequest, res: Response): Promise { - const { featureName } = req.params; - await this.service.updateStale(featureName, false, req.audit); - const feature = await this.service.getFeatureToggleLegacy(featureName); - res.json(feature); - } - - async archiveToggle(req: IAuthRequest, res: Response): Promise { - const { featureName } = req.params; - - await this.service.archiveToggle(featureName, req.user, req.audit); - res.status(200).end(); - } } export default FeatureController;