Skip to content

Commit 09d1269

Browse files
committed
Code review updates
1 parent 4c89639 commit 09d1269

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

src/SIL.XForge.Scripture/ClientApp/src/app/core/permissions.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ export class PermissionsService {
6565
* @param project The project.
6666
* @returns A boolean value.
6767
*/
68-
canAccessText(textDocId?: TextDocId, project?: SFProjectProfile): boolean {
68+
canAccessText(textDocId: TextDocId, project?: SFProjectProfile): boolean {
6969
// Ensure the user has project level permission to view the text
7070
if (
71-
textDocId != null &&
7271
project != null &&
7372
SF_PROJECT_RIGHTS.hasRight(project, this.userService.currentUserId, SFProjectDomain.Texts, Operation.View)
7473
) {

src/SIL.XForge.Scripture/ClientApp/src/app/core/text-doc.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,13 @@ describe('TextDocService', () => {
410410
expect(actual).toBeUndefined();
411411
});
412412

413-
it('should return undefined if the user does not have the permission', () => {
413+
it('should return false if the user does not have the permission', () => {
414414
const env = new TestEnvironment();
415415
const text: Partial<TextInfo> = { chapters: [{ number: 1 } as Chapter] };
416416

417417
// SUT
418418
const actual: boolean | undefined = env.textDocService.hasChapterEditPermissionForText(text as TextInfo, 1);
419-
expect(actual).toBeUndefined();
419+
expect(actual).toBe(false);
420420
});
421421

422422
it('should return false if the user does not have the write permission for the chapter', () => {

src/SIL.XForge.Scripture/ClientApp/src/app/core/text-doc.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,12 @@ export class TextDocService {
187187
*/
188188
hasChapterEditPermissionForText(text: TextInfo | undefined, chapterNum: number | undefined): boolean | undefined {
189189
const chapter: Chapter | undefined = text?.chapters.find(c => c.number === chapterNum);
190+
if (chapter == null) return undefined;
190191
// Even though permissions is guaranteed to be there in the model, its not in IndexedDB the first time the project
191192
// is accessed after migration
192193
const permission: string | undefined =
193194
chapter?.permissions?.[this.userService.currentUserId] ?? text?.permissions?.[this.userService.currentUserId];
194-
return permission == null ? undefined : permission === TextInfoPermission.Write;
195+
return permission === TextInfoPermission.Write;
195196
}
196197

197198
/**

src/SIL.XForge.Scripture/ClientApp/src/app/translate/editor/editor.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,12 @@ export class EditorComponent extends DataLoadingComponent implements OnDestroy,
528528

529529
get hasSourceViewRight(): boolean {
530530
const sourceProject = this.sourceProjectDoc?.data;
531-
if (sourceProject == null) {
531+
const sourceId = this.source?.id;
532+
if (sourceProject == null || sourceId == null) {
532533
return this.isParatextUserRole;
533534
}
534535

535-
return this.isParatextUserRole && this.permissionsService.canAccessText(this.source?.id, sourceProject);
536+
return this.isParatextUserRole && this.permissionsService.canAccessText(sourceId, sourceProject);
536537
}
537538

538539
get canInsertNote(): boolean {

0 commit comments

Comments
 (0)