Skip to content

Commit

Permalink
Merge branch 'develop' into dr/parametrize-rollover
Browse files Browse the repository at this point in the history
  • Loading branch information
datahub-portal-pr-rw[bot] authored Feb 14, 2025
2 parents 4c51f14 + 655e604 commit d358357
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@

using Datahub.Core.Model.Projects;

using Datahub.Core.Components.Resources;

namespace Datahub.Application.Services
{
public interface IProjectDeletionService
{
public Task<bool> DeleteWorkspace(string acronym, Project_Delete_Questionnaire questionnaire);
public Task<bool> DeleteWorkspace(string acronym, Project_Delete_Questionnaire questionnaire);
public Task<bool> CleanWorkspaceFromRecentLinks(string workspaceAcronym);
public Task<bool> CleanResourceFromRecentLinks(string section, string workspaceAcronym);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
using Datahub.Shared.Entities;
using Datahub.Shared;
using Google.Api.Gax.ResourceNames;
using Datahub.Core.Components.Resources;
using Microsoft.Graph.Models.Search;
using Datahub.Core.Components;
using Datahub.Core.Model.Projects;

namespace Datahub.Infrastructure.Services
Expand Down Expand Up @@ -74,5 +77,58 @@ public async Task<bool> DeleteWorkspace(string acronym, Project_Delete_Questionn
}
}

public async Task<bool> CleanWorkspaceFromRecentLinks(string workspaceAcronym)
{
try
{
await using var ctx = await datahubProjectDbFactory.CreateDbContextAsync();

var recentLinks = await ctx.UserRecentLinks
.Where(link => link.DataProject == workspaceAcronym)
.ToListAsync(CancellationToken.None);

ctx.UserRecentLinks.RemoveRange(recentLinks);
await ctx.SaveChangesAsync(CancellationToken.None);

return true;
}
catch (Exception ex)
{
logger.LogError(ex, $"Error deleting workspace from recent links - {workspaceAcronym}");
return false;
}
}

public async Task<bool> CleanResourceFromRecentLinks(string section, string workspaceAcronym)
{
try
{
await using var ctx = await datahubProjectDbFactory.CreateDbContextAsync();

DatahubLinkType linkType = section switch
{
//currently can only delete postgres and app service, and postgres doesnt get added to recent links yet
TerraformTemplate.AzureAppService => DatahubLinkType.AzureWebApp,
_ => DatahubLinkType.Undefined
};

if (linkType != DatahubLinkType.Undefined)
{
var recentLinks = await ctx.UserRecentLinks
.Where(link => link.LinkType == linkType && link.DataProject == workspaceAcronym)
.ToListAsync(CancellationToken.None);

ctx.UserRecentLinks.RemoveRange(recentLinks);
await ctx.SaveChangesAsync(CancellationToken.None);
}

return true;
}
catch (Exception ex)
{
logger.LogError(ex, $"Error deleting recent links for - {section} - for workspace - {workspaceAcronym}");
return false;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@namespace Datahub.Portal.Pages.Workspace.Delete

@using Datahub.Application.Services
@using Datahub.Core.Services.Projects
@using Datahub.Shared
@using Datahub.Shared.Entities
Expand All @@ -9,6 +10,7 @@
@inject IDbContextFactory<DatahubProjectDBContext> _contextFactory

@inject IRequestManagementService _requestManagementService
@inject IProjectDeletionService _projectDeletionService
@inject IUserInformationService _userInformationService

<MudStack Class="px-4">
Expand Down Expand Up @@ -74,8 +76,8 @@
await base.OnInitializedAsync();

await using var ctx = await _contextFactory.CreateDbContextAsync();


if (WorkspaceAcronym == null || SubSection == null)
{
_snackbar.Add(Localizer["Invalid parameters, redirecting"], Severity.Error);
Expand Down Expand Up @@ -112,7 +114,9 @@
var workspace = await ctx.Projects
.FirstAsync(w => w.Project_Acronym_CD == WorkspaceAcronym);
var currentUser = await _userInformationService.GetCurrentPortalUserAsync();


var isRecentLinksCleaned = await _projectDeletionService.CleanResourceFromRecentLinks(SubSection, WorkspaceAcronym);

var template = new TerraformTemplate(SubSection, TerraformStatus.DeleteRequested);
await _requestManagementService.HandleTerraformRequestServiceAsync(workspace, template, currentUser);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
if (!await _jSRuntime.InvokeAsync<bool>("confirm", message))
return;

var isRecentLinksCleaned = await _projectDeletionService.CleanWorkspaceFromRecentLinks(WorkspaceAcronym);
_deleteRequested = await _projectDeletionService.DeleteWorkspace(WorkspaceAcronym, _questionnaire);

if (_deleteRequested)
Expand Down
1 change: 1 addition & 0 deletions Shared/src/Datahub.Shared/TerraformVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public static class TerraformVariables
public const string OutputNewProjectTemplate = "new_project_template";
public const string OutputWorkspaceVersion = "workspace_version";
public const string OutputAzureResourceGroupName = "azure_resource_group_name";
public const string OutputAzureResourceGroupStatus = "azure_resource_group_status";

// Azure Storage output variables
public const string AzureStorageType = "blob";
Expand Down

0 comments on commit d358357

Please sign in to comment.