Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SF-3149 Only update resource permissions when necessary #2938

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/SIL.XForge.Scripture/Services/ParatextSyncRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ IGuidService guidService
_guidService = guidService;
}

private bool TranslationSuggestionsEnabled => _projectDoc.Data.TranslateConfig.TranslationSuggestionsEnabled;
private bool CheckingEnabled => _projectDoc.Data.CheckingConfig.CheckingEnabled;

/// <summary>
Expand Down Expand Up @@ -327,8 +326,7 @@ await GetAndUpdateParatextBooksAndNotes(
// Update user resource access, if this project has a source resource
// The updating of a source project's permissions is done when that project is synced.
if (
TranslationSuggestionsEnabled
&& !string.IsNullOrWhiteSpace(sourceParatextId)
!string.IsNullOrWhiteSpace(sourceParatextId)
&& !string.IsNullOrWhiteSpace(sourceProjectRef)
&& _paratextService.IsResource(sourceParatextId)
)
Expand Down Expand Up @@ -440,9 +438,14 @@ await UpdateBiblicalTermsAsync(
await UpdateResourceConfig(paratextProject);
}

// We will always update permissions, even if this is a resource project
LogMetric("Updating permissions");
await _projectService.UpdatePermissionsAsync(userId, _projectDoc, _paratextUsers, token);
// Update permissions if not a resource, or if it is a resource and needs updating.
// A resource will need updating if its text or permissions have changed on the DBL.
// Source resources have their permissions updated above in the section "Updating user resource access".
if (!_paratextService.IsResource(targetParatextId) || resourceNeedsUpdating)
{
LogMetric("Updating permissions");
await _projectService.UpdatePermissionsAsync(userId, _projectDoc, _paratextUsers, token);
}

await NotifySyncProgress(SyncPhase.Phase9, 40.0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ public async Task SyncAsync_UserRoleChangedAndUserRemoved()
}

[Test]
public async Task SyncAsync_SetsUserPermissions()
public async Task SyncAsync_UpdatesPermissionsForProjects()
{
var env = new TestEnvironment();
Book[] books = [new Book("MAT", 2), new Book("MRK", 2)];
Expand All @@ -650,6 +650,7 @@ public async Task SyncAsync_SetsUserPermissions()
Arg.Any<CancellationToken>()
)
.Returns([TestEnvironment.ParatextProjectUser01 with { Role = SFProjectRole.Translator }]);
env.ParatextService.IsResource(Arg.Any<string>()).Returns(false);

// SUT
await env.Runner.RunAsync("project01", "user01", "project01", false, CancellationToken.None);
Expand All @@ -658,9 +659,8 @@ await env
.SFProjectService.Received()
.UpdatePermissionsAsync(
"user01",
Arg.Is<IDocument<SFProject>>(
(IDocument<SFProject> sfProjDoc) =>
sfProjDoc.Data.Id == "project01" && sfProjDoc.Data.ParatextId == "target"
Arg.Is<IDocument<SFProject>>(sfProjDoc =>
sfProjDoc.Data.Id == "project01" && sfProjDoc.Data.ParatextId == "target"
),
Arg.Any<IReadOnlyList<ParatextProjectUser>>(),
Arg.Any<CancellationToken>()
Expand Down Expand Up @@ -2382,6 +2382,18 @@ public async Task SyncAsync_ResourceChanged()
// Check that the resource users metrics have been updated
SyncMetrics syncMetrics = env.GetSyncMetrics("project01");
Assert.That(syncMetrics.ResourceUsers, Is.EqualTo(new SyncMetricInfo(2, 0, 0)));

// Check that the permissions were updated
await env
.SFProjectService.Received()
.UpdatePermissionsAsync(
"user01",
Arg.Is<IDocument<SFProject>>(sfProjDoc =>
sfProjDoc.Data.Id == "project01" && sfProjDoc.Data.ParatextId == "target"
),
Arg.Any<IReadOnlyList<ParatextProjectUser>>(),
Arg.Any<CancellationToken>()
);
}

[Test]
Expand Down Expand Up @@ -2419,6 +2431,18 @@ public async Task SyncAsync_ResourceNotChanged()
Assert.IsNull(env.GetProject().ResourceConfig);
Assert.That(env.ContainsText("project01", "MAT", 2), Is.True);
Assert.That(env.ContainsText("project01", "MRK", 2), Is.True);

// Ensure that the permissions were not updated
await env
.SFProjectService.DidNotReceive()
.UpdatePermissionsAsync(
"user01",
Arg.Is<IDocument<SFProject>>(sfProjDoc =>
sfProjDoc.Data.Id == "project01" && sfProjDoc.Data.ParatextId == "target"
),
Arg.Any<IReadOnlyList<ParatextProjectUser>>(),
Arg.Any<CancellationToken>()
);
}

[Test]
Expand Down
Loading