Skip to content

Commit 64ac61a

Browse files
committed
ecer-5253 obtaining dynamics feature flag and using it in vue
1 parent 81f76c1 commit 64ac61a

File tree

12 files changed

+1578
-1487
lines changed

12 files changed

+1578
-1487
lines changed

src/ECER.Clients.RegistryPortal/ECER.Clients.RegistryPortal.Server/ConfigurationEndpoints.cs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using AutoMapper;
2-
using ECER.Clients.RegistryPortal.Server.Applications;
32
using ECER.Clients.RegistryPortal.Server.Shared;
43
using ECER.Managers.Admin.Contract.Metadatas;
54
using ECER.Utilities.Hosting;
@@ -12,13 +11,20 @@ public class ConfigurationEndpoints : IRegisterEndpoints
1211
{
1312
public void Register(IEndpointRouteBuilder endpointRouteBuilder)
1413
{
15-
endpointRouteBuilder.MapGet("/api/configuration", async (HttpContext ctx) =>
14+
endpointRouteBuilder.MapGet("/api/configuration", async (HttpContext ctx, IMediator messageBus, CancellationToken ct) =>
1615
{
1716
await Task.CompletedTask;
1817
var configuration = ctx.RequestServices.GetRequiredService<IConfiguration>();
18+
19+
var dynamicsConfig = await messageBus.Send(new DynamicsConfigQuery(), ct);
1920
var appConfig = configuration.Get<ApplicationConfiguration>()!;
21+
22+
23+
appConfig.ICRAFeatureEnabled = dynamicsConfig.config.ICRAFeatureEnabled;
24+
2025
return TypedResults.Ok(appConfig);
21-
}).WithOpenApi("Returns the UI initial configuration", string.Empty, "configuration_get");
26+
}).WithOpenApi("Returns the UI initial configuration", string.Empty, "configuration_get")
27+
.CacheOutput(p => p.Expire(TimeSpan.FromMinutes(5)));
2228

2329
endpointRouteBuilder.MapGet("/api/provincelist", async (HttpContext ctx, IMediator messageBus, IMapper mapper, CancellationToken ct) =>
2430
{
@@ -28,7 +34,6 @@ public void Register(IEndpointRouteBuilder endpointRouteBuilder)
2834
.WithOpenApi("Handles province queries", string.Empty, "province_get")
2935
.CacheOutput(p => p.Expire(TimeSpan.FromMinutes(5)));
3036

31-
3237
endpointRouteBuilder.MapGet("/api/defaultContents", async (HttpContext ctx, IMediator messageBus, IMapper mapper, CancellationToken ct) =>
3338
{
3439
var results = await messageBus.Send(new DefaultContentsQuery(), ct);
@@ -93,6 +98,7 @@ public void Register(IEndpointRouteBuilder endpointRouteBuilder)
9398
public record ApplicationConfiguration
9499
{
95100
public Dictionary<string, OidcAuthenticationSettings> ClientAuthenticationMethods { get; set; } = [];
101+
public bool ICRAFeatureEnabled { get; set; }
96102
}
97103

98104
#pragma warning restore CA2227 // Collection properties should be read only
@@ -128,21 +134,21 @@ public record IdentificationTypesQuery
128134
public bool? ForPrimary { get; set; }
129135
public bool? ForSecondary { get; set; }
130136
}
131-
public record OutOfProvinceCertificationType(string Id)
132-
{
133-
public string? CertificationType { get; set; }
134-
}
137+
public record OutOfProvinceCertificationType(string Id)
138+
{
139+
public string? CertificationType { get; set; }
140+
}
135141

136-
public record CertificationComparison(string Id)
137-
{
138-
public string? BcCertificate { get; set; }
139-
}
142+
public record CertificationComparison(string Id)
143+
{
144+
public string? BcCertificate { get; set; }
145+
}
140146

141-
public record ComparisonRecord()
142-
{
143-
public OutOfProvinceCertificationType? TransferringCertificate { get; set; }
144-
public IEnumerable<CertificationComparison> Options { get; set; } = Array.Empty<CertificationComparison>();
145-
}
147+
public record ComparisonRecord()
148+
{
149+
public OutOfProvinceCertificationType? TransferringCertificate { get; set; }
150+
public IEnumerable<CertificationComparison> Options { get; set; } = Array.Empty<CertificationComparison>();
151+
}
146152
public record DefaultContent
147153
{
148154
public string? Name { get; set; }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!-- this component will render the child based on the outcome of the ICRA flag from dynamics -->
2+
<template>
3+
<slot v-if="configStore.applicationConfiguration.icraFeatureEnabled"></slot>
4+
</template>
5+
6+
<script lang="ts">
7+
import { defineComponent } from "vue";
8+
import { useConfigStore } from "@/store/config";
9+
10+
export default defineComponent({
11+
name: "ConditionalRenderICRA",
12+
setup() {
13+
const configStore = useConfigStore();
14+
return { configStore };
15+
},
16+
});
17+
</script>

src/ECER.Clients.RegistryPortal/ecer.clients.registryportal.client/src/router.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useCertificationStore } from "./store/certification";
77
import { useFormStore } from "./store/form";
88
import { useMessageStore } from "./store/message";
99
import { useWizardStore } from "./store/wizard";
10+
import { useConfigStore } from "./store/config";
1011

1112
const router = createRouter({
1213
history: createWebHistory(),
@@ -390,4 +391,13 @@ router.beforeEach((to, _, next) => {
390391
} else next();
391392
});
392393

394+
// Guard to prevent users from accessing ICRA routes if the flag is not enabled
395+
router.beforeEach((to, _, next) => {
396+
const configStore = useConfigStore();
397+
if (to.meta.requiresICRAFeature && !configStore.applicationConfiguration.icraFeatureEnabled) {
398+
console.warn("ICRA feature is not enabled, redirecting to home page.");
399+
next({ path: "/" });
400+
} else next();
401+
});
402+
393403
export default router;

0 commit comments

Comments
 (0)