diff --git a/.changeset/pr-848-2155869305.md b/.changeset/pr-848-2155869305.md new file mode 100644 index 000000000..017b123fe --- /dev/null +++ b/.changeset/pr-848-2155869305.md @@ -0,0 +1,3 @@ + +--- +--- diff --git a/backend/src/Equinor.ProjectExecutionPortal.Application/Cache/CacheManager.cs b/backend/src/Equinor.ProjectExecutionPortal.Application/Cache/CacheManager.cs index 5a8eac961..ebab21d28 100644 --- a/backend/src/Equinor.ProjectExecutionPortal.Application/Cache/CacheManager.cs +++ b/backend/src/Equinor.ProjectExecutionPortal.Application/Cache/CacheManager.cs @@ -5,9 +5,7 @@ namespace Equinor.ProjectExecutionPortal.Application.Cache; public class CacheManager : ICacheManager { - private readonly IMemoryCache _cache; - - public CacheManager() => _cache = new MemoryCache(new MemoryCacheOptions + private readonly IMemoryCache _cache = new MemoryCache(new MemoryCacheOptions { Clock = new CacheClock() }); diff --git a/backend/src/Equinor.ProjectExecutionPortal.Application/Cache/CacheOptions.cs b/backend/src/Equinor.ProjectExecutionPortal.Application/Cache/CacheOptions.cs new file mode 100644 index 000000000..9ed168131 --- /dev/null +++ b/backend/src/Equinor.ProjectExecutionPortal.Application/Cache/CacheOptions.cs @@ -0,0 +1,6 @@ +namespace Equinor.ProjectExecutionPortal.Application.Cache; + +public class CacheOptions +{ + public int FusionAppsCacheMinutes { get; init; } +} diff --git a/backend/src/Equinor.ProjectExecutionPortal.Application/Cache/FusionAppsCache.cs b/backend/src/Equinor.ProjectExecutionPortal.Application/Cache/FusionAppsCache.cs index 53a4fd265..3c7499ba2 100644 --- a/backend/src/Equinor.ProjectExecutionPortal.Application/Cache/FusionAppsCache.cs +++ b/backend/src/Equinor.ProjectExecutionPortal.Application/Cache/FusionAppsCache.cs @@ -1,5 +1,6 @@ using Fusion.Integration.Apps.Abstractions.Abstractions; using Fusion.Integration.Apps.Abstractions.Models; +using Microsoft.Extensions.Options; namespace Equinor.ProjectExecutionPortal.Application.Cache; @@ -7,33 +8,33 @@ public class FusionAppsCache : IFusionAppsCache { private readonly ICacheManager _cacheManager; private readonly IAppsClient _fusionAppsClient; + private readonly IOptions _cacheOptions; - public FusionAppsCache(ICacheManager cacheManager, IAppsClient fusionAppsClient) + private const string FusionAppCacheKey = "FUSION_APP"; + + public FusionAppsCache(ICacheManager cacheManager, IAppsClient fusionAppsClient, IOptions cacheOptions) { _cacheManager = cacheManager; _fusionAppsClient = fusionAppsClient; + _cacheOptions = cacheOptions; } - // TODO: Move cache duration to app settings - public async Task> GetFusionApps() { - return await _cacheManager.GetOrCreateAsync("FUSION_APP", + return await _cacheManager.GetOrCreateAsync(FusionAppCacheKey, async () => { var fusionApps = await _fusionAppsClient.GetAppsAsync(); return fusionApps.ToList(); }, - CacheDuration.Minutes, - 60); + CacheDuration.Minutes, _cacheOptions.Value.FusionAppsCacheMinutes); } public async Task GetFusionApp(string appKey) { - return await _cacheManager.GetOrCreateAsync("FUSION_APP", + return await _cacheManager.GetOrCreateAsync(FusionAppCacheKey, async () => await _fusionAppsClient.GetAppAsync(appKey), - CacheDuration.Minutes, - 60); + CacheDuration.Minutes, _cacheOptions.Value.FusionAppsCacheMinutes); } -} \ No newline at end of file +} diff --git a/backend/src/Equinor.ProjectExecutionPortal.Application/Infrastructure/Mappings/MappingProfile.cs b/backend/src/Equinor.ProjectExecutionPortal.Application/Infrastructure/Mappings/MappingProfile.cs index 2b060f285..50c067a32 100644 --- a/backend/src/Equinor.ProjectExecutionPortal.Application/Infrastructure/Mappings/MappingProfile.cs +++ b/backend/src/Equinor.ProjectExecutionPortal.Application/Infrastructure/Mappings/MappingProfile.cs @@ -22,7 +22,7 @@ private void ApplyMappingsFromAssembly(Assembly assembly) var methodInfo = type.GetMethod("Mapping") ?? type.GetInterface("IMapFrom`1")!.GetMethod("Mapping"); - methodInfo?.Invoke(instance, new object[] { this }); + methodInfo?.Invoke(instance, [this]); } } diff --git a/backend/src/Equinor.ProjectExecutionPortal.Domain/Common/EntityBase.cs b/backend/src/Equinor.ProjectExecutionPortal.Domain/Common/EntityBase.cs index ee2caabde..8df1aaa07 100644 --- a/backend/src/Equinor.ProjectExecutionPortal.Domain/Common/EntityBase.cs +++ b/backend/src/Equinor.ProjectExecutionPortal.Domain/Common/EntityBase.cs @@ -9,13 +9,13 @@ public abstract class EntityBase { private List? _domainEvents; - public IReadOnlyCollection DomainEvents => _domainEvents?.AsReadOnly() ?? (_domainEvents = new List()).AsReadOnly(); + public IReadOnlyCollection DomainEvents => _domainEvents?.AsReadOnly() ?? (_domainEvents = []).AsReadOnly(); public virtual Guid Id { get; protected set; } public void AddDomainEvent(INotification eventItem) { - _domainEvents ??= new List(); + _domainEvents ??= []; _domainEvents.Add(eventItem); } diff --git a/backend/src/Equinor.ProjectExecutionPortal.Domain/Infrastructure/QueryBase.cs b/backend/src/Equinor.ProjectExecutionPortal.Domain/Infrastructure/QueryBase.cs index 0d1e8314e..e8ae4bff0 100644 --- a/backend/src/Equinor.ProjectExecutionPortal.Domain/Infrastructure/QueryBase.cs +++ b/backend/src/Equinor.ProjectExecutionPortal.Domain/Infrastructure/QueryBase.cs @@ -2,7 +2,5 @@ namespace Equinor.ProjectExecutionPortal.Domain.Infrastructure { - public abstract class QueryBase : IRequest - { - } + public abstract class QueryBase : IRequest; } diff --git a/backend/src/Equinor.ProjectExecutionPortal.Infrastructure/IReadWriteContext.cs b/backend/src/Equinor.ProjectExecutionPortal.Infrastructure/IReadWriteContext.cs index 76d69fd55..2299bf15b 100644 --- a/backend/src/Equinor.ProjectExecutionPortal.Infrastructure/IReadWriteContext.cs +++ b/backend/src/Equinor.ProjectExecutionPortal.Infrastructure/IReadWriteContext.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; namespace Equinor.ProjectExecutionPortal.Infrastructure; @@ -8,6 +7,4 @@ public interface IReadWriteContext : IDisposable DbSet Set() where TEntity : class; Task SaveChangesAsync(CancellationToken cancellationToken); - - DatabaseFacade Database { get; } -} +} \ No newline at end of file diff --git a/backend/src/Equinor.ProjectExecutionPortal.Infrastructure/InfrastructureModule.cs b/backend/src/Equinor.ProjectExecutionPortal.Infrastructure/InfrastructureModule.cs index d53ba8e69..a04c9e3d2 100644 --- a/backend/src/Equinor.ProjectExecutionPortal.Infrastructure/InfrastructureModule.cs +++ b/backend/src/Equinor.ProjectExecutionPortal.Infrastructure/InfrastructureModule.cs @@ -6,7 +6,7 @@ namespace Equinor.ProjectExecutionPortal.Infrastructure; public static class InfrastructureModule { - public static IServiceCollection AddInfrastructureModules(this IServiceCollection services, IConfiguration configuration) + public static void AddInfrastructureModules(this IServiceCollection services, IConfiguration configuration) { var connectionString = configuration.GetConnectionString("ProjectPortalContext"); @@ -15,7 +15,5 @@ public static IServiceCollection AddInfrastructureModules(this IServiceCollectio b => b.MigrationsAssembly(typeof(ProjectExecutionPortalContext).Assembly.FullName) ) ); - - return services; } } diff --git a/backend/src/Equinor.ProjectExecutionPortal.Infrastructure/ProjectExecutionPortalContext.cs b/backend/src/Equinor.ProjectExecutionPortal.Infrastructure/ProjectExecutionPortalContext.cs index 5cabba755..7b01fdb75 100644 --- a/backend/src/Equinor.ProjectExecutionPortal.Infrastructure/ProjectExecutionPortalContext.cs +++ b/backend/src/Equinor.ProjectExecutionPortal.Infrastructure/ProjectExecutionPortalContext.cs @@ -33,16 +33,16 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) public static DateTimeKindConverter DateTimeKindConverter { get; } = new(); - public DbSet Portals { get; set; } - public DbSet PortalApps { get; set; } - public DbSet OnboardedApps { get; set; } - public DbSet OnboardedContexts { get; set; } - public DbSet ContextTypes { get; set; } + public DbSet Portals { get; init; } + public DbSet PortalApps { get; init; } + public DbSet OnboardedApps { get; init; } + public DbSet OnboardedContexts { get; init; } + public DbSet ContextTypes { get; init; } public override async Task SaveChangesAsync(CancellationToken cancellationToken = default) { await DispatchEventsAsync(cancellationToken); - await SetAuditDataAsync(); + SetAuditData(); try { @@ -63,12 +63,13 @@ private async Task DispatchEventsAsync(CancellationToken cancellationToken = def await _eventDispatcher.DispatchAsync(entities, cancellationToken); } - private async Task SetAuditDataAsync() + private void SetAuditData() { var addedEntries = ChangeTracker .Entries() .Where(x => x.State == EntityState.Added) .ToList(); + var modifiedEntries = ChangeTracker .Entries() .Where(x => x.State == EntityState.Modified) diff --git a/backend/src/Equinor.ProjectExecutionPortal.WebApi/DiModules/ApplicationModule.cs b/backend/src/Equinor.ProjectExecutionPortal.WebApi/DiModules/ApplicationModule.cs index 40fe5c7ff..c4ad6376c 100644 --- a/backend/src/Equinor.ProjectExecutionPortal.WebApi/DiModules/ApplicationModule.cs +++ b/backend/src/Equinor.ProjectExecutionPortal.WebApi/DiModules/ApplicationModule.cs @@ -1,5 +1,6 @@ using System.Reflection; using Equinor.ProjectExecutionPortal.Application; +using Equinor.ProjectExecutionPortal.Application.Cache; using Equinor.ProjectExecutionPortal.Application.Events.Common; using Equinor.ProjectExecutionPortal.Domain.Common.Events.Common; using Equinor.ProjectExecutionPortal.Domain.Common.Time; @@ -11,7 +12,6 @@ using FluentValidation; using MediatR; using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.Identity.Client; namespace Equinor.ProjectExecutionPortal.WebApi.DiModules; @@ -23,7 +23,7 @@ public static void AddApplicationModules(this IServiceCollection services, IConf var applicationAssembly = typeof(IApplicationMarker).GetTypeInfo().Assembly; - services.Configure(configuration.GetSection("CacheOptions")); + services.Configure(configuration.GetSection("Cache")); services.AddAuthorization(options => { diff --git a/backend/src/Equinor.ProjectExecutionPortal.WebApi/Program.cs b/backend/src/Equinor.ProjectExecutionPortal.WebApi/Program.cs index ea400c17a..998f03e28 100644 --- a/backend/src/Equinor.ProjectExecutionPortal.WebApi/Program.cs +++ b/backend/src/Equinor.ProjectExecutionPortal.WebApi/Program.cs @@ -1,6 +1,7 @@ using System.Text.Json.Serialization; using Equinor.ProjectExecutionPortal.WebApi.DiModules; using Equinor.ProjectExecutionPortal.WebApi.Middleware; +using FluentValidation; using FluentValidation.AspNetCore; using Fusion.Integration.Apps.Configuration; using Microsoft.AspNetCore.Authentication.JwtBearer; @@ -44,13 +45,14 @@ // Add fusion integration builder.Services.AddFusionIntegration(f => { - var environment = builder.Configuration.GetValue("Fusion:Environment" ?? "ci"); + var environment = builder.Configuration.GetValue("Fusion:Environment")!; + f.UseServiceInformation("Fusion.Project.Portal", environment); f.UseDefaultEndpointResolver(environment); f.AddAppsClient(); f.UseDefaultTokenProvider(opts => { - opts.ClientId = builder.Configuration.GetValue("AzureAd:ClientId"); + opts.ClientId = builder.Configuration.GetValue("AzureAd:ClientId")!; opts.ClientSecret = builder.Configuration.GetValue("AzureAd:ClientSecret"); }); f.DisableClaimsTransformation(); @@ -65,10 +67,8 @@ }) .AddJsonOptions(options => options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter())); -builder.Services.AddFluentValidation(c => - { - c.RegisterValidatorsFromAssemblyContaining(); - }); +builder.Services.AddFluentValidationAutoValidation(); +builder.Services.AddValidatorsFromAssemblyContaining(); builder.Services.AddEndpointsApiExplorer(); @@ -89,8 +89,8 @@ { Implicit = new OpenApiOAuthFlow { - AuthorizationUrl = new Uri(builder.Configuration["Swagger:AuthorizationUrl"]), - TokenUrl = new Uri(builder.Configuration["Swagger:TokenUrl"]), + AuthorizationUrl = new Uri(builder.Configuration["Swagger:AuthorizationUrl"]!), + TokenUrl = new Uri(builder.Configuration["Swagger:TokenUrl"]!), Scopes = scopes } } @@ -148,5 +148,4 @@ app.Run(); // Used for tests -public partial class Program -{ } +public abstract partial class Program; diff --git a/backend/src/Equinor.ProjectExecutionPortal.WebApi/appsettings.json b/backend/src/Equinor.ProjectExecutionPortal.WebApi/appsettings.json index bdd37ebbe..321916ba0 100644 --- a/backend/src/Equinor.ProjectExecutionPortal.WebApi/appsettings.json +++ b/backend/src/Equinor.ProjectExecutionPortal.WebApi/appsettings.json @@ -12,7 +12,7 @@ "Scope": "access_as_user" }, "Fusion": { - "Environment": "ci" + "Environment": "ci" }, "AzureAd": { "ClientId": "guid", // This app's AppReg key @@ -25,6 +25,9 @@ "ApplicationInsights": { "ConnectionString": "" }, + "Cache": { + "FusionAppsCacheMinutes": 60 + }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/ContextTypeData.cs b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/ContextTypeData.cs index 030a676af..740bb0ecf 100644 --- a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/ContextTypeData.cs +++ b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/ContextTypeData.cs @@ -2,24 +2,24 @@ namespace Equinor.ProjectExecutionPortal.Tests.WebApi.Data { - internal class ContextTypeData + internal static class ContextTypeData { - public class InitialDbSeedData + public static class InitialDbSeedData { - public static ContextType ContextType1 = new(ValidContextTypes.ProjectMasterContextTypeKey); - public static ContextType ContextType2 = new(ValidContextTypes.FacilityContextTypeKey); + public static readonly ContextType ContextType1 = new(ValidContextTypes.ProjectMasterContextTypeKey); + public static readonly ContextType ContextType2 = new(ValidContextTypes.FacilityContextTypeKey); } - public class ValidContextTypes + public static class ValidContextTypes { - public static string ProjectMasterContextTypeKey = "ProjectMaster"; - public static string FacilityContextTypeKey = "Facility"; - public static string ContractContextTypeKey = "Contract"; + public const string ProjectMasterContextTypeKey = "ProjectMaster"; + public const string FacilityContextTypeKey = "Facility"; + public const string ContractContextTypeKey = "Contract"; } - public class InvalidContextTypes + public static class InvalidContextTypes { - public static string InvalidContextTypeKey = "SuperContext"; + public const string InvalidContextTypeKey = "SuperContext"; } } } diff --git a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/FusionAppApiData.cs b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/FusionAppApiData.cs index bd5cf6f9e..28ae3100f 100644 --- a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/FusionAppApiData.cs +++ b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/FusionAppApiData.cs @@ -2,7 +2,7 @@ namespace Equinor.ProjectExecutionPortal.Tests.WebApi.Data { - internal class FusionAppApiData + internal static class FusionAppApiData { public static App MeetingsFusion => new() { diff --git a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/FusionContextApiData.cs b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/FusionContextApiData.cs index 4e37daea6..86d0a29f6 100644 --- a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/FusionContextApiData.cs +++ b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/FusionContextApiData.cs @@ -2,15 +2,15 @@ namespace Equinor.ProjectExecutionPortal.Tests.WebApi.Data { - internal class FusionContextApiData + internal static class FusionContextApiData { - public static string JcaContextExternalId = "fc5ffcbc-392f-4d7e-bb14-79a006579337"; + public const string JcaContextExternalId = "fc5ffcbc-392f-4d7e-bb14-79a006579337"; public static Guid JcaContextId = new("94dd5f4d-17f1-4312-bf75-ad75f4d9572c"); - public static string OgpContextExternalId = "91dd6653-a364-40c7-af26-7af516d66c42"; + public const string OgpContextExternalId = "91dd6653-a364-40c7-af26-7af516d66c42"; public static Guid OgpContextId = new("ce31b83a-b6cd-4267-89f3-db308edf721e"); - public static string MongstadContextExternalId = "09206ca3-02ac-4c65-adbf-caa7b66364ea"; + public const string MongstadContextExternalId = "09206ca3-02ac-4c65-adbf-caa7b66364ea"; public static Guid MongstadContextId = new("4CB78175-46CF-41A3-58DB-08DC74C80D40"); - public static string InvalidContextExternalId = "11111111-1111-1111-1111-111111111111"; + public const string InvalidContextExternalId = "11111111-1111-1111-1111-111111111111"; public static Guid InvalidContextId = new("11111111-1111-1111-1111-111111111111"); public static FusionContext JcaFusionContext => new() diff --git a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/OnboardedAppData.cs b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/OnboardedAppData.cs index 2857f4a84..f86bf7b4d 100644 --- a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/OnboardedAppData.cs +++ b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/OnboardedAppData.cs @@ -2,16 +2,16 @@ namespace Equinor.ProjectExecutionPortal.Tests.WebApi.Data { - internal class OnboardedAppData + internal static class OnboardedAppData { - public class InitialDbSeedData + public static class InitialDbSeedData { - public static OnboardedApp MeetingsApp = new("meetings"); - public static OnboardedApp ReviewsApp = new("reviews"); - public static OnboardedApp TasksApp = new("tasks"); - public static OnboardedApp OrgChartApp = new("one-equinor"); - public static OnboardedApp HandoverGardenApp = new("handover-garden"); - public static OnboardedApp WorkOrderGardenApp = new("workorder-garden"); + public static readonly OnboardedApp MeetingsApp = new("meetings"); + public static readonly OnboardedApp ReviewsApp = new("reviews"); + public static readonly OnboardedApp TasksApp = new("tasks"); + public static readonly OnboardedApp OrgChartApp = new("one-equinor"); + public static readonly OnboardedApp HandoverGardenApp = new("handover-garden"); + public static readonly OnboardedApp WorkOrderGardenApp = new("workorder-garden"); } } } diff --git a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/OnboardedContextData.cs b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/OnboardedContextData.cs index 46b98f6c4..197efe1d0 100644 --- a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/OnboardedContextData.cs +++ b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/OnboardedContextData.cs @@ -2,12 +2,12 @@ namespace Equinor.ProjectExecutionPortal.Tests.WebApi.Data { - internal class OnboardedContextData + internal static class OnboardedContextData { - public class InitialDbSeedData + public static class InitialDbSeedData { - public static OnboardedContext JcaContext = new(FusionContextApiData.JcaContextExternalId, ContextTypeData.ValidContextTypes.ProjectMasterContextTypeKey, "desc"); - public static OnboardedContext OgpContext = new(FusionContextApiData.OgpContextExternalId, ContextTypeData.ValidContextTypes.ProjectMasterContextTypeKey, "desc"); + public static readonly OnboardedContext JcaContext = new(FusionContextApiData.JcaContextExternalId, ContextTypeData.ValidContextTypes.ProjectMasterContextTypeKey, "desc"); + public static readonly OnboardedContext OgpContext = new(FusionContextApiData.OgpContextExternalId, ContextTypeData.ValidContextTypes.ProjectMasterContextTypeKey, "desc"); } } } diff --git a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/PortalConfigurationData.cs b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/PortalConfigurationData.cs index 6cc985782..c423f4a9c 100644 --- a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/PortalConfigurationData.cs +++ b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/PortalConfigurationData.cs @@ -2,11 +2,11 @@ namespace Equinor.ProjectExecutionPortal.Tests.WebApi.Data { - internal class PortalConfigurationData + internal static class PortalConfigurationData { - public class InitialDbSeedData + public static class InitialDbSeedData { - public static PortalConfiguration GenericPortalConfiguration = new( + public static readonly PortalConfiguration GenericPortalConfiguration = new( "routerConfig", "extensionConfig", "environmentConfig" diff --git a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/PortalData.cs b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/PortalData.cs index 1bcf82902..383ef8930 100644 --- a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/PortalData.cs +++ b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Data/PortalData.cs @@ -2,11 +2,11 @@ namespace Equinor.ProjectExecutionPortal.Tests.WebApi.Data { - internal class PortalData + internal static class PortalData { - public class InitialDbSeedData + public static class InitialDbSeedData { - public static Portal PortfolioManagement = new( + public static readonly Portal PortfolioManagement = new( "portfolio-management", "Portfolio Management", "< DG 3", @@ -15,7 +15,7 @@ public class InitialDbSeedData "" ); - public static Portal ProjectExecution = new("project-execution", + public static readonly Portal ProjectExecution = new("project-execution", "Project Execution", "DG 3 - DG 4", "Go to this phase to work with projects that are beyond DG3", diff --git a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Equinor.ProjectExecutionPortal.Tests.WebApi.csproj b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Equinor.ProjectExecutionPortal.Tests.WebApi.csproj index c33e82894..7fc97e136 100644 --- a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Equinor.ProjectExecutionPortal.Tests.WebApi.csproj +++ b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Equinor.ProjectExecutionPortal.Tests.WebApi.csproj @@ -17,8 +17,8 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - - + + diff --git a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/IntegrationTests/PortalControllerTests.cs b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/IntegrationTests/PortalControllerTests.cs index f5c775bc5..5f74982ca 100644 --- a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/IntegrationTests/PortalControllerTests.cs +++ b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/IntegrationTests/PortalControllerTests.cs @@ -77,7 +77,7 @@ public async Task Create_Portal_AsAdministratorUser_ShouldReturnOk() ShortName = "Created short name", Subtext = "Created subtext", Icon = "Created icon", - ContextTypes = new List { ContextTypeData.ValidContextTypes.ProjectMasterContextTypeKey } + ContextTypes = [ContextTypeData.ValidContextTypes.ProjectMasterContextTypeKey] }; // Act @@ -103,7 +103,15 @@ public async Task Create_Portal_AsAdministratorUser_ShouldReturnOk() public async Task Create_Portal_AsAuthenticatedUser_ShouldReturnForbidden() { // Arrange - var payload = new ApiCreatePortalRequest(); + var payload = new ApiCreatePortalRequest + { + Name = "Created portal name", + Description = "Created description", + ShortName = "Created short name", + Subtext = "Created subtext", + Icon = "Created icon", + ContextTypes = [ContextTypeData.ValidContextTypes.ProjectMasterContextTypeKey] + }; // Act var response = await CreatePortal(UserType.Authenticated, payload); @@ -116,7 +124,15 @@ public async Task Create_Portal_AsAuthenticatedUser_ShouldReturnForbidden() public async Task Create_Portal_AsAnonymousUser_ShouldReturnUnauthorized() { // Arrange - var payload = new ApiCreatePortalRequest(); + var payload = new ApiCreatePortalRequest + { + Name = "Created portal name", + Description = "Created description", + ShortName = "Created short name", + Subtext = "Created subtext", + Icon = "Created icon", + ContextTypes = [ContextTypeData.ValidContextTypes.ProjectMasterContextTypeKey] + }; // Act var response = await CreatePortal(UserType.Anonymous, payload); @@ -139,7 +155,7 @@ public async Task Update_Portal_AsAdministratorUser_ShouldReturnOk() ShortName = "Updated short name", Subtext = "Updated subtext", Icon = "Updated icon", - ContextTypes = new List { ContextTypeData.ValidContextTypes.ProjectMasterContextTypeKey } + ContextTypes = [ContextTypeData.ValidContextTypes.ProjectMasterContextTypeKey] }; // Act @@ -162,7 +178,15 @@ public async Task Update_Portal_AsAdministratorUser_ShouldReturnOk() public async Task Update_Portal_AsAuthenticatedUser_ShouldReturnForbidden() { // Arrange - var payload = new ApiUpdatePortalRequest(); + var payload = new ApiUpdatePortalRequest + { + Name = "Updated portal name", + Description = "Updated description", + ShortName = "Updated short name", + Subtext = "Updated subtext", + Icon = "Updated icon", + ContextTypes = [ContextTypeData.ValidContextTypes.ProjectMasterContextTypeKey] + }; // Act var response = await UpdatePortal(UserType.Authenticated, payload, Guid.NewGuid()); @@ -175,7 +199,15 @@ public async Task Update_Portal_AsAuthenticatedUser_ShouldReturnForbidden() public async Task Update_Portal_AsAnonymousUser_ShouldReturnUnauthorized() { // Arrange - var payload = new ApiUpdatePortalRequest(); + var payload = new ApiUpdatePortalRequest + { + Name = "Updated portal name", + Description = "Updated description", + ShortName = "Updated short name", + Subtext = "Updated subtext", + Icon = "Updated icon", + ContextTypes = [ContextTypeData.ValidContextTypes.ProjectMasterContextTypeKey] + }; // Act var response = await UpdatePortal(UserType.Anonymous, payload, Guid.NewGuid()); @@ -442,7 +474,7 @@ public async Task Delete_Portal_AsAdministrator_ShouldReturnOk() ShortName = "Created short name", Subtext = "Created subtext", Icon = "Created icon", - ContextTypes = new List { "ProjectMaster" } + ContextTypes = [ContextTypeData.ValidContextTypes.ProjectMasterContextTypeKey] }; await CreatePortal(UserType.Administrator, payload); diff --git a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Setup/IntegrationTestAuthHandler.cs b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Setup/IntegrationTestAuthHandler.cs index 889442019..77df091f0 100644 --- a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Setup/IntegrationTestAuthHandler.cs +++ b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Setup/IntegrationTestAuthHandler.cs @@ -48,7 +48,7 @@ protected override async Task HandleAuthenticateAsync() private Task> GatherTestUserClaimsAsync() { var authorizationHeader = Request.Headers["Authorization"]; - var tokens = authorizationHeader.ToString()?.Split(' '); + var tokens = authorizationHeader.ToString().Split(' '); if (tokens == null || tokens.Length <= 1) { throw new Exception("[Authorization] header missing"); diff --git a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Setup/IntegrationTestAuthOptions.cs b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Setup/IntegrationTestAuthOptions.cs index eedcfd663..7be669141 100644 --- a/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Setup/IntegrationTestAuthOptions.cs +++ b/backend/src/tests/Equinor.ProjectExecutionPortal.Tests.WebApi/Setup/IntegrationTestAuthOptions.cs @@ -2,7 +2,5 @@ namespace Equinor.ProjectExecutionPortal.Tests.WebApi.Setup { - internal class IntegrationTestAuthOptions : AuthenticationSchemeOptions - { - } + internal class IntegrationTestAuthOptions : AuthenticationSchemeOptions; } diff --git a/clientBackend/src/Equinor.ProjectExecutionPortal.ClientBackend/Program.cs b/clientBackend/src/Equinor.ProjectExecutionPortal.ClientBackend/Program.cs index f53dec038..fc4b24b7b 100644 --- a/clientBackend/src/Equinor.ProjectExecutionPortal.ClientBackend/Program.cs +++ b/clientBackend/src/Equinor.ProjectExecutionPortal.ClientBackend/Program.cs @@ -2,7 +2,6 @@ using Equinor.ProjectExecutionPortal.ClientBackend.Modules; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.OpenIdConnect; -using Microsoft.Identity.Client; using Microsoft.Identity.Web; var builder = WebApplication.CreateBuilder(args); @@ -17,7 +16,6 @@ builder.Services.Configure(builder.Configuration.GetSection("FusionProjectPortalApi")); builder.Services.Configure(builder.Configuration.GetSection("AssetProxy")); builder.Services.Configure(builder.Configuration.GetSection("ApplicationInsights")); -builder.Services.Configure(builder.Configuration.GetSection("Cache")); // Add bearer auth builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)