Skip to content

Commit 678817f

Browse files
authored
Deleting test projects now deletes FwHeadless repo (#1937)
* Deleting test projects now deletes FwHeadless repo * Invalidate caches after deleting project
1 parent 0f8bce8 commit 678817f

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

backend/LexBoxApi/Controllers/ProjectController.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,12 @@ public async Task<ActionResult> FinishResetProject(string code)
170170
[AdminRequired]
171171
public async Task<ActionResult<Project>> DeleteProject(Guid id)
172172
{
173-
//this project is only for testing purposes. It will delete projects permanently from the database.
173+
//this endpoint is only for testing purposes. It will delete projects permanently from the database.
174174
var project = await lexBoxDbContext.Projects.FindAsync(id);
175175
if (project is null) return NotFound();
176176
if (project.RetentionPolicy != RetentionPolicy.Dev) return Forbid();
177-
lexBoxDbContext.Projects.Remove(project);
178-
var hgService = HttpContext.RequestServices.GetRequiredService<IHgService>();
179-
await hgService.DeleteRepo(project.Code);
180-
project.UpdateUpdatedDate();
181-
await lexBoxDbContext.SaveChangesAsync();
177+
project = await projectService.DeleteProjectPermanently(id);
178+
if (project is null) return NotFound();
182179
return project;
183180
}
184181

backend/LexBoxApi/Services/ProjectService.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,25 @@ public async Task FinishReset(string code, Stream? zipFile = null)
200200
await dbContext.SaveChangesAsync();
201201
}
202202

203+
public async Task<Project?> DeleteProjectPermanently(Guid projectId)
204+
{
205+
// This method should only be called for test projects, like those created during E2E tests
206+
var project = await dbContext.Projects.FindAsync(projectId);
207+
// These checks *should* be redundant with the ProjectController's checks, but do them again anyway
208+
if (project is null) return null;
209+
if (project.RetentionPolicy != RetentionPolicy.Dev) return null;
210+
dbContext.Projects.Remove(project);
211+
await hgService.DeleteRepo(project.Code);
212+
await fwHeadless.DeleteRepo(projectId);
213+
project.UpdateUpdatedDate();
214+
// Don't forget to add more Invalidate calls here if we add new caches
215+
InvalidateProjectCodeCache(project.Code);
216+
InvalidateProjectConfidentialityCache(projectId);
217+
InvalidateProjectOrgIdsCache(projectId);
218+
await dbContext.SaveChangesAsync();
219+
return project;
220+
}
221+
203222
public async ValueTask<Guid[]> LookupProjectOrgIds(Guid projectId)
204223
{
205224
var cacheKey = $"ProjectOrgsForId:{projectId}";

0 commit comments

Comments
 (0)