mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACA-3942] Enable assignee edit button only when userTask shared among the candidates (#6113)
* [ACA-3942] Enable assignee edit button only when user task shared among the candidates * * Moved logic to service level
This commit is contained in:
@@ -139,6 +139,11 @@ describe('Task Cloud Service', () => {
|
||||
expect(isTaskEditable).toEqual(true);
|
||||
});
|
||||
|
||||
it('should verify if the task assignee property is clickable', () => {
|
||||
const isAssigneePropertyClickable = service.isAssigneePropertyClickable(assignedTaskDetailsCloudMock, [ { icon: '', value: 'user' } ], [ { icon: '', value: 'group' } ]);
|
||||
expect(isAssigneePropertyClickable).toEqual(true);
|
||||
});
|
||||
|
||||
it('should complete task with owner as null', async(() => {
|
||||
const appName = 'simple-app';
|
||||
const taskId = '68d54a8f';
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AlfrescoApiService, LogService, AppConfigService, IdentityUserService } from '@alfresco/adf-core';
|
||||
import { AlfrescoApiService, LogService, AppConfigService, IdentityUserService, CardViewArrayItem } from '@alfresco/adf-core';
|
||||
import { throwError, Observable, of, Subject } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { TaskDetailsCloudModel, StartTaskCloudResponseModel } from '../start-task/models/task-details-cloud.model';
|
||||
@@ -28,6 +28,7 @@ import { StartTaskCloudRequestModel } from '../start-task/models/start-task-clou
|
||||
})
|
||||
export class TaskCloudService extends BaseCloudService {
|
||||
|
||||
static TASK_ASSIGNED_STATE = 'ASSIGNED';
|
||||
dataChangesDetected$ = new Subject();
|
||||
|
||||
constructor(
|
||||
@@ -63,7 +64,7 @@ export class TaskCloudService extends BaseCloudService {
|
||||
* @returns Boolean value if the task can be completed
|
||||
*/
|
||||
canCompleteTask(taskDetails: TaskDetailsCloudModel): boolean {
|
||||
return taskDetails && taskDetails.status === 'ASSIGNED' && this.isAssignedToMe(taskDetails.assignee);
|
||||
return taskDetails && taskDetails.status === TaskCloudService.TASK_ASSIGNED_STATE && this.isAssignedToMe(taskDetails.assignee);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +73,16 @@ export class TaskCloudService extends BaseCloudService {
|
||||
* @returns Boolean value if the task is editable
|
||||
*/
|
||||
isTaskEditable(taskDetails: TaskDetailsCloudModel): boolean {
|
||||
return taskDetails && taskDetails.status === 'ASSIGNED' && this.isAssignedToMe(taskDetails.assignee);
|
||||
return taskDetails && taskDetails.status === TaskCloudService.TASK_ASSIGNED_STATE && this.isAssignedToMe(taskDetails.assignee);
|
||||
}
|
||||
|
||||
isAssigneePropertyClickable(taskDetails: TaskDetailsCloudModel, candidateUsers: CardViewArrayItem[], candidateGroups: CardViewArrayItem[]): boolean {
|
||||
let isClickable = false;
|
||||
const states = [TaskCloudService.TASK_ASSIGNED_STATE];
|
||||
if (candidateUsers?.length || candidateGroups?.length) {
|
||||
isClickable = states.includes(taskDetails.status);
|
||||
}
|
||||
return isClickable;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +101,7 @@ export class TaskCloudService extends BaseCloudService {
|
||||
*/
|
||||
canUnclaimTask(taskDetails: TaskDetailsCloudModel): boolean {
|
||||
const currentUser = this.identityUserService.getCurrentUserInfo().username;
|
||||
return taskDetails && taskDetails.status === 'ASSIGNED' && taskDetails.assignee === currentUser;
|
||||
return taskDetails && taskDetails.status === TaskCloudService.TASK_ASSIGNED_STATE && taskDetails.assignee === currentUser;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -28,7 +28,8 @@ import {
|
||||
completedTaskDetailsCloudMock,
|
||||
createdStateTaskDetailsCloudMock,
|
||||
suspendedTaskDetailsCloudMock,
|
||||
taskDetailsWithParentTaskIdMock
|
||||
taskDetailsWithParentTaskIdMock,
|
||||
createdTaskDetailsCloudMock
|
||||
} from '../mocks/task-details-cloud.mock';
|
||||
import moment from 'moment-es6';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
@@ -263,7 +264,7 @@ describe('TaskHeaderCloudComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should render defined edit icon for assignee property if the task in assigned state and assingee should be current user', () => {
|
||||
it('should render defined edit icon for assignee property if the task in assigned state and shared among candidates', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
const value = fixture.debugElement.query(By.css(`[data-automation-id="header-assignee"] [data-automation-id="card-textitem-clickable-icon-assignee"]`));
|
||||
@@ -271,6 +272,17 @@ describe('TaskHeaderCloudComponent', () => {
|
||||
expect(value.nativeElement.innerText).toBe('create');
|
||||
});
|
||||
|
||||
it('should not render defined edit icon for assignee property if the task in created state and shared among condidates', async () => {
|
||||
getTaskByIdSpy.and.returnValue(of(createdTaskDetailsCloudMock));
|
||||
|
||||
component.ngOnChanges();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const editIcon = fixture.debugElement.query(By.css(`[data-automation-id="header-assignee"] [data-automation-id="card-textitem-clickable-icon-assignee"]`));
|
||||
expect(editIcon).toBeNull();
|
||||
});
|
||||
|
||||
it('should render edit icon if the task in assigned state and assingee should be current user', () => {
|
||||
fixture.detectChanges();
|
||||
const priorityEditIcon = fixture.debugElement.query(By.css(`[data-automation-id="header-priority"] [class*="adf-textitem-edit-icon"]`));
|
||||
|
@@ -31,7 +31,7 @@ import {
|
||||
CardViewDatetimeItemModel,
|
||||
CardViewArrayItem
|
||||
} from '@alfresco/adf-core';
|
||||
import { TaskDetailsCloudModel, TaskStatus } from '../../start-task/models/task-details-cloud.model';
|
||||
import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model';
|
||||
import { TaskCloudService } from '../../services/task-cloud.service';
|
||||
import { NumericFieldValidator } from '../../../validators/numeric-field.validator';
|
||||
|
||||
@@ -141,7 +141,7 @@ export class TaskHeaderCloudComponent implements OnInit, OnDestroy, OnChanges {
|
||||
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.ASSIGNEE',
|
||||
value: this.taskDetails.assignee,
|
||||
key: 'assignee',
|
||||
clickable: this.isClickable(),
|
||||
clickable: this.isAssigneePropertyClickable(),
|
||||
default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.ASSIGNEE_DEFAULT'),
|
||||
icon: 'create'
|
||||
}
|
||||
@@ -318,9 +318,8 @@ export class TaskHeaderCloudComponent implements OnInit, OnDestroy, OnChanges {
|
||||
return this.taskCloudService.isTaskEditable(this.taskDetails);
|
||||
}
|
||||
|
||||
isClickable(): boolean {
|
||||
const states: TaskStatus[] = ['ASSIGNED', 'CREATED'];
|
||||
return states.includes(this.taskDetails.status);
|
||||
isAssigneePropertyClickable(): boolean {
|
||||
return this.taskCloudService.isAssigneePropertyClickable(this.taskDetails, this.candidateUsers, this.candidateGroups);
|
||||
}
|
||||
|
||||
private isValidSelection(filteredProperties: string[], cardItem: CardViewBaseItemModel): boolean {
|
||||
|
Reference in New Issue
Block a user