Skip to content

Commit

Permalink
feat: remove dependency on archive
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Oct 16, 2023
1 parent 010332e commit 9ac0bc1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ export default class DependentFeaturesController extends Controller {
const { child, projectId } = req.params;

if (this.config.flagResolver.isEnabled('dependentFeatures')) {
await this.dependentFeaturesService.deleteFeatureDependencies(
child,
await this.dependentFeaturesService.deleteFeaturesDependencies(
[child],
projectId,
req.user,
);
Expand Down
28 changes: 15 additions & 13 deletions src/lib/features/dependent-features/dependent-features-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,32 +163,34 @@ export class DependentFeaturesService {
});
}

async deleteFeatureDependencies(
feature: string,
async deleteFeaturesDependencies(
features: string[],
projectId: string,
user: User,
): Promise<void> {
await this.stopWhenChangeRequestsEnabled(projectId, user);

return this.unprotectedDeleteFeatureDependencies(
feature,
return this.unprotectedDeleteFeaturesDependencies(
features,
projectId,
extractUsernameFromUser(user),
);
}

async unprotectedDeleteFeatureDependencies(
feature: string,
async unprotectedDeleteFeaturesDependencies(
features: string[],
projectId: string,
user: string,
): Promise<void> {
await this.dependentFeaturesStore.deleteAll([feature]);
await this.eventService.storeEvent({
type: 'feature-dependencies-removed',
project: projectId,
featureName: feature,
createdBy: user,
});
await this.dependentFeaturesStore.deleteAll(features);
await this.eventService.storeEvents(
features.map((feature) => ({
type: 'feature-dependencies-removed',
project: projectId,
featureName: feature,
createdBy: user,
})),
);
}

async getParentOptions(feature: string): Promise<string[]> {
Expand Down
10 changes: 6 additions & 4 deletions src/lib/features/feature-toggle/feature-toggle-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,12 @@ export default class ProjectFeaturesController extends Controller {
res: Response<void>,
): Promise<void> {
const { featureName, projectId } = req.params;
await this.featureService.archiveToggle(
featureName,
req.user,
projectId,
await this.startTransaction(async (tx) =>
this.transactionalFeatureToggleService(tx).archiveToggle(
featureName,
req.user,
projectId,
),
);
res.status(202).send();
}
Expand Down
12 changes: 12 additions & 0 deletions src/lib/features/feature-toggle/feature-toggle-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,13 @@ class FeatureToggleService {
await this.validateNoChildren(featureName);

await this.featureToggleStore.archive(featureName);
if (projectId) {
await this.dependentFeaturesService.unprotectedDeleteFeaturesDependencies(
[featureName],
projectId,
createdBy,
);
}

await this.eventService.storeEvent(
new FeatureArchivedEvent({
Expand Down Expand Up @@ -1551,6 +1558,11 @@ class FeatureToggleService {
featureNames,
);
await this.featureToggleStore.batchArchive(featureNames);
await this.dependentFeaturesService.unprotectedDeleteFeaturesDependencies(
featureNames,
projectId,
createdBy,
);

await this.eventService.storeEvents(
features.map(
Expand Down
9 changes: 8 additions & 1 deletion src/lib/routes/admin-api/project/project-archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,14 @@ export default class ProjectArchiveController extends Controller {
const { features } = req.body;
const { projectId } = req.params;

await this.featureService.archiveToggles(features, req.user, projectId);
await this.startTransaction(async (tx) =>
this.transactionalFeatureToggleService(tx).archiveToggles(
features,
req.user,
projectId,
),
);

res.status(202).end();
}

Expand Down

0 comments on commit 9ac0bc1

Please sign in to comment.