Skip to content

Commit

Permalink
merge from main
Browse files Browse the repository at this point in the history
  • Loading branch information
kjetilhau committed Dec 17, 2024
2 parents ca2ba9f + 55a0688 commit a4fd96d
Show file tree
Hide file tree
Showing 46 changed files with 495 additions and 467 deletions.
5 changes: 5 additions & 0 deletions .changeset/pr-892-2229093445.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

---
"fusion-project-portal": patch
---
- Updated packages to fix vulnerabilities
5 changes: 5 additions & 0 deletions .changeset/pr-893-2230942484.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

---
"fusion-project-portal": patch
---
update API endpoints for app keys to apps in PortalAppsClient
5 changes: 5 additions & 0 deletions .changeset/pr-896-2237159974.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

---
"fusion-project-portal": patch
---
Show error when application is deleted form app service
5 changes: 5 additions & 0 deletions .changeset/pr-897-2237253494.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

---
"fusion-project-portal": minor
---
- OnboardedApp: Added a new field about whether an app is found in Fusion or not.
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,60 @@
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace Equinor.ProjectExecutionPortal.Application.Commands.OnboardedApps.AddContextTypeToOnboardedApp
namespace Equinor.ProjectExecutionPortal.Application.Commands.OnboardedApps.AddContextTypeToOnboardedApp;

public class AddContextTypeToOnboardedAppCommand : IRequest<Unit>
{
public class AddContextTypeToOnboardedAppCommand : IRequest<Unit>
public AddContextTypeToOnboardedAppCommand(string appKey, string type)
{
public AddContextTypeToOnboardedAppCommand(string appKey, string type)
{
AppKey = appKey;
Type = type;
}
AppKey = appKey;
Type = type;
}

public string AppKey { get; }
public string Type { get; }
public string AppKey { get; }
public string Type { get; }
}

