Skip to content

Commit cb5bf2d

Browse files
committed
Fixes for issues raised by devin
1 parent 66dc74a commit cb5bf2d

8 files changed

Lines changed: 94 additions & 8 deletions

File tree

src/RealtimeServer/scriptureforge/models/translate-config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export interface DraftUsfmConfig {
5858
quoteFormat: QuoteFormat;
5959
}
6060

61+
/**
62+
* The configuration used for Quality Estimation.
63+
*/
6164
export interface QualityEstimationConfig {
6265
version: string;
6366
slope: number;

src/SIL.XForge.Scripture/ClientApp/src/app/serval-administration/serval-project.component.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,23 @@ describe('ServalProjectComponent', () => {
357357
}));
358358

359359
it('should not update an unchanged quality estimation config value', fakeAsync(() => {
360+
const env = new TestEnvironment({
361+
preTranslate: true,
362+
draftConfig: { qualityEstimationConfig: { version: '0.1', slope: 109.6145, intercept: -14.0633 } }
363+
});
364+
expect(env.qualityEstimationConfigTextArea.value).toBe(
365+
'{"version":"0.1","slope":109.6145,"intercept":-14.0633}'
366+
);
367+
expect(env.statusDone(env.qualityEstimationConfigStatus)).toBeNull();
368+
369+
env.setQualityEstimationConfigValue('{ "version": "0.1", "slope": 109.6145, "intercept": -14.0633 }');
370+
env.clickElement(env.saveQualityEstimationConfigButton);
371+
372+
verify(mockSFProjectService.onlineSetQualityEstimationConfig(env.mockProjectId, anything())).never();
373+
expect(env.statusDone(env.qualityEstimationConfigStatus)).toBeNull();
374+
}));
375+
376+
it('should not update an unchanged empty quality estimation config value', fakeAsync(() => {
360377
const env = new TestEnvironment();
361378
expect(env.qualityEstimationConfigTextArea.value).toBe('');
362379
expect(env.statusDone(env.qualityEstimationConfigStatus)).toBeNull();

src/SIL.XForge.Scripture/ClientApp/src/app/serval-administration/serval-project.component.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,15 @@ export class ServalProjectComponent extends DataLoadingComponent implements OnIn
367367
}
368368

369369
updateQualityEstimationConfig(): void {
370+
// Do not save if we do not have the project doc or if the configuration was and is empty
371+
const projectId: string | undefined = this.activatedProjectService.projectId;
372+
const project: SFProjectProfile | undefined = this.activatedProjectService.projectDoc?.data;
370373
if (
371-
this.activatedProjectService.projectDoc?.data == null ||
374+
project == null ||
375+
projectId == null ||
372376
(this.form.value.qualityEstimationConfig ?? '') ===
373-
(this.activatedProjectService.projectDoc.data.translateConfig.draftConfig.qualityEstimationConfig ?? '')
377+
(project.translateConfig.draftConfig.qualityEstimationConfig ?? '')
374378
) {
375-
// Do not save if we do not have the project doc or if the configuration has not changed
376379
return;
377380
}
378381

@@ -391,19 +394,30 @@ export class ServalProjectComponent extends DataLoadingComponent implements OnIn
391394
// Ensure the JSON is valid
392395
if (
393396
qualityEstimationConfig != null &&
394-
typeof qualityEstimationConfig.version !== 'string' &&
395-
typeof qualityEstimationConfig.slope !== 'number' &&
396-
typeof qualityEstimationConfig.intercept !== 'number' &&
397-
qualityEstimationConfig.version !== '0.1'
397+
(typeof qualityEstimationConfig.version !== 'string' ||
398+
typeof qualityEstimationConfig.slope !== 'number' ||
399+
typeof qualityEstimationConfig.intercept !== 'number' ||
400+
qualityEstimationConfig.version !== '0.1')
398401
) {
399402
this.qualityEstimationConfigUpdateState = ElementState.Error;
400403
return;
401404
}
402405

406+
// Do not update if the values did not change
407+
const existingQualityEstimationConfig: QualityEstimationConfig | undefined =
408+
project.translateConfig.draftConfig.qualityEstimationConfig;
409+
if (
410+
qualityEstimationConfig?.version === existingQualityEstimationConfig?.version &&
411+
qualityEstimationConfig?.slope === existingQualityEstimationConfig?.slope &&
412+
qualityEstimationConfig?.intercept === existingQualityEstimationConfig?.intercept
413+
) {
414+
return;
415+
}
416+
403417
// Update the Quality Estimation Configuration
404418
this.qualityEstimationConfigUpdateState = ElementState.Submitting;
405419
void this.projectService
406-
.onlineSetQualityEstimationConfig(this.activatedProjectService.projectDoc.id, qualityEstimationConfig)
420+
.onlineSetQualityEstimationConfig(projectId, qualityEstimationConfig)
407421
.then(() => (this.qualityEstimationConfigUpdateState = ElementState.Submitted))
408422
.catch(() => (this.qualityEstimationConfigUpdateState = ElementState.Error));
409423
}

src/SIL.XForge.Scripture/Controllers/SFProjectsRpcController.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,10 @@ await projectService.SetQualityEstimationConfigAsync(
965965
{
966966
return ForbiddenError();
967967
}
968+
catch (InvalidOperationException e)
969+
{
970+
return InvalidParamsError(e.Message);
971+
}
968972
catch (DataNotFoundException dnfe)
969973
{
970974
return NotFoundError(dnfe.Message);

src/SIL.XForge.Scripture/Models/QualityEstimationConfig.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
namespace SIL.XForge.Scripture.Models;
22

3+
/// <summary>
4+
/// The configuration used for Quality Estimation.
5+
/// </summary>
36
public class QualityEstimationConfig
47
{
58
public required string Version { get; set; }

src/SIL.XForge.Scripture/Services/SFProjectService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,9 @@ public async Task SetQualityEstimationConfigAsync(
12431243
if (!systemRoles.Contains(SystemRole.ServalAdmin))
12441244
throw new ForbiddenException();
12451245

1246+
if ((qualityEstimationConfig?.Version ?? "0.1") != "0.1")
1247+
throw new InvalidOperationException("Unsupported version number");
1248+
12461249
await using IConnection conn = await RealtimeService.ConnectAsync(curUserId);
12471250
IDocument<SFProject> projectDoc = await GetProjectDocAsync(projectId, conn);
12481251
if (qualityEstimationConfig is null)

test/SIL.XForge.Scripture.Tests/Controllers/SFProjectsRpcControllerTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,26 @@ await env
10531053
.SetQualityEstimationConfigAsync(User01, Roles, Project01, qualityEstimationConfig);
10541054
}
10551055

1056+
[Test]
1057+
public async Task SetQualityEstimationConfig_InvalidParams()
1058+
{
1059+
var env = new TestEnvironment();
1060+
var qualityEstimationConfig = new QualityEstimationConfig
1061+
{
1062+
Version = "11.0",
1063+
Slope = 109.6145,
1064+
Intercept = -14.0633,
1065+
};
1066+
const string errorMessage = "Unsupported version number";
1067+
env.SFProjectService.SetQualityEstimationConfigAsync(User01, Roles, Project01, qualityEstimationConfig)
1068+
.Throws(new InvalidOperationException(errorMessage));
1069+
1070+
// SUT
1071+
var result = await env.Controller.SetQualityEstimationConfig(Project01, qualityEstimationConfig);
1072+
Assert.IsInstanceOf<RpcMethodErrorResult>(result);
1073+
Assert.AreEqual(errorMessage, (result as RpcMethodErrorResult)!.Message);
1074+
}
1075+
10561076
[Test]
10571077
public async Task SetQualityEstimationConfig_NotFound()
10581078
{

test/SIL.XForge.Scripture.Tests/Services/SFProjectServiceTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3971,6 +3971,28 @@ await env.Service.SetQualityEstimationConfigAsync(
39713971
);
39723972
}
39733973

3974+
[Test]
3975+
public void SetQualityEstimationConfigAsync_UnsupportedVersion()
3976+
{
3977+
var env = new TestEnvironment();
3978+
var qualityEstimationConfig = new QualityEstimationConfig
3979+
{
3980+
Version = "11.0",
3981+
Slope = 109.6145,
3982+
Intercept = -14.0633,
3983+
};
3984+
3985+
// SUT
3986+
Assert.ThrowsAsync<InvalidOperationException>(() =>
3987+
env.Service.SetQualityEstimationConfigAsync(
3988+
User01,
3989+
[SystemRole.ServalAdmin],
3990+
Project01,
3991+
qualityEstimationConfig
3992+
)
3993+
);
3994+
}
3995+
39743996
[Test]
39753997
public void SetQualityEstimationConfigAsync_UserMustBeServalAdmin()
39763998
{

0 commit comments

Comments
 (0)