Skip to content

Commit

Permalink
Merge branch 'main' into feature/DP-689-request-to-join-notify
Browse files Browse the repository at this point in the history
  • Loading branch information
rmohammed-goaco authored Oct 21, 2024
2 parents 68ed21b + 44621dd commit 8ef55b3
Show file tree
Hide file tree
Showing 17 changed files with 3,171 additions and 19 deletions.
5 changes: 0 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ ARG BUILD_CONFIGURATION
WORKDIR /src/Services/CO.CDP.Person.WebApi
RUN dotnet build -c $BUILD_CONFIGURATION -o /app/build

FROM build AS build-localization
ARG BUILD_CONFIGURATION
WORKDIR /src/Services/CO.CDP.Localization
RUN dotnet build -c $BUILD_CONFIGURATION -o /app/build

FROM build AS build-forms
ARG BUILD_CONFIGURATION
WORKDIR /src/Services/CO.CDP.Forms.WebApi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
using AutoMapper;
using CO.CDP.DataSharing.WebApi.AutoMapper;
using CO.CDP.Localization;
using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.Extensions.DependencyInjection;
using Moq;

namespace CO.CDP.DataSharing.WebApi.Tests.AutoMapper;

public class AutoMapperFixture
{
public IMapper Mapper => Configuration.CreateMapper();

public readonly MapperConfiguration Configuration = new(
config => config.AddProfile<DataSharingProfile>()
);
}

public IMapper Mapper { get; }

