From 71e40fdb6ef3d6e63b6232eee5dc333af2aaff3c Mon Sep 17 00:00:00 2001 From: lotte Date: Wed, 15 Dec 2021 14:04:38 +0100 Subject: [PATCH 1/6] 85979: only show security tab on profile page when canChangePassword FeatureID is true --- src/app/core/data/feature-authorization/feature-id.ts | 1 + src/app/profile-page/profile-page.component.html | 2 +- src/app/profile-page/profile-page.component.ts | 7 ++++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/app/core/data/feature-authorization/feature-id.ts b/src/app/core/data/feature-authorization/feature-id.ts index 15eba0e5db..b64de5100b 100644 --- a/src/app/core/data/feature-authorization/feature-id.ts +++ b/src/app/core/data/feature-authorization/feature-id.ts @@ -13,6 +13,7 @@ export enum FeatureID { CanManageGroup = 'canManageGroup', IsCollectionAdmin = 'isCollectionAdmin', IsCommunityAdmin = 'isCommunityAdmin', + CanChangePassword = 'canChangePassword', CanDownload = 'canDownload', CanRequestACopy = 'canRequestACopy', CanManageVersions = 'canManageVersions', diff --git a/src/app/profile-page/profile-page.component.html b/src/app/profile-page/profile-page.component.html index 619e4a2411..95d2be1274 100644 --- a/src/app/profile-page/profile-page.component.html +++ b/src/app/profile-page/profile-page.component.html @@ -7,7 +7,7 @@ -
+
{{'profile.card.security' | translate}}
; constructor(private authService: AuthService, private notificationsService: NotificationsService, private translate: TranslateService, - private epersonService: EPersonDataService) { + private epersonService: EPersonDataService, + private authorizationService: AuthorizationDataService) { } ngOnInit(): void { @@ -83,6 +87,7 @@ export class ProfilePageComponent implements OnInit { tap((user: EPerson) => this.currentUser = user) ); this.groupsRD$ = this.user$.pipe(switchMap((user: EPerson) => user.groups)); + this.canChangePassword$ = this.user$.pipe(switchMap((user:EPerson) => this.authorizationService.isAuthorized(FeatureID.CanChangePassword, user._links.self.href))); } /** From 2f022f505dd8c1543e77ab5b57287eebd5cf41c2 Mon Sep 17 00:00:00 2001 From: lotte Date: Wed, 15 Dec 2021 14:41:10 +0100 Subject: [PATCH 2/6] 85979: tests for canChangePassword UI changes --- .../profile-page/profile-page.component.html | 2 +- .../profile-page.component.spec.ts | 46 +++++++++++++++++-- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/app/profile-page/profile-page.component.html b/src/app/profile-page/profile-page.component.html index 95d2be1274..ccfae0bba1 100644 --- a/src/app/profile-page/profile-page.component.html +++ b/src/app/profile-page/profile-page.component.html @@ -7,7 +7,7 @@
-
+
{{'profile.card.security' | translate}}
{ let component: ProfilePageComponent; @@ -28,10 +31,13 @@ describe('ProfilePageComponent', () => { let epersonService; let notificationsService; + let canChangePassword = new BehaviorSubject(true); + function init() { user = Object.assign(new EPerson(), { id: 'userId', - groups: createSuccessfulRemoteDataObject$(createPaginatedList([])) + groups: createSuccessfulRemoteDataObject$(createPaginatedList([])), + _links: {self: {href: 'test.com/uuid/1234567654321'}} }); initialState = { core: { @@ -74,6 +80,7 @@ describe('ProfilePageComponent', () => { { provide: EPersonDataService, useValue: epersonService }, { provide: NotificationsService, useValue: notificationsService }, { provide: AuthService, useValue: authService }, + { provide: AuthorizationDataService, useValue: jasmine.createSpyObj('authorizationService', { isAuthorized: canChangePassword }) }, provideMockStore({ initialState }), ], schemas: [NO_ERRORS_SCHEMA] @@ -183,7 +190,7 @@ describe('ProfilePageComponent', () => { component.setPasswordValue('testest'); component.setInvalid(false); - operations = [{op: 'add', path: '/password', value: 'testest'}]; + operations = [{ op: 'add', path: '/password', value: 'testest' }]; result = component.updateSecurity(); }); @@ -196,4 +203,35 @@ describe('ProfilePageComponent', () => { }); }); }); + + describe('canChangePassword$', () => { + describe('when the user is allowed to change their password', () => { + beforeEach(() => { + canChangePassword.next(true); + }); + + it('should contain true', () => { + getTestScheduler().expectObservable(component.canChangePassword$).toBe('(a)', { a: true }); + }); + + it('should show the security section on the page', () => { + fixture.detectChanges(); + expect(fixture.debugElement.query(By.css('.security-section'))).not.toBeNull(); + }); + }); + + describe('when the user is not allowed to change their password', () => { + beforeEach(() => { + canChangePassword.next(false); + }); + + it('should contain false', () => { + getTestScheduler().expectObservable(component.canChangePassword$).toBe('(a)', { a: false }); + }); + + it('should not show the security section on the page', fakeAsync(() => { + expect(fixture.debugElement.query(By.css('.security-section'))).toBeNull(); + })); + }); + }); }); From 6594a3877fc1c3dfe258d048449eae87abcde34f Mon Sep 17 00:00:00 2001 From: lotte Date: Wed, 15 Dec 2021 15:13:27 +0100 Subject: [PATCH 3/6] fixed lint/lgtm issues --- src/app/profile-page/profile-page.component.spec.ts | 4 ++-- src/app/profile-page/profile-page.component.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/profile-page/profile-page.component.spec.ts b/src/app/profile-page/profile-page.component.spec.ts index adffe527d1..c7b644375c 100644 --- a/src/app/profile-page/profile-page.component.spec.ts +++ b/src/app/profile-page/profile-page.component.spec.ts @@ -1,5 +1,5 @@ import { ProfilePageComponent } from './profile-page.component'; -import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, TestBed, waitForAsync } from '@angular/core/testing'; import { VarDirective } from '../shared/utils/var.directive'; import { TranslateModule } from '@ngx-translate/core'; import { RouterTestingModule } from '@angular/router/testing'; @@ -31,7 +31,7 @@ describe('ProfilePageComponent', () => { let epersonService; let notificationsService; - let canChangePassword = new BehaviorSubject(true); + const canChangePassword = new BehaviorSubject(true); function init() { user = Object.assign(new EPerson(), { diff --git a/src/app/profile-page/profile-page.component.ts b/src/app/profile-page/profile-page.component.ts index 271b0277da..fece166a59 100644 --- a/src/app/profile-page/profile-page.component.ts +++ b/src/app/profile-page/profile-page.component.ts @@ -87,7 +87,7 @@ export class ProfilePageComponent implements OnInit { tap((user: EPerson) => this.currentUser = user) ); this.groupsRD$ = this.user$.pipe(switchMap((user: EPerson) => user.groups)); - this.canChangePassword$ = this.user$.pipe(switchMap((user:EPerson) => this.authorizationService.isAuthorized(FeatureID.CanChangePassword, user._links.self.href))); + this.canChangePassword$ = this.user$.pipe(switchMap((user: EPerson) => this.authorizationService.isAuthorized(FeatureID.CanChangePassword, user._links.self.href))); } /** From dd69bc65ab6938aaf2684c597f3a3f246ac4ea2c Mon Sep 17 00:00:00 2001 From: lotte Date: Wed, 15 Dec 2021 16:21:09 +0100 Subject: [PATCH 4/6] Fixes to tests --- src/app/profile-page/profile-page.component.spec.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app/profile-page/profile-page.component.spec.ts b/src/app/profile-page/profile-page.component.spec.ts index c7b644375c..ce7f2f1acb 100644 --- a/src/app/profile-page/profile-page.component.spec.ts +++ b/src/app/profile-page/profile-page.component.spec.ts @@ -204,7 +204,7 @@ describe('ProfilePageComponent', () => { }); }); - describe('canChangePassword$', () => { + fdescribe('canChangePassword$', () => { describe('when the user is allowed to change their password', () => { beforeEach(() => { canChangePassword.next(true); @@ -229,9 +229,10 @@ describe('ProfilePageComponent', () => { getTestScheduler().expectObservable(component.canChangePassword$).toBe('(a)', { a: false }); }); - it('should not show the security section on the page', fakeAsync(() => { + it('should not show the security section on the page', () => { + fixture.detectChanges(); expect(fixture.debugElement.query(By.css('.security-section'))).toBeNull(); - })); + }); }); }); }); From b7d01127a536b6f8650ac331477351373e5229f1 Mon Sep 17 00:00:00 2001 From: lotte Date: Wed, 15 Dec 2021 16:21:55 +0100 Subject: [PATCH 5/6] Removed unnecessary import --- src/app/profile-page/profile-page.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/profile-page/profile-page.component.spec.ts b/src/app/profile-page/profile-page.component.spec.ts index ce7f2f1acb..59e62c6a16 100644 --- a/src/app/profile-page/profile-page.component.spec.ts +++ b/src/app/profile-page/profile-page.component.spec.ts @@ -1,5 +1,5 @@ import { ProfilePageComponent } from './profile-page.component'; -import { ComponentFixture, fakeAsync, TestBed, waitForAsync } from '@angular/core/testing'; +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { VarDirective } from '../shared/utils/var.directive'; import { TranslateModule } from '@ngx-translate/core'; import { RouterTestingModule } from '@angular/router/testing'; From 7529fcde35cb5b6fe52676b47c1cafefc3429629 Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Wed, 15 Dec 2021 16:46:40 +0100 Subject: [PATCH 6/6] remove fdescribe --- src/app/profile-page/profile-page.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/profile-page/profile-page.component.spec.ts b/src/app/profile-page/profile-page.component.spec.ts index 59e62c6a16..f48b894d8d 100644 --- a/src/app/profile-page/profile-page.component.spec.ts +++ b/src/app/profile-page/profile-page.component.spec.ts @@ -204,7 +204,7 @@ describe('ProfilePageComponent', () => { }); }); - fdescribe('canChangePassword$', () => { + describe('canChangePassword$', () => { describe('when the user is allowed to change their password', () => { beforeEach(() => { canChangePassword.next(true);