diff --git a/lib/core/models/user-process.model.ts b/lib/core/models/user-process.model.ts index e2c7fdb817..bd395519f1 100644 --- a/lib/core/models/user-process.model.ts +++ b/lib/core/models/user-process.model.ts @@ -27,6 +27,7 @@ export class UserProcessModel implements LightUserRepresentation { firstName?: string; lastName?: string; pictureId?: number = null; + externalId?: string; constructor(obj?: any) { if (obj) { @@ -35,6 +36,7 @@ export class UserProcessModel implements LightUserRepresentation { this.firstName = obj.firstName || null; this.lastName = obj.lastName || null; this.pictureId = obj.pictureId || null; + this.externalId = obj.externalId || null; } } diff --git a/lib/core/services/authentication.service.spec.ts b/lib/core/services/authentication.service.spec.ts index 072bb9934b..a598328dc0 100644 --- a/lib/core/services/authentication.service.spec.ts +++ b/lib/core/services/authentication.service.spec.ts @@ -22,6 +22,7 @@ import { CookieService } from './cookie.service'; import { AppConfigService } from '../app-config/app-config.service'; import { setupTestBed } from '../testing/setupTestBed'; import { CoreTestingModule } from '../testing/core.testing.module'; +import { UserRepresentation } from 'alfresco-js-api'; declare let jasmine: any; @@ -349,6 +350,18 @@ describe('AuthenticationService', () => { it('[BPM] should return isALLProvider false', () => { expect(authService.isALLProvider()).toBe(false); }); + + it('[BPM] should be able to retrieve current logged in user', (done) => { + spyOn(apiService.getInstance().activiti.profileApi, 'getProfile').and.returnValue( + Promise.resolve(( { + email: 'fake-email' + }))); + + authService.getBpmLoggedUser().subscribe((fakeUser) => { + expect(fakeUser.email).toBe('fake-email'); + done(); + }); + }); }); describe('when the setting is both ECM and BPM ', () => { diff --git a/lib/core/services/authentication.service.ts b/lib/core/services/authentication.service.ts index b7a8521a06..34cfdfe881 100644 --- a/lib/core/services/authentication.service.ts +++ b/lib/core/services/authentication.service.ts @@ -26,6 +26,7 @@ import { AppConfigService, AppConfigValues } from '../app-config/app-config.serv import 'rxjs/add/observable/fromPromise'; import 'rxjs/add/operator/catch'; import 'rxjs/add/observable/throw'; +import { UserRepresentation } from 'alfresco-js-api'; const REMEMBER_ME_COOKIE_KEY = 'ALFRESCO_REMEMBER_ME'; const REMEMBER_ME_UNTIL = 1000 * 60 * 60 * 24 * 30 ; @@ -228,6 +229,10 @@ export class AuthenticationService { return this.hasValidRedirection(provider) ? this.redirectUrl.url : null; } + getBpmLoggedUser(): Observable { + return Observable.fromPromise(this.alfrescoApi.getInstance().activiti.profileApi.getProfile()); + } + private hasValidRedirection(provider: string): boolean { return this.redirectUrl && (this.redirectUrl.provider === provider || this.hasSelectedProviderAll(provider)); } diff --git a/lib/process-services/task-list/components/task-details.component.spec.ts b/lib/process-services/task-list/components/task-details.component.spec.ts index 8379f3d12c..f11f2bc4e0 100644 --- a/lib/process-services/task-list/components/task-details.component.spec.ts +++ b/lib/process-services/task-list/components/task-details.component.spec.ts @@ -21,7 +21,7 @@ import { By } from '@angular/platform-browser'; import { Observable } from 'rxjs/Observable'; import { FormModel, FormOutcomeEvent, FormOutcomeModel, FormService, setupTestBed, BpmUserService } from '@alfresco/adf-core'; -import { CommentProcessService, LogService } from '@alfresco/adf-core'; +import { CommentProcessService, LogService, AuthenticationService } from '@alfresco/adf-core'; import { UserProcessModel } from '@alfresco/adf-core'; import { TaskDetailsModel } from '../models/task-details.model'; @@ -51,6 +51,7 @@ describe('TaskDetailsComponent', () => { let logService: LogService; let commentProcessService: CommentProcessService; let peopleProcessService: PeopleProcessService; + let authService: AuthenticationService; setupTestBed({ imports: [ @@ -80,6 +81,9 @@ describe('TaskDetailsComponent', () => { completeTaskSpy = spyOn(service, 'completeTask').and.returnValue(Observable.of({})); commentProcessService = TestBed.get(CommentProcessService); + authService = TestBed.get(AuthenticationService); + spyOn(authService, 'getBpmLoggedUser').and.returnValue(Observable.of({ email: 'fake-email'})); + spyOn(commentProcessService, 'getTaskComments').and.returnValue(Observable.of([ {message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}, {message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}, diff --git a/lib/process-services/task-list/components/task-details.component.ts b/lib/process-services/task-list/components/task-details.component.ts index db3f8d9f96..856718f5b7 100644 --- a/lib/process-services/task-list/components/task-details.component.ts +++ b/lib/process-services/task-list/components/task-details.component.ts @@ -44,6 +44,7 @@ import { TaskQueryRequestRepresentationModel } from '../models/filter.model'; import { TaskDetailsModel } from '../models/task-details.model'; import { TaskListService } from './../services/tasklist.service'; import { AttachFileWidgetComponent, AttachFolderWidgetComponent } from '../../content-widget'; +import { UserRepresentation } from 'alfresco-js-api'; @Component({ selector: 'adf-task-details', @@ -179,6 +180,8 @@ export class TaskDetailsComponent implements OnInit, OnChanges { peopleSearch: Observable; + currentLoggedUser: UserRepresentation; + constructor(private taskListService: TaskListService, private authService: AuthenticationService, private peopleProcessService: PeopleProcessService, @@ -199,6 +202,10 @@ export class TaskDetailsComponent implements OnInit, OnChanges { this.cardViewUpdateService.itemUpdated$.subscribe(this.updateTaskDetails.bind(this)); this.cardViewUpdateService.itemClicked$.subscribe(this.clickTaskDetails.bind(this)); + + this.authService.getBpmLoggedUser().subscribe((user: UserRepresentation) => { + this.currentLoggedUser = user; + }); } ngOnChanges(changes: SimpleChanges): void { @@ -285,8 +292,22 @@ export class TaskDetailsComponent implements OnInit, OnChanges { return this.taskDetails.assignee ? true : false; } + private hasEmailAddress(): boolean { + return this.taskDetails.assignee.email ? true : false; + } + isAssignedToMe(): boolean { - return this.isAssigned() ? this.taskDetails.assignee.email === this.authService.getBpmUsername() : false; + return this.isAssigned() && this.hasEmailAddress() ? + this.isEmailEqual(this.taskDetails.assignee.email, this.currentLoggedUser.email) : + this.isExternalIdEqual(this.taskDetails.assignee.externalId, this.currentLoggedUser.externalId); + } + + private isEmailEqual(assigneeMail, currentLoggedEmail): boolean { + return assigneeMail.toLocaleLowerCase() === currentLoggedEmail.toLocaleLowerCase(); + } + + private isExternalIdEqual(assigneeExternalId, currentUserExternalId): boolean { + return assigneeExternalId.toLocaleLowerCase() === currentUserExternalId.toLocaleLowerCase(); } isCompleteButtonEnabled(): boolean {