Skip to content

Commit a62cd24

Browse files
committed
Set role to none if user has been removed from the project
1 parent 23be802 commit a62cd24

File tree

5 files changed

+11
-19
lines changed

5 files changed

+11
-19
lines changed

src/SIL.XForge.Scripture/ClientApp/src/app/shared/share/share-control.component.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
import {
2-
ChangeDetectorRef,
3-
Component,
4-
DestroyRef,
5-
ElementRef,
6-
EventEmitter,
7-
Input,
8-
Output,
9-
ViewChild
10-
} from '@angular/core';
1+
import { Component, DestroyRef, ElementRef, EventEmitter, Input, Output, ViewChild } from '@angular/core';
112
import { FormControl, FormGroup, FormGroupDirective, Validators } from '@angular/forms';
123
import { Operation } from 'realtime-server/lib/esm/common/models/project-rights';
134
import { SF_PROJECT_RIGHTS, SFProjectDomain } from 'realtime-server/lib/esm/scriptureforge/models/sf-project-rights';
145
import { SFProjectRole } from 'realtime-server/lib/esm/scriptureforge/models/sf-project-role';
15-
import { BehaviorSubject, combineLatest } from 'rxjs';
6+
import { BehaviorSubject, combineLatest, startWith } from 'rxjs';
167
import { CommandError } from 'xforge-common/command.service';
178
import { I18nService } from 'xforge-common/i18n.service';
189
import { NoticeService } from 'xforge-common/notice.service';
@@ -58,7 +49,6 @@ export class ShareControlComponent extends ShareBaseComponent {
5849
private readonly noticeService: NoticeService,
5950
private readonly projectService: SFProjectService,
6051
private readonly onlineStatusService: OnlineStatusService,
61-
private readonly changeDetector: ChangeDetectorRef,
6252
userService: UserService,
6353
private destroyRef: DestroyRef
6454
) {
@@ -80,7 +70,7 @@ export class ShareControlComponent extends ShareBaseComponent {
8070
.pipe(quietTakeUntilDestroyed(this.destroyRef, { logWarnings: false }))
8171
.subscribe(() => this.updateFormEnabledStateAndLinkSharingKey());
8272
});
83-
combineLatest([this.onlineStatusService.onlineStatus$, this.roleControl.valueChanges])
73+
combineLatest([this.onlineStatusService.onlineStatus$, this.roleControl.valueChanges.pipe(startWith(null))])
8474
.pipe(quietTakeUntilDestroyed(this.destroyRef))
8575
.subscribe(() => this.updateFormEnabledStateAndLinkSharingKey());
8676
}
@@ -201,8 +191,6 @@ export class ShareControlComponent extends ShareBaseComponent {
201191
this.sendInviteForm.enable({ emitEvent: false });
202192
} else {
203193
this.sendInviteForm.disable({ emitEvent: false });
204-
// Workaround for angular/angular#17793 (ExpressionChangedAfterItHasBeenCheckedError after form disabled)
205-
this.changeDetector.detectChanges();
206194
}
207195
}
208196
}

src/SIL.XForge.Scripture/ClientApp/src/app/users/collaborators/collaborators.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,8 @@ class TestEnvironment {
589589
{ username: 'User A', opaqueUserId: 'opaqueA', role: SFProjectRole.ParatextObserver },
590590
{ username: 'User B', opaqueUserId: 'opaqueB', role: SFProjectRole.ParatextTranslator },
591591
{ username: 'User C', opaqueUserId: 'opaqueC', role: SFProjectRole.ParatextAdministrator },
592-
{ username: 'User No Role', opaqueUserId: 'opaqueNoRole' }
592+
{ username: 'User No Role', opaqueUserId: 'opaqueNoRole' },
593+
{ username: 'User Not Member', opaqueUserId: 'opaqueNotMember', role: SFProjectRole.None }
593594
];
594595
paratextUsers.push(...ptMembersNotConnected);
595596
return createTestProject({

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static class SFProjectRole
99
public const string Commenter = "sf_commenter";
1010
public const string CommunityChecker = "sf_community_checker";
1111
public const string Viewer = "sf_observer";
12+
public const string None = "none";
1213

1314
public static bool IsParatextRole(string role) =>
1415
role switch

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1907,7 +1907,7 @@ await _projectDoc.SubmitJson0OpAsync(op =>
19071907
userIdsAdded.Add(updatedSFUserId);
19081908
}
19091909

1910-
string paratextRole = ptUserInRegistry?.Role;
1910+
string paratextRole = ptUserInRegistry?.Role ?? SFProjectRole.None;
19111911
if (paratextRole != existingUser.Role)
19121912
{
19131913
op.Set(pd => pd.ParatextUsers[index].Role, paratextRole);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,9 @@ public async Task SyncAsync_UpdatesExistingParatextUser()
19631963
await env.Runner.RunAsync("project01", "user01", "project01", false, CancellationToken.None);
19641964
project = env.GetProject();
19651965
Assert.That(project.ParatextUsers.Select(u => u.Username), Is.EquivalentTo(new[] { "User 1", "User 2" }));
1966-
Assert.That(project.ParatextUsers.Single(u => u.Username == "User 1").SFUserId, Is.EqualTo(null));
1966+
ParatextUserProfile ptUser1 = project.ParatextUsers.Single(u => u.Username == "User 1");
1967+
Assert.That(ptUser1.SFUserId, Is.EqualTo(null));
1968+
Assert.That(ptUser1.Role, Is.EqualTo(SFProjectRole.None));
19671969
ParatextUserProfile ptUser2 = project.ParatextUsers.Single(u => u.Username == "User 2");
19681970
Assert.That(ptUser2.SFUserId, Is.EqualTo(user2.Id));
19691971
Assert.That(ptUser2.Role, Is.EqualTo(user2.Role));
@@ -1986,7 +1988,7 @@ public async Task SyncAsync_UpdatesRoleIfUserNoLongerAMember()
19861988
Assert.That(project.ParatextUsers.Select(u => u.Username), Is.EquivalentTo(new[] { "User 1", "User 2" }));
19871989

19881990
ParatextUserProfile ptUser2 = project.ParatextUsers.Single(u => u.Username == "User 2");
1989-
Assert.That(ptUser2.Role, Is.Null);
1991+
Assert.That(ptUser2.Role, Is.EqualTo(SFProjectRole.None));
19901992
}
19911993

19921994
[Test]

0 commit comments

Comments
 (0)