Skip to content

Commit 1812111

Browse files
committed
Fixes file extension validation
1 parent 46f3744 commit 1812111

File tree

6 files changed

+43
-27
lines changed

6 files changed

+43
-27
lines changed

DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ int adminId
198198

199199
void UpdateFrameworkConfig(int frameworkId, int adminId, string? frameworkConfig);
200200

201-
void UpdateFrameworkCompetencyGroup(
201+
bool UpdateFrameworkCompetencyGroup(
202202
int frameworkCompetencyGroupId,
203203
int competencyGroupId,
204204
string name,
@@ -973,7 +973,7 @@ FROM FrameworkCompetencies AS fc
973973
);
974974
}
975975

976-
public void UpdateFrameworkCompetencyGroup(
976+
public bool UpdateFrameworkCompetencyGroup(
977977
int frameworkCompetencyGroupId,
978978
int competencyGroupId,
979979
string name,
@@ -986,7 +986,7 @@ int adminId
986986
logger.LogWarning(
987987
$"Not updating framework competency group as it failed server side validation. AdminId: {adminId}, frameworkCompetencyGroupId: {frameworkCompetencyGroupId}, competencyGroupId: {competencyGroupId}, name: {name}"
988988
);
989-
return;
989+
return false;
990990
}
991991

992992
var usedElsewhere = connection.QuerySingle<int>(
@@ -1005,29 +1005,40 @@ int adminId
10051005
SET CompetencyGroupID = @newCompetencyGroupId, UpdatedByAdminID = @adminId
10061006
WHERE ID = @frameworkCompetencyGroupId",
10071007
new { newCompetencyGroupId, adminId, frameworkCompetencyGroupId }
1008+
10081009
);
10091010
if (numberOfAffectedRows < 1)
10101011
{
10111012
logger.LogWarning(
10121013
"Not updating competency group id as db update failed. " +
10131014
$"newCompetencyGroupId: {newCompetencyGroupId}, admin id: {adminId}, frameworkCompetencyGroupId: {frameworkCompetencyGroupId}"
10141015
);
1016+
return false;
1017+
}
1018+
else
1019+
{
1020+
return true;
10151021
}
10161022
}
1023+
else
1024+
{
1025+
return false;
1026+
}
10171027
}
10181028
else
10191029
{
10201030
var numberOfAffectedRows = connection.Execute(
10211031
@"UPDATE CompetencyGroups SET Name = @name, UpdatedByAdminID = @adminId, Description = @description
1022-
WHERE ID = @competencyGroupId",
1032+
WHERE ID = @competencyGroupId AND (Name <> @name OR Description <> @description)",
10231033
new { name, adminId, competencyGroupId, description }
10241034
);
10251035
if (numberOfAffectedRows < 1)
10261036
{
1027-
logger.LogWarning(
1028-
"Not updating competency group name as db update failed. " +
1029-
$"Name: {name}, admin id: {adminId}, competencyGroupId: {competencyGroupId}"
1030-
);
1037+
return false;
1038+
}
1039+
else
1040+
{
1041+
return true;
10311042
}
10321043
}
10331044
}

DigitalLearningSolutions.Web/Services/FrameworkService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ int adminId
192192

193193
void UpdateFrameworkConfig(int frameworkId, int adminId, string? frameworkConfig);
194194

195-
void UpdateFrameworkCompetencyGroup(
195+
bool UpdateFrameworkCompetencyGroup(
196196
int frameworkCompetencyGroupId,
197197
int competencyGroupId,
198198
string name,
@@ -678,9 +678,9 @@ public void UpdateFrameworkCompetency(int frameworkCompetencyId, string name, st
678678
frameworkDataService.UpdateFrameworkCompetency(frameworkCompetencyId, name, description, adminId, alwaysShowDescription);
679679
}
680680

681-
public void UpdateFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, string name, string? description, int adminId)
681+
public bool UpdateFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, string name, string? description, int adminId)
682682
{
683-
frameworkDataService.UpdateFrameworkCompetencyGroup(frameworkCompetencyGroupId, competencyGroupId, name, description, adminId);
683+
return frameworkDataService.UpdateFrameworkCompetencyGroup(frameworkCompetencyGroupId, competencyGroupId, name, description, adminId);
684684
}
685685

686686
public void UpdateFrameworkConfig(int frameworkId, int adminId, string? frameworkConfig)

DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/ImportCompetenciesFormData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class ImportCompetenciesFormData
88
{
99
[Required(ErrorMessage = "Import competencies file is required")]
10-
[AllowedExtensions(new[] { ".xlsx" }, "Import competencies file must be in xlsx format")]
10+
[AllowedExtensions([".xlsx"], "Import competencies file must be in xlsx format")]
1111
[MaxFileSize(5 * 1024 * 1024, "Maximum allowed file size is 5MB")]
1212
public IFormFile? ImportFile { get; set; }
1313
}

