mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +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);
|
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(() => {
|
it('should complete task with owner as null', async(() => {
|
||||||
const appName = 'simple-app';
|
const appName = 'simple-app';
|
||||||
const taskId = '68d54a8f';
|
const taskId = '68d54a8f';
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
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 { throwError, Observable, of, Subject } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { TaskDetailsCloudModel, StartTaskCloudResponseModel } from '../start-task/models/task-details-cloud.model';
|
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 {
|
export class TaskCloudService extends BaseCloudService {
|
||||||
|
|
||||||
|
static TASK_ASSIGNED_STATE = 'ASSIGNED';
|
||||||
dataChangesDetected$ = new Subject();
|
dataChangesDetected$ = new Subject();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -63,7 +64,7 @@ export class TaskCloudService extends BaseCloudService {
|
|||||||
* @returns Boolean value if the task can be completed
|
* @returns Boolean value if the task can be completed
|
||||||
*/
|
*/
|
||||||
canCompleteTask(taskDetails: TaskDetailsCloudModel): boolean {
|
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
|
* @returns Boolean value if the task is editable
|
||||||
*/
|
*/
|
||||||
isTaskEditable(taskDetails: TaskDetailsCloudModel): boolean {
|
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 {
|
canUnclaimTask(taskDetails: TaskDetailsCloudModel): boolean {
|
||||||
const currentUser = this.identityUserService.getCurrentUserInfo().username;
|
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,
|
completedTaskDetailsCloudMock,
|
||||||
createdStateTaskDetailsCloudMock,
|
createdStateTaskDetailsCloudMock,
|
||||||
suspendedTaskDetailsCloudMock,
|
suspendedTaskDetailsCloudMock,
|
||||||
taskDetailsWithParentTaskIdMock
|
taskDetailsWithParentTaskIdMock,
|
||||||
|
createdTaskDetailsCloudMock
|
||||||
} from '../mocks/task-details-cloud.mock';
|
} from '../mocks/task-details-cloud.mock';
|
||||||
import moment from 'moment-es6';
|
import moment from 'moment-es6';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
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();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const value = fixture.debugElement.query(By.css(`[data-automation-id="header-assignee"] [data-automation-id="card-textitem-clickable-icon-assignee"]`));
|
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');
|
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', () => {
|
it('should render edit icon if the task in assigned state and assingee should be current user', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
const priorityEditIcon = fixture.debugElement.query(By.css(`[data-automation-id="header-priority"] [class*="adf-textitem-edit-icon"]`));
|
const priorityEditIcon = fixture.debugElement.query(By.css(`[data-automation-id="header-priority"] [class*="adf-textitem-edit-icon"]`));
|
||||||
|
@@ -31,7 +31,7 @@ import {
|
|||||||
CardViewDatetimeItemModel,
|
CardViewDatetimeItemModel,
|
||||||
CardViewArrayItem
|
CardViewArrayItem
|
||||||
} from '@alfresco/adf-core';
|
} 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 { TaskCloudService } from '../../services/task-cloud.service';
|
||||||
import { NumericFieldValidator } from '../../../validators/numeric-field.validator';
|
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',
|
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.ASSIGNEE',
|
||||||
value: this.taskDetails.assignee,
|
value: this.taskDetails.assignee,
|
||||||
key: 'assignee',
|
key: 'assignee',
|
||||||
clickable: this.isClickable(),
|
clickable: this.isAssigneePropertyClickable(),
|
||||||
default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.ASSIGNEE_DEFAULT'),
|
default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.ASSIGNEE_DEFAULT'),
|
||||||
icon: 'create'
|
icon: 'create'
|
||||||
}
|
}
|
||||||
@@ -318,9 +318,8 @@ export class TaskHeaderCloudComponent implements OnInit, OnDestroy, OnChanges {
|
|||||||
return this.taskCloudService.isTaskEditable(this.taskDetails);
|
return this.taskCloudService.isTaskEditable(this.taskDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
isClickable(): boolean {
|
isAssigneePropertyClickable(): boolean {
|
||||||
const states: TaskStatus[] = ['ASSIGNED', 'CREATED'];
|
return this.taskCloudService.isAssigneePropertyClickable(this.taskDetails, this.candidateUsers, this.candidateGroups);
|
||||||
return states.includes(this.taskDetails.status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private isValidSelection(filteredProperties: string[], cardItem: CardViewBaseItemModel): boolean {
|
private isValidSelection(filteredProperties: string[], cardItem: CardViewBaseItemModel): boolean {
|
||||||
|
Reference in New Issue
Block a user