1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix: legacy feature stale on/off needs to return full toggle

This commit is contained in:
Ivar Conradi Østhus 2021-10-28 15:48:07 +02:00
parent 8ad235e77f
commit 3ef7fd2420
No known key found for this signature in database
GPG Key ID: 31AC596886B0BD09

View File

@ -22,11 +22,9 @@ import { DEFAULT_ENV } from '../../util/constants';
const version = 1; const version = 1;
class FeatureController extends Controller { class FeatureController extends Controller {
private logger: Logger; private tagService: FeatureTagService;
private featureTagService: FeatureTagService; private service: FeatureToggleServiceV2;
private featureService2: FeatureToggleServiceV2;
constructor( constructor(
config: IUnleashConfig, config: IUnleashConfig,
@ -39,9 +37,8 @@ class FeatureController extends Controller {
>, >,
) { ) {
super(config); super(config);
this.featureTagService = featureTagService; this.tagService = featureTagService;
this.featureService2 = featureToggleServiceV2; this.service = featureToggleServiceV2;
this.logger = config.getLogger('/admin-api/feature.ts');
this.get('/', this.getAllToggles); this.get('/', this.getAllToggles);
this.post('/', this.createToggle, CREATE_FEATURE); this.post('/', this.createToggle, CREATE_FEATURE);
@ -94,7 +91,7 @@ class FeatureController extends Controller {
async getAllToggles(req: Request, res: Response): Promise<void> { async getAllToggles(req: Request, res: Response): Promise<void> {
const query = await this.prepQuery(req.query); const query = await this.prepQuery(req.query);
const features = await this.featureService2.getFeatureToggles(query); const features = await this.service.getFeatureToggles(query);
res.json({ version, features }); res.json({ version, features });
} }
@ -104,21 +101,19 @@ class FeatureController extends Controller {
res: Response, res: Response,
): Promise<void> { ): Promise<void> {
const name = req.params.featureName; const name = req.params.featureName;
const feature = await this.featureService2.getFeatureToggleLegacy(name); const feature = await this.service.getFeatureToggleLegacy(name);
res.json(feature).end(); res.json(feature).end();
} }
async listTags(req: Request, res: Response): Promise<void> { async listTags(req: Request, res: Response): Promise<void> {
const tags = await this.featureTagService.listTags( const tags = await this.tagService.listTags(req.params.featureName);
req.params.featureName,
);
res.json({ version, tags }); res.json({ version, tags });
} }
async addTag(req: IAuthRequest, res: Response): Promise<void> { async addTag(req: IAuthRequest, res: Response): Promise<void> {
const { featureName } = req.params; const { featureName } = req.params;
const userName = extractUsername(req); const userName = extractUsername(req);
const tag = await this.featureTagService.addTag( const tag = await this.tagService.addTag(
featureName, featureName,
req.body, req.body,
userName, userName,
@ -130,18 +125,14 @@ class FeatureController extends Controller {
async removeTag(req: IAuthRequest, res: Response): Promise<void> { async removeTag(req: IAuthRequest, res: Response): Promise<void> {
const { featureName, type, value } = req.params; const { featureName, type, value } = req.params;
const userName = extractUsername(req); const userName = extractUsername(req);
await this.featureTagService.removeTag( await this.tagService.removeTag(featureName, { type, value }, userName);
featureName,
{ type, value },
userName,
);
res.status(200).end(); res.status(200).end();
} }
async validate(req: Request, res: Response): Promise<void> { async validate(req: Request, res: Response): Promise<void> {
const { name } = req.body; const { name } = req.body;
await this.featureService2.validateName(name); await this.service.validateName(name);
res.status(200).end(); res.status(200).end();
} }
@ -151,14 +142,14 @@ class FeatureController extends Controller {
const validatedToggle = await featureSchema.validateAsync(toggle); const validatedToggle = await featureSchema.validateAsync(toggle);
const { enabled } = validatedToggle; const { enabled } = validatedToggle;
const createdFeature = await this.featureService2.createFeatureToggle( const createdFeature = await this.service.createFeatureToggle(
validatedToggle.project, validatedToggle.project,
validatedToggle, validatedToggle,
userName, userName,
); );
const strategies = await Promise.all( const strategies = await Promise.all(
toggle.strategies.map(async (s) => toggle.strategies.map(async (s) =>
this.featureService2.createStrategy( this.service.createStrategy(
s, s,
createdFeature.project, createdFeature.project,
createdFeature.name, createdFeature.name,
@ -166,7 +157,7 @@ class FeatureController extends Controller {
), ),
), ),
); );
await this.featureService2.updateEnabled( await this.service.updateEnabled(
createdFeature.project, createdFeature.project,
createdFeature.name, createdFeature.name,
DEFAULT_ENV, DEFAULT_ENV,
@ -188,23 +179,17 @@ class FeatureController extends Controller {
updatedFeature.name = featureName; updatedFeature.name = featureName;
const projectId = await this.featureService2.getProjectId( const projectId = await this.service.getProjectId(updatedFeature.name);
updatedFeature.name,
);
const value = await featureSchema.validateAsync(updatedFeature); const value = await featureSchema.validateAsync(updatedFeature);
await this.featureService2.updateFeatureToggle( await this.service.updateFeatureToggle(projectId, value, userName);
projectId,
value,
userName,
);
await this.featureService2.removeAllStrategiesForEnv(featureName); await this.service.removeAllStrategiesForEnv(featureName);
if (updatedFeature.strategies) { if (updatedFeature.strategies) {
await Promise.all( await Promise.all(
updatedFeature.strategies.map(async (s) => updatedFeature.strategies.map(async (s) =>
this.featureService2.createStrategy( this.service.createStrategy(
s, s,
projectId, projectId,
featureName, featureName,
@ -213,7 +198,7 @@ class FeatureController extends Controller {
), ),
); );
} }
await this.featureService2.updateEnabled( await this.service.updateEnabled(
projectId, projectId,
updatedFeature.name, updatedFeature.name,
DEFAULT_ENV, DEFAULT_ENV,
@ -221,11 +206,10 @@ class FeatureController extends Controller {
userName, userName,
); );
const feature = const feature = await this.service.storeFeatureUpdatedEventLegacy(
await this.featureService2.storeFeatureUpdatedEventLegacy( featureName,
featureName, userName,
userName, );
);
res.status(200).json(feature); res.status(200).json(feature);
} }
@ -235,14 +219,14 @@ class FeatureController extends Controller {
async toggle(req: IAuthRequest, res: Response): Promise<void> { async toggle(req: IAuthRequest, res: Response): Promise<void> {
const userName = extractUsername(req); const userName = extractUsername(req);
const { featureName } = req.params; const { featureName } = req.params;
const projectId = await this.featureService2.getProjectId(featureName); const projectId = await this.service.getProjectId(featureName);
const feature = await this.featureService2.toggle( const feature = await this.service.toggle(
projectId, projectId,
featureName, featureName,
DEFAULT_ENV, DEFAULT_ENV,
userName, userName,
); );
await this.featureService2.storeFeatureUpdatedEventLegacy( await this.service.storeFeatureUpdatedEventLegacy(
featureName, featureName,
userName, userName,
); );
@ -252,15 +236,15 @@ class FeatureController extends Controller {
async toggleOn(req: IAuthRequest, res: Response): Promise<void> { async toggleOn(req: IAuthRequest, res: Response): Promise<void> {
const { featureName } = req.params; const { featureName } = req.params;
const userName = extractUsername(req); const userName = extractUsername(req);
const projectId = await this.featureService2.getProjectId(featureName); const projectId = await this.service.getProjectId(featureName);
const feature = await this.featureService2.updateEnabled( const feature = await this.service.updateEnabled(
projectId, projectId,
featureName, featureName,
DEFAULT_ENV, DEFAULT_ENV,
true, true,
userName, userName,
); );
await this.featureService2.storeFeatureUpdatedEventLegacy( await this.service.storeFeatureUpdatedEventLegacy(
featureName, featureName,
userName, userName,
); );
@ -270,15 +254,15 @@ class FeatureController extends Controller {
async toggleOff(req: IAuthRequest, res: Response): Promise<void> { async toggleOff(req: IAuthRequest, res: Response): Promise<void> {
const { featureName } = req.params; const { featureName } = req.params;
const userName = extractUsername(req); const userName = extractUsername(req);
const projectId = await this.featureService2.getProjectId(featureName); const projectId = await this.service.getProjectId(featureName);
const feature = await this.featureService2.updateEnabled( const feature = await this.service.updateEnabled(
projectId, projectId,
featureName, featureName,
DEFAULT_ENV, DEFAULT_ENV,
false, false,
userName, userName,
); );
await this.featureService2.storeFeatureUpdatedEventLegacy( await this.service.storeFeatureUpdatedEventLegacy(
featureName, featureName,
userName, userName,
); );
@ -288,22 +272,24 @@ class FeatureController extends Controller {
async staleOn(req: IAuthRequest, res: Response): Promise<void> { async staleOn(req: IAuthRequest, res: Response): Promise<void> {
const { featureName } = req.params; const { featureName } = req.params;
const userName = extractUsername(req); const userName = extractUsername(req);
await this.featureService2.updateStale(featureName, true, userName); await this.service.updateStale(featureName, true, userName);
res.status(200).end(); const feature = await this.service.getFeatureToggleLegacy(featureName);
res.json(feature);
} }
async staleOff(req: IAuthRequest, res: Response): Promise<void> { async staleOff(req: IAuthRequest, res: Response): Promise<void> {
const { featureName } = req.params; const { featureName } = req.params;
const userName = extractUsername(req); const userName = extractUsername(req);
await this.featureService2.updateStale(featureName, false, userName); await this.service.updateStale(featureName, false, userName);
res.status(200).end(); const feature = await this.service.getFeatureToggleLegacy(featureName);
res.json(feature);
} }
async archiveToggle(req: IAuthRequest, res: Response): Promise<void> { async archiveToggle(req: IAuthRequest, res: Response): Promise<void> {
const { featureName } = req.params; const { featureName } = req.params;
const userName = extractUsername(req); const userName = extractUsername(req);
await this.featureService2.archiveToggle(featureName, userName); await this.service.archiveToggle(featureName, userName);
res.status(200).end(); res.status(200).end();
} }
} }