public AutoMapperFixture()
{
var localizerMock = new Mock<IHtmlLocalizer<FormsEngineResource>>();

localizerMock.Setup(l => l[It.IsAny<string>()])
.Returns((string key) =>
{
if (key == "FinancialInformation_SectionTitle")
{
return new LocalizedHtmlString("FinancialInformation_SectionTitle", "Financial Information");
}

return new LocalizedHtmlString(key, key);
});

var services = new ServiceCollection();
services.AddSingleton<IHtmlLocalizer<FormsEngineResource>>(localizerMock.Object);
services.AddTransient(typeof(NullableLocalizedPropertyResolver<,>));
services.AddTransient(typeof(LocalizedPropertyResolver<,>));

var serviceProvider = services.BuildServiceProvider();

Mapper = Configuration.CreateMapper(type => serviceProvider.GetService(type) ?? Activator.CreateInstance(type));
}
}
2 changes: 1 addition & 1 deletion Services/CO.CDP.DataSharing.WebApi.Tests/EntityFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private static PersistenceForms.FormSection GivenSection(Guid sectionId, Persist
FormId = form.Id,
Form = form,
Questions = new List<PersistenceForms.FormQuestion>(),
Title = "Test Section",
Title = "FinancialInformation_SectionTitle",
Type = sectionType ?? PersistenceForms.FormSectionType.Declaration,
AllowsMultipleAnswerSets = true,
CheckFurtherQuestionsExempted = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ private void AssertSupplierInformationData(SupplierInformationData? supplierInfo
supplierInformationData?.AnswerSets.First().Answers.Should().HaveCount(3);

supplierInformationData?.AnswerSets.First().SectionName.Should().NotBeNull();
supplierInformationData?.AnswerSets.First().SectionName.Should().Be("Financial Information");

supplierInformationData?.AnswerSets.First().Answers.First().QuestionName.Should().NotBeNull();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public DataSharingProfile()

CreateMap<Persistence.FormAnswerSet, FormAnswerSet>()
.ForMember(m => m.Id, o => o.MapFrom(m => m.Guid))
.ForMember(m=>m.SectionName, o=>o.MapFrom(m=>m.Section.Title))
.ForMember(m => m.SectionName, opt => opt.MapFrom<LocalizedPropertyResolver<Persistence.FormAnswerSet, FormAnswerSet>, string>(m => m.Section.Title))
.ForMember(m => m.Answers, o => o.MapFrom(m => m.Answers.Where(x => x.Question.Type != Persistence.FormQuestionType.NoInput && x.Question.Type != Persistence.FormQuestionType.CheckYourAnswers)));

CreateMap<Persistence.FormAnswer, FormAnswer>()
Expand All @@ -113,7 +113,7 @@ public DataSharingProfile()
.ForMember(m => m.Name, o => o.MapFrom(m => m.Name))
.ForMember(m => m.Text, o => o.MapFrom(m => m.Description))
.ForMember(m => m.IsRequired, o => o.MapFrom(m => m.IsRequired))
.ForMember(m => m.SectionName, o => o.MapFrom(m => m.Section.Title))
.ForMember(m => m.SectionName, opt => opt.MapFrom<LocalizedPropertyResolver<Persistence.FormQuestion, FormQuestion>, string>(m => m.Section.Title))
.ForMember(m => m.Options, o => o.MapFrom(m => m.Options.Choices))
.ForMember(m => m.SortOrder, o => o.MapFrom(m => m.SortOrder));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using AutoMapper;
using CO.CDP.Localization;
using Microsoft.AspNetCore.Mvc.Localization;

namespace CO.CDP.DataSharing.WebApi.AutoMapper;

public class LocalizedPropertyResolver<TSource, TDestination> : IMemberValueResolver<TSource, TDestination, string, string>
{
private readonly IHtmlLocalizer<FormsEngineResource> _localizer;

public LocalizedPropertyResolver(IHtmlLocalizer<FormsEngineResource> localizer)
{
_localizer = localizer;
}

public string Resolve(TSource source, TDestination destination, string sourceMember, string destMember, ResolutionContext context)
{
return _localizer[sourceMember].Value;
}
}

public class NullableLocalizedPropertyResolver<TSource, TDestination> : IMemberValueResolver<TSource, TDestination, string?, string?>
{
private readonly IHtmlLocalizer<FormsEngineResource> _localizer;

public NullableLocalizedPropertyResolver(IHtmlLocalizer<FormsEngineResource> localizer)
{
_localizer = localizer;
}

public string? Resolve(TSource? source, TDestination? destination, string? sourceMember, string? destMember, ResolutionContext context)
{
if (sourceMember == null)
{
return null;
}

return _localizer[sourceMember].Value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<InvariantGlobalization>false</InvariantGlobalization>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<OpenApiDocumentsDirectory>$(MSBuildProjectDirectory)/OpenAPI</OpenApiDocumentsDirectory>
<OpenApiGenerateDocuments>true</OpenApiGenerateDocuments>
Expand All @@ -26,6 +26,7 @@
<ProjectReference Include="..\..\Libraries\CO.CDP.Functional\CO.CDP.Functional.csproj" />
<ProjectReference Include="..\..\Libraries\CO.CDP.Swashbuckle\CO.CDP.Swashbuckle.csproj" />
<ProjectReference Include="..\..\Libraries\CO.CDP.Configuration\CO.CDP.Configuration.csproj" />
<ProjectReference Include="..\CO.CDP.Localization\CO.CDP.Localization.csproj" />
<ProjectReference Include="..\CO.CDP.OrganisationInformation.Persistence\CO.CDP.OrganisationInformation.Persistence.csproj" />
<ProjectReference Include="..\CO.CDP.OrganisationInformation\CO.CDP.OrganisationInformation.csproj" />
</ItemGroup>
Expand Down
23 changes: 23 additions & 0 deletions Services/CO.CDP.DataSharing.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
using CO.CDP.DataSharing.WebApi.Model;
using CO.CDP.DataSharing.WebApi.UseCase;
using CO.CDP.OrganisationInformation.Persistence;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.EntityFrameworkCore;
using System.Globalization;
using System.Reflection;

var builder = WebApplication.CreateBuilder(args);
Expand All @@ -21,8 +24,27 @@
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options => { options.DocumentDataSharingApi(builder.Configuration); });

builder.Services.AddLocalization();

// Note that we have to register IHtmlLocalizer manually, since this is an API and we are not calling AddViewLocalization
builder.Services.AddSingleton<IHtmlLocalizerFactory, HtmlLocalizerFactory>();
builder.Services.AddTransient(typeof(IHtmlLocalizer<>), typeof(HtmlLocalizer<>));

var supportedCultures = new[] { new CultureInfo("en"), new CultureInfo("cy") };
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
options.DefaultRequestCulture = new RequestCulture("en");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;

options.RequestCultureProviders.Insert(0, new AcceptLanguageHeaderRequestCultureProvider());
});

builder.Services.AddHealthChecks()
.AddNpgSql(ConnectionStringHelper.GetConnectionString(builder.Configuration, "OrganisationInformationDatabase"));

builder.Services.AddTransient(typeof(LocalizedPropertyResolver<,>));
builder.Services.AddAutoMapper(typeof(DataSharingProfile));

builder.Services.AddDbContext<OrganisationInformationContext>(o =>
Expand Down Expand Up @@ -82,6 +104,7 @@
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.UseRequestLocalization();
app.UseDataSharingEndpoints();

app.Run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public SupportUpdateOrganisationUseCaseTests()
{
Id = 1,
Guid = Guid.NewGuid(),
Roles = [],
Roles = [PartyRole.Tenderer],
PendingRoles = [PartyRole.Buyer],
Tenant = null!,
Name = null!,
Expand Down Expand Up @@ -147,7 +147,7 @@ public async Task Execute_WhenUpdateIsReviewAndApprovedAndEmailIsSent_ShouldUpda
_organisation.ApprovedOn.Should().BeCloseTo(DateTimeOffset.UtcNow, TimeSpan.FromSeconds(1));
_organisation.ReviewedBy.Should().Be(_person);
_organisation.ReviewComment.Should().Be("Reviewed and approved");
_organisation.Roles.Should().BeEquivalentTo([PartyRole.Buyer]);
_organisation.Roles.Should().BeEquivalentTo([PartyRole.Tenderer, PartyRole.Buyer]);
_organisation.PendingRoles.Should().BeEmpty();

_notifyApiClient.Verify(x => x.SendEmail(It.IsAny<EmailNotificationRequest>()));
Expand Down Expand Up @@ -181,7 +181,7 @@ public async Task Execute_WhenUpdateIsReviewAndNotApproved_ShouldNotSetApprovalD
_organisation.ApprovedOn.Should().BeNull();
_organisation.ReviewedBy.Should().Be(_person);
_organisation.ReviewComment.Should().Be("Reviewed but rejected");
_organisation.Roles.Should().BeEmpty();
_organisation.Roles.Should().BeEquivalentTo([PartyRole.Tenderer]);
_organisation.PendingRoles.Should().BeEquivalentTo([PartyRole.Buyer]);

_mockOrganisationRepository.Verify(repo => repo.Save(_organisation), Times.Once);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public async Task<bool> Execute((Guid organisationId, SupportUpdateOrganisation
if (command.supportUpdateOrganisation.Organisation.Approved)
{
organisation.ApprovedOn = DateTimeOffset.UtcNow;
organisation.Roles = organisation.PendingRoles;
organisation.PendingRoles = [];
organisation.PendingRoles.ForEach(r => organisation.Roles.Add(r));
organisation.PendingRoles.Clear();
sendemail = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class Organisation : IEntityDate
public IList<Identifier> Identifiers { get; set; } = [];
public ICollection<OrganisationAddress> Addresses { get; set; } = [];
public ICollection<ContactPoint> ContactPoints { get; set; } = [];
public List<PartyRole> Roles { get; set; } = [];
public List<PartyRole> PendingRoles { get; set; } = [];
public List<PartyRole> Roles { get; init; } = [];
public List<PartyRole> PendingRoles { get; init; } = [];
public List<Person> Persons => OrganisationPersons.Select(p => p.Person).ToList();
public List<OrganisationPerson> OrganisationPersons { get; set; } = [];
public SupplierInformation? SupplierInfo { get; set; }
Expand Down
1 change: 1 addition & 0 deletions terragrunt/tools/grafana/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ COPY configs/datasource.yaml.tpl /etc/grafana/provisioning/datasources/datasourc
COPY configs/dashboard.yaml /etc/grafana/provisioning/dashboards/dashboard.yaml
COPY configs/entrypoint.sh /entrypoint.sh
COPY configs/dashboards /etc/grafana/provisioning/dashboards/
COPY configs/grafana.ini /etc/grafana/grafana.ini

ENTRYPOINT ["/entrypoint.sh"]
10 changes: 10 additions & 0 deletions terragrunt/tools/grafana/configs/dashboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ providers:
updateIntervalSeconds: 10
options:
path: /etc/grafana/provisioning/dashboards/application

- name: 'infrastructure'
orgId: 1
folder: 'Infrastructure'
Expand All @@ -16,3 +17,12 @@ providers:
updateIntervalSeconds: 10
options:
path: /etc/grafana/provisioning/dashboards/infrastructure

- name: 'overview'
orgId: 1
folder: 'Overview'
type: file
disableDeletion: false
updateIntervalSeconds: 10
options:
path: /etc/grafana/provisioning/dashboards/overview
Loading

0 comments on commit 8ef55b3

Please sign in to comment.