public class Handler : IRequestHandler<AddContextTypeToOnboardedAppCommand, Unit>
{
private readonly IReadWriteContext _readWriteContext;

public Handler(IReadWriteContext readWriteContext)
{
_readWriteContext = readWriteContext;
}

public class Handler : IRequestHandler<AddContextTypeToOnboardedAppCommand, Unit>
public async Task<Unit> Handle(AddContextTypeToOnboardedAppCommand command, CancellationToken cancellationToken)
{
private readonly IReadWriteContext _readWriteContext;
var onboardedAppWithAllContextTypes = await _readWriteContext.Set<OnboardedApp>()
.Include(x => x.ContextTypes)
.FirstOrDefaultAsync(x => x.AppKey == command.AppKey, cancellationToken);

public Handler(IReadWriteContext readWriteContext)
if (onboardedAppWithAllContextTypes == null)
{
_readWriteContext = readWriteContext;
throw new NotFoundException(nameof(Portal), command.AppKey);
}

public async Task<Unit> Handle(AddContextTypeToOnboardedAppCommand command, CancellationToken cancellationToken)
{
var onboardedAppWithAllContextTypes = await _readWriteContext.Set<OnboardedApp>()
.Include(x => x.ContextTypes)
.FirstOrDefaultAsync(x => x.AppKey == command.AppKey, cancellationToken);

if (onboardedAppWithAllContextTypes == null)
{
throw new NotFoundException(nameof(Portal), command.AppKey);
}
var contextTypeExistsOnOnboardedApp = onboardedAppWithAllContextTypes.ContextTypes.Where(x => x.ContextTypeKey == command.Type);

var contextTypeExistsOnOnboardedApp = onboardedAppWithAllContextTypes.ContextTypes.Where(x => x.ContextTypeKey == command.Type);

if (contextTypeExistsOnOnboardedApp.Any())
{
throw new InvalidOperationException($"context-type {command.Type} is already enabled on onboarded app");
}
if (contextTypeExistsOnOnboardedApp.Any())
{
throw new InvalidOperationException($"context-type {command.Type} is already enabled on onboarded app");
}

var contextType = await _readWriteContext.Set<ContextType>()
.AsNoTracking()
.FirstOrDefaultAsync(x => x.ContextTypeKey == command.Type, cancellationToken);
var contextType = await _readWriteContext.Set<ContextType>()
.AsNoTracking()
.FirstOrDefaultAsync(x => x.ContextTypeKey == command.Type, cancellationToken);

if (contextType == null)
{
throw new InvalidActionException($"context-type: {command.Type} is not supported");
}
if (contextType == null)
{
throw new InvalidActionException($"context-type: {command.Type} is not supported");
}

onboardedAppWithAllContextTypes.AddContextType(contextType);
onboardedAppWithAllContextTypes.AddContextType(contextType);

await _readWriteContext.SaveChangesAsync(cancellationToken);
await _readWriteContext.SaveChangesAsync(cancellationToken);

return Unit.Value;
}
return Unit.Value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,60 @@
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace Equinor.ProjectExecutionPortal.Application.Commands.Portals.AddContextTypeToPortal
namespace Equinor.ProjectExecutionPortal.Application.Commands.Portals.AddContextTypeToPortal;

public class AddContextTypeToPortalCommand : IRequest<Unit>
{
public class AddContextTypeToPortalCommand : IRequest<Unit>
public AddContextTypeToPortalCommand(Guid portalId, string type)
{
public AddContextTypeToPortalCommand(Guid portalId, string type)
{
PortalId = portalId;
Type = type;
}
PortalId = portalId;
Type = type;
}

public Guid PortalId { get; }
public string Type { get; }
public Guid PortalId { get; }
public string Type { get; }
}

public class Handler : IRequestHandler<AddContextTypeToPortalCommand, Unit>
{
private readonly IReadWriteContext _readWriteContext;

public Handler(IReadWriteContext readWriteContext)
{
_readWriteContext = readWriteContext;
}

public class Handler : IRequestHandler<AddContextTypeToPortalCommand, Unit>
public async Task<Unit> Handle(AddContextTypeToPortalCommand command, CancellationToken cancellationToken)
{
private readonly IReadWriteContext _readWriteContext;
var portalWithAllContextTypes = await _readWriteContext.Set<Portal>()
.Include(x => x.ContextTypes)
.FirstOrDefaultAsync(x => x.Id == command.PortalId, cancellationToken);

public Handler(IReadWriteContext readWriteContext)
if (portalWithAllContextTypes == null)
{
_readWriteContext = readWriteContext;
throw new NotFoundException(nameof(Portal), command.PortalId);
}

public async Task<Unit> Handle(AddContextTypeToPortalCommand command, CancellationToken cancellationToken)
{
var portalWithAllContextTypes = await _readWriteContext.Set<Portal>()
.Include(x => x.ContextTypes)
.FirstOrDefaultAsync(x => x.Id == command.PortalId, cancellationToken);

if (portalWithAllContextTypes == null)
{
throw new NotFoundException(nameof(Portal), command.PortalId);
}
var contextTypeExistsOnPortal = portalWithAllContextTypes.ContextTypes.Where(x => x.ContextTypeKey == command.Type);

var contextTypeExistsOnPortal = portalWithAllContextTypes.ContextTypes.Where(x => x.ContextTypeKey == command.Type);

if (contextTypeExistsOnPortal.Any())
{
throw new InvalidActionException($"context-type {command.Type}is already enabled on portal");
}
if (contextTypeExistsOnPortal.Any())
{
throw new InvalidActionException($"context-type {command.Type}is already enabled on portal");
}

var contextType = await _readWriteContext.Set<ContextType>()
.AsNoTracking()
.FirstOrDefaultAsync(x => x.ContextTypeKey == command.Type, cancellationToken);
var contextType = await _readWriteContext.Set<ContextType>()
.AsNoTracking()
.FirstOrDefaultAsync(x => x.ContextTypeKey == command.Type, cancellationToken);

if (contextType == null)
{
throw new InvalidOperationException($"context-type: {command.Type} is not supported");
}
if (contextType == null)
{
throw new InvalidOperationException($"context-type: {command.Type} is not supported");
}

portalWithAllContextTypes.AddContextType(contextType);
portalWithAllContextTypes.AddContextType(contextType);

await _readWriteContext.SaveChangesAsync(cancellationToken);
await _readWriteContext.SaveChangesAsync(cancellationToken);

return Unit.Value;
}
return Unit.Value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,46 @@
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace Equinor.ProjectExecutionPortal.Application.Commands.Portals.RemovePortal
namespace Equinor.ProjectExecutionPortal.Application.Commands.Portals.RemovePortal;

public class RemovePortalCommand : IRequest
{
public class RemovePortalCommand : IRequest
public RemovePortalCommand(Guid id)
{
Id = id;
}

public Guid Id { get; }

public class Handler : IRequestHandler<RemovePortalCommand>
{
public RemovePortalCommand(Guid id)
private readonly IReadWriteContext _context;

public Handler(IReadWriteContext context)
{
Id = id;
_context = context;
}

public Guid Id { get; }

public class Handler : IRequestHandler<RemovePortalCommand>
public async Task Handle(RemovePortalCommand command, CancellationToken cancellationToken)
{
private readonly IReadWriteContext _context;
var entity = await _context.Set<Portal>()
.Include(x => x.Apps)
.FirstOrDefaultAsync(portal => portal.Id == command.Id, cancellationToken);

public Handler(IReadWriteContext context)
if (entity == null)
{
_context = context;
throw new NotFoundException(nameof(Portal), command.Id);
}

public async Task Handle(RemovePortalCommand command, CancellationToken cancellationToken)
if (entity.Apps.Any())
{
var entity = await _context.Set<Portal>()
.Include(x => x.Apps)
.FirstOrDefaultAsync(portal => portal.Id == command.Id, cancellationToken);

if (entity == null)
{
throw new NotFoundException(nameof(Portal), command.Id);
}

if (entity.Apps.Any())
{
throw new InvalidOperationException("Cannot remove Portal, portal has onboarded apps");
}
throw new InvalidOperationException("Cannot remove Portal, portal has onboarded apps");
}

_context.Set<Portal>().Remove(entity);
_context.Set<Portal>().Remove(entity);

await _context.SaveChangesAsync(cancellationToken);
await _context.SaveChangesAsync(cancellationToken);

}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="Fusion.Integration.Abstractions" Version="8.1.0" />
<PackageReference Include="Fusion.Integration.Abstractions" Version="8.2.0" />
<PackageReference Include="Fusion.Integration.Apps.Abstractions" Version="8.1.0" />
<PackageReference Include="MediatR" Version="12.4.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.11" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public class OnboardedAppDto : AuditDto, IMapFrom<Domain.Entities.OnboardedApp>
public string? DisplayName { get; set; }
public string? Description { get; set; }
public App? AppInformation { get; set; }
public bool DoesNotExistInFusion { get; set; } = false;
public List<ContextTypeDto> ContextTypes { get; set; } = [];
// existsInFusion

public void SupplyWithFusionData(App app)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Equinor.ProjectExecutionPortal.Domain.Common;
using Equinor.ProjectExecutionPortal.Infrastructure;
using Fusion.Integration;
using Fusion.Integration.Profile;
using ProfileNotFoundError = Equinor.ProjectExecutionPortal.Domain.Common.Exceptions.ProfileNotFoundError;
Expand All @@ -10,7 +9,7 @@ public class AccountService : IAccountService
{
private readonly IFusionProfileResolver _profileResolver;

public AccountService(IFusionProfileResolver profileResolver, IReadWriteContext context)
public AccountService(IFusionProfileResolver profileResolver)
{
_profileResolver = profileResolver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public async Task<OnboardedAppDto> EnrichWithFusionAppData(OnboardedAppDto onboa
{
onboardedApp.SupplyWithFusionData(fusionApp);
}
else
{
onboardedApp.DoesNotExistInFusion = true;
}

return onboardedApp;
}
Expand All @@ -45,5 +49,9 @@ private static void CombineAppWithFusionAppData(OnboardedAppDto onboardedApp, IE
{
onboardedApp.SupplyWithFusionData(fusionApp);
}
else
{
onboardedApp.DoesNotExistInFusion = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Equinor.ProjectExecutionPortal.Application.Queries.OnboardedApps;

namespace Equinor.ProjectExecutionPortal.Application.Services.AppService
namespace Equinor.ProjectExecutionPortal.Application.Services.AppService;

public interface IAppService
{
public interface IAppService
{
Task<OnboardedAppDto> EnrichWithFusionAppData(OnboardedAppDto onboardedApp, CancellationToken cancellationToken);
Task<OnboardedAppDto> EnrichWithFusionAppData(OnboardedAppDto onboardedApp, CancellationToken cancellationToken);

Task<List<OnboardedAppDto>> EnrichWithFusionAppData(List<OnboardedAppDto> apps, CancellationToken cancellationToken);
}
Task<List<OnboardedAppDto>> EnrichWithFusionAppData(List<OnboardedAppDto> apps, CancellationToken cancellationToken);
}
Loading

0 comments on commit a4fd96d

Please sign in to comment.