DigitalLearningSolutions.Web/Views/Shared/Components/DateInput/Default.cshtml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
var yearErrorCss = Model.HasYearError ? "nhsuk-input--error" : "";
99
var hintTextLine = string.Empty;
1010
}
11-
11+
@* Removed pattern property *@
1212
<div class="@Model.CssClass @errorCss" id="@Model.Id">
1313
<fieldset class="nhsuk-fieldset" aria-describedby="@Model.Id-hint" role="group">
1414
<legend class="nhsuk-fieldset__legend nhsuk-label">
@@ -54,12 +54,12 @@
5454
id="@Model.DayId"
5555
name="@Model.DayId"
5656
value="@Model.DayValue"
57-
type="number"
58-
pattern="[0-9]*"
57+
type="text"
5958
min="1"
6059
max="31"
6160
step="1"
62-
inputmode="numeric" />
61+
inputmode="numeric"
62+
aria-describedby="date-error" aria-invalid="false" />
6363
</div>
6464
</div>
6565
<div class="nhsuk-date-input__item">
@@ -69,12 +69,12 @@
6969
id="@Model.MonthId"
7070
name="@Model.MonthId"
7171
value="@Model.MonthValue"
72-
type="number"
73-
pattern="[0-9]*"
72+
type="text"
7473
min="1"
7574
max="12"
7675
step="1"
77-
inputmode="numeric" />
76+
inputmode="numeric"
77+
aria-describedby="date-error" aria-invalid="false" />
7878
</div>
7979
</div>
8080
<div class="nhsuk-date-input__item">
@@ -84,12 +84,12 @@
8484
id="@Model.YearId"
8585
name="@Model.YearId"
8686
value="@Model.YearValue"
87-
type="number"
88-
pattern="[0-9]*"
87+
type="text"
8988
min="1900"
9089
max="9999"
9190
step="1"
92-
inputmode="numeric" />
91+
inputmode="numeric"
92+
aria-describedby="date-error" aria-invalid="false" />
9393
</div>
9494
</div>
9595
</div>

DigitalLearningSolutions.Web/Views/Shared/Components/ErrorSummary/Default.cshtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
</ul>
2222
</div>
2323
</div>
24+
<script>
25+
const errorSummary = document.querySelector("#error-summary-title").parentElement;
26+
errorSummary.focus();
27+
</script>
2428
}
2529
else
2630
{

DigitalLearningSolutions.Web/Views/Shared/Components/RadioList/Default.cshtml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<div class="nhsuk-form-group @(Model.HasError ? "nhsuk-form-group--error" : "")">
1111

12-
<fieldset class="nhsuk-fieldset" aria-describedby="@(!string.IsNullOrEmpty(Model.HintText) ? $"{Model.Label.RemoveWhitespace()}-hint" : string.Empty)">
12+
<fieldset id="@Model.AspFor" class="nhsuk-fieldset" aria-describedby="@(!string.IsNullOrEmpty(Model.HintText) ? $"{Model.Label.RemoveWhitespace()}-hint" : string.Empty)">
1313
<legend class="nhsuk-fieldset__legend nhsuk-fieldset__legend--m">
1414
@if (Model.IsPageHeading.GetValueOrDefault() == true)
1515
{
@@ -44,15 +44,15 @@
4444

4545
@if (Model.Required && !Model.HasError)
4646
{
47-
<div data-valmsg-for="@Model.AspFor" data-valmsg-replace="true" class="error-message--margin-bottom-1 nhsuk-error-message field-validation-valid nhsuk-u-padding-top-1 nhsuk-u-padding-bottom-3">
47+
<div data-valmsg-for="@Model.AspFor" data-valmsg-replace="true" class="error-message--margin-bottom-1 nhsuk-error-message field-validation-valid nhsuk-u-padding-top-1 nhsuk-u-padding-bottom-3" aria-live="assertive" role="alert">
4848
</div>
4949
}
5050

5151
<div class="nhsuk-radios">
5252
@foreach (var (radio, index) in Model.Radios.Select((r, i) => (r, i)))
5353
{
5454
counter = index;
55-
var radioId = $"{radio.Value}-{index}";
55+
var radioId = $"{Model.AspFor}-{index}";
5656
if (!string.IsNullOrWhiteSpace(Model.Class))
5757
{
5858
<div class="@Model.Class">
@@ -65,6 +65,7 @@
6565
aria-describedby="@(!string.IsNullOrEmpty(radio.HintText) ? $"{radio.Value}-item-hint" : string.Empty)"
6666
data-val-required="@(Model.Required ? Model.RequiredClientSideErrorMessage : "")"
6767
data-val="@(Model.Required ? "true" : "false")"
68+
aria-invalid="@(Model.Required ? "true" : "false")"
6869
@(radio.Selected ? "checked" : string.Empty) />
6970
<label class="nhsuk-label nhsuk-radios__label" for="@radioId">
7071
@radio.Label
@@ -89,6 +90,7 @@
8990
aria-describedby="@(!string.IsNullOrEmpty(radio.HintText) ? $"{radio.Value}-item-hint" : string.Empty)"
9091
data-val-required="@(Model.Required ? Model.RequiredClientSideErrorMessage : "")"
9192
data-val="@(Model.Required ? "true" : "false")"
93+
aria-invalid="@(Model.Required ? "true" : "false")"
9294
@(radio.Selected ? "checked" : string.Empty) />
9395
<label class="nhsuk-label nhsuk-radios__label" for="@radioId">
9496
@radio.Label
@@ -106,7 +108,7 @@
106108
@if (Model.OptionalRadio != null)
107109
{
108110
<div class="nhsuk-radios__divider nhsuk-u-padding-left-2">or</div>
109-
var radioId = $"{Model.OptionalRadio.Value}-{++counter}";
111+
var radioId = $"{Model.AspFor}-{++counter}";
110112
<div class="nhsuk-radios__item">
111113
<input class="nhsuk-radios__input"
112114
id="@radioId"
@@ -131,5 +133,4 @@
131133

132134
</div>
133135
</fieldset>
134-
135136
</div>

0 commit comments

Comments
 (0)