mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
feat: delete all feature dependencies (#4832)
This commit is contained in:
parent
2b9678266c
commit
d49ff03464
@ -117,6 +117,26 @@ export default class DependentFeaturesController extends Controller {
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
this.route({
|
||||
method: 'delete',
|
||||
path: PATH_DEPENDENCIES,
|
||||
handler: this.deleteFeatureDependencies,
|
||||
permission: UPDATE_FEATURE,
|
||||
acceptAnyContentType: true,
|
||||
middleware: [
|
||||
openApiService.validPath({
|
||||
tags: ['Features'],
|
||||
summary: 'Deletes feature dependencies.',
|
||||
description: 'Remove dependencies to all parent features.',
|
||||
operationId: 'deleteFeatureDependencies',
|
||||
responses: {
|
||||
200: emptyResponse,
|
||||
...getStandardResponses(401, 403, 404),
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
async addFeatureDependency(
|
||||
@ -162,4 +182,22 @@ export default class DependentFeaturesController extends Controller {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteFeatureDependencies(
|
||||
req: IAuthRequest<FeatureParams, any, any>,
|
||||
res: Response,
|
||||
): Promise<void> {
|
||||
const { child } = req.params;
|
||||
|
||||
if (this.config.flagResolver.isEnabled('dependentFeatures')) {
|
||||
await this.dependentFeaturesService.deleteFeatureDependencies(
|
||||
child,
|
||||
);
|
||||
res.status(200).end();
|
||||
} else {
|
||||
throw new InvalidOperationError(
|
||||
'Dependent features are not enabled',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,4 +44,8 @@ export class DependentFeaturesService {
|
||||
): Promise<void> {
|
||||
await this.dependentFeaturesStore.delete(dependency);
|
||||
}
|
||||
|
||||
async deleteFeatureDependencies(feature: string): Promise<void> {
|
||||
await this.dependentFeaturesStore.deleteAll(feature);
|
||||
}
|
||||
}
|
||||
|
@ -4,4 +4,5 @@ export interface IDependentFeaturesStore {
|
||||
upsert(featureDependency: FeatureDependency): Promise<void>;
|
||||
getChildren(parent: string): Promise<string[]>;
|
||||
delete(dependency: FeatureDependencyId): Promise<void>;
|
||||
deleteAll(child: string): Promise<void>;
|
||||
}
|
||||
|
@ -44,4 +44,8 @@ export class DependentFeaturesStore implements IDependentFeaturesStore {
|
||||
.andWhere('child', dependency.child)
|
||||
.del();
|
||||
}
|
||||
|
||||
async deleteAll(feature: string): Promise<void> {
|
||||
await this.db('dependent_features').andWhere('child', feature).del();
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,18 @@ const deleteFeatureDependency = async (
|
||||
.expect(expectedCode);
|
||||
};
|
||||
|
||||
test('should add feature dependency', async () => {
|
||||
const deleteFeatureDependencies = async (
|
||||
childFeature: string,
|
||||
expectedCode = 200,
|
||||
) => {
|
||||
return app.request
|
||||
.delete(
|
||||
`/api/admin/projects/default/features/${childFeature}/dependencies`,
|
||||
)
|
||||
.expect(expectedCode);
|
||||
};
|
||||
|
||||
test('should add and delete feature dependencies', async () => {
|
||||
const parent = uuidv4();
|
||||
const child = uuidv4();
|
||||
await app.createFeature(parent);
|
||||
@ -73,7 +84,8 @@ test('should add feature dependency', async () => {
|
||||
variants: ['variantB'],
|
||||
});
|
||||
|
||||
await deleteFeatureDependency(child, parent);
|
||||
await deleteFeatureDependency(child, parent); // single
|
||||
await deleteFeatureDependencies(child); // all
|
||||
});
|
||||
|
||||
test('should not allow to add a parent dependency to a feature that already has children', async () => {
|
||||
|
@ -12,4 +12,8 @@ export class FakeDependentFeaturesStore implements IDependentFeaturesStore {
|
||||
delete(): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
deleteAll(): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user