diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/OpenApi/ExcludeFromSchemaAttribute.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/OpenApi/ExcludeFromSchemaAttribute.cs new file mode 100644 index 0000000000..6686a4cf2b --- /dev/null +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/OpenApi/ExcludeFromSchemaAttribute.cs @@ -0,0 +1,6 @@ +namespace TeachingRecordSystem.Api.Infrastructure.OpenApi; + +[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] +public sealed class ExcludeFromSchemaAttribute : Attribute +{ +} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/OpenApi/RemoveExcludedEnumOptionsSchemaProcessor.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/OpenApi/RemoveExcludedEnumOptionsSchemaProcessor.cs new file mode 100644 index 0000000000..c81e97c67b --- /dev/null +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/OpenApi/RemoveExcludedEnumOptionsSchemaProcessor.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using NJsonSchema.Generation; + +namespace TeachingRecordSystem.Api.Infrastructure.OpenApi; + +public class RemoveExcludedEnumOptionsSchemaProcessor : ISchemaProcessor +{ + public void Process(SchemaProcessorContext context) + { + var type = context.ContextualType.Type; + + if (!type.IsEnum) + { + return; + } + + foreach (var memberName in Enum.GetNames(type)) + { + var member = type.GetField(memberName)!; + if (member.GetCustomAttribute() is not null) + { + context.Schema.Enumeration.Remove(memberName); + context.Schema.EnumerationNames.Remove(memberName); + } + } + } +} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/OpenApi/ServiceCollectionExtensions.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/OpenApi/ServiceCollectionExtensions.cs index d077a9677a..1dee59527b 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/OpenApi/ServiceCollectionExtensions.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/OpenApi/ServiceCollectionExtensions.cs @@ -22,6 +22,7 @@ public static IServiceCollection AddOpenApi(this IServiceCollection services, IC settings.DocumentProcessors.Add(new PopulateResponseDescriptionOperationProcessor()); settings.SchemaProcessors.Add(new RemoveCompositeValuesFromFlagsEnumSchemaProcessor()); + settings.SchemaProcessors.Add(new RemoveExcludedEnumOptionsSchemaProcessor()); settings.OperationProcessors.Add(new ResponseContentTypeOperationProcessor()); settings.OperationProcessors.Add(new PopulateResponseDescriptionOperationProcessor()); diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Handlers/GetTeacherHandler.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Handlers/GetTeacherHandler.cs index 1782e6c3dc..396f97fdf6 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Handlers/GetTeacherHandler.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Handlers/GetTeacherHandler.cs @@ -39,7 +39,8 @@ public GetTeacherHandler(IDataverseAdapter dataverseAdapter, ICrmQueryDispatcher Contact.Fields.dfeta_NINumber, Contact.Fields.dfeta_QTSDate, Contact.Fields.dfeta_EYTSDate, - Contact.Fields.EMailAddress1 + Contact.Fields.EMailAddress1, + Contact.Fields.dfeta_AllowIDSignInWithProhibitions }); if (teacher is null) @@ -214,6 +215,10 @@ public GetTeacherHandler(IDataverseAdapter dataverseAdapter, ICrmQueryDispatcher var qtsAwardedInWales = qtsRegistrations.Any(qts => qts.dfeta_QTSDate is not null && qts.dfeta_TeacherStatusId.Id == qtsAwardedInWalesStatus.Id); + var allowIdSignInWithProhibitions = request.Include.HasFlag(GetTeacherRequestIncludes._AllowIdSignInWithProhibitions) ? + Option.Some(teacher.dfeta_AllowIDSignInWithProhibitions == true) : + default; + return new GetTeacherResponse() { Trn = request.Trn, @@ -270,7 +275,8 @@ public GetTeacherHandler(IDataverseAdapter dataverseAdapter, ICrmQueryDispatcher AlertType = AlertType.Prohibition, DqtSanctionCode = s.SanctionCode })) : - default + default, + AllowIdSignInWithProhibitions = allowIdSignInWithProhibitions }; } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Requests/GetTeacherRequest.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Requests/GetTeacherRequest.cs index 7bdd943d01..7794dffe00 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Requests/GetTeacherRequest.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Requests/GetTeacherRequest.cs @@ -1,5 +1,6 @@ using System.ComponentModel; using MediatR; +using TeachingRecordSystem.Api.Infrastructure.OpenApi; using TeachingRecordSystem.Api.V3.Responses; namespace TeachingRecordSystem.Api.V3.Requests; @@ -26,5 +27,8 @@ public enum GetTeacherRequestIncludes Sanctions = 1 << 6, Alerts = 1 << 7, + [ExcludeFromSchema] + _AllowIdSignInWithProhibitions = 1 << 8, + All = Induction | InitialTeacherTraining | NpqQualifications | MandatoryQualifications | PendingDetailChanges | HigherEducationQualifications | Sanctions | Alerts } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Responses/GetTeacherResponse.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Responses/GetTeacherResponse.cs index 8ded8421ab..ac5123035f 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Responses/GetTeacherResponse.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Responses/GetTeacherResponse.cs @@ -24,6 +24,7 @@ public record GetTeacherResponse public required Option> HigherEducationQualifications { get; init; } public required Option> Sanctions { get; init; } public required Option> Alerts { get; init; } + public required Option AllowIdSignInWithProhibitions { get; init; } } public record GetTeacherResponseQts diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Models/GeneratedCode.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Models/GeneratedCode.cs index c3a14f24ad..59042a8fbe 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Models/GeneratedCode.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Models/GeneratedCode.cs @@ -1272,6 +1272,7 @@ public static class Fields public const string Id = "contactid"; public const string CreatedOn = "createdon"; public const string dfeta_ActiveSanctions = "dfeta_activesanctions"; + public const string dfeta_AllowIDSignInWithProhibitions = "dfeta_allowidsigninwithprohibitions"; public const string dfeta_AllowPiiUpdatesFromRegister = "dfeta_allowpiiupdatesfromregister"; public const string dfeta_EYTSDate = "dfeta_eytsdate"; public const string dfeta_HUSID = "dfeta_husid"; @@ -1605,6 +1606,26 @@ public System.Nullable dfeta_ActiveSanctions } } + /// + /// + /// + [Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("dfeta_allowidsigninwithprohibitions")] + public System.Nullable dfeta_AllowIDSignInWithProhibitions + { + [System.Diagnostics.DebuggerNonUserCode()] + get + { + return this.GetAttributeValue>("dfeta_allowidsigninwithprohibitions"); + } + [System.Diagnostics.DebuggerNonUserCode()] + set + { + this.OnPropertyChanging("dfeta_AllowIDSignInWithProhibitions"); + this.SetAttributeValue("dfeta_allowidsigninwithprohibitions", value); + this.OnPropertyChanged("dfeta_AllowIDSignInWithProhibitions"); + } + } + /// /// /// diff --git a/crm_attributes.json b/crm_attributes.json index 25d2a93a0c..330925db71 100644 --- a/crm_attributes.json +++ b/crm_attributes.json @@ -58,7 +58,8 @@ "telephone1", "dfeta_slugid", "dfeta_allowpiiupdatesfromregister", - "dfeta_previouslastname" + "dfeta_previouslastname", + "dfeta_AllowIDSignInWithProhibitions" ], "dfeta_businesseventaudit":[ "createdon", diff --git a/tools/coretools/CrmSvcUtil.exe.config b/tools/coretools/CrmSvcUtil.exe.config index 6c2bfa1baf..344144d1c3 100644 --- a/tools/coretools/CrmSvcUtil.exe.config +++ b/tools/coretools/CrmSvcUtil.exe.config @@ -20,7 +20,7 @@ - +