mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
chore: remove unused and deprecated methods in feature toggle legacy controller and in feature toggle service (#7199)
This commit is contained in:
parent
ef9f09b58c
commit
998abaad67
@ -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<FeatureToggleLegacy> {
|
||||
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<FeatureToggle> {
|
||||
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<FeatureToggleLegacy> {
|
||||
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,
|
||||
|
@ -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<void> {
|
||||
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<TagsSchema>,
|
||||
@ -274,182 +264,5 @@ class FeatureController extends Controller {
|
||||
);
|
||||
res.status(200).end();
|
||||
}
|
||||
|
||||
async createToggle(req: IAuthRequest, res: Response): Promise<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
const { featureName } = req.params;
|
||||
|
||||
await this.service.archiveToggle(featureName, req.user, req.audit);
|
||||
res.status(200).end();
|
||||
}
|
||||
}
|
||||
export default FeatureController;
|
||||
|
Loading…
Reference in New Issue
Block a user