[ADF-4269] ProcessCloud - fix start task with invalid Asignee or Candidat… (#4727)

* [ADF-4269] - prevent starting a task with invalid Asignee or CandidateUser

* [ADF-4269] - refractor people/group cloud

* [ADF-4269] - change docs
This commit is contained in:
Silviu Popa
2019-05-15 17:49:46 +03:00
committed by Maurizio Vitale
parent 4a363c731b
commit b4e3a71bef
7 changed files with 49 additions and 9 deletions

View File

@@ -71,6 +71,10 @@ export class GroupCloudComponent implements OnInit, OnChanges {
@Input()
preSelectGroups: GroupModel[] = [];
/** FormControl to search the group */
@Input()
searchGroupsControl: FormControl = new FormControl();
/** Role names of the groups to be listed. */
@Input()
roles: string[] = [];
@@ -98,8 +102,6 @@ export class GroupCloudComponent implements OnInit, OnChanges {
selectedGroups$: Observable<GroupModel[]>;
searchGroupsControl: FormControl = new FormControl('');
_subscriptAnimationState = 'enter';
clientId: string;
@@ -154,8 +156,6 @@ export class GroupCloudComponent implements OnInit, OnChanges {
this.searchedValue = value;
if (value) {
this.setError();
} else {
this.clearError();
}
}),
debounceTime(500),
@@ -300,7 +300,7 @@ export class GroupCloudComponent implements OnInit, OnChanges {
}
hasError(): boolean {
return this.searchGroupsControl && this.searchGroupsControl.errors && this.searchGroupsControl.errors.invalid;
return this.searchGroupsControl && this.searchGroupsControl.errors && (this.searchGroupsControl.errors.invalid || this.searchGroupsControl.errors.required);
}
setFocus(isFocused: boolean) {

View File

@@ -71,6 +71,10 @@ export class PeopleCloudComponent implements OnInit, OnChanges {
@Input()
preSelectUsers: IdentityUserModel[];
/** FormControl to search the user */
@Input()
searchUserCtrl: FormControl = new FormControl();
/** Placeholder translation key
*/
@Input()
@@ -97,8 +101,6 @@ export class PeopleCloudComponent implements OnInit, OnChanges {
selectedUsers$: Observable<IdentityUserModel[]>;
searchUsers$: Observable<IdentityUserModel[]>;
searchUserCtrl: FormControl = new FormControl();
_subscriptAnimationState: string = 'enter';
clientId: string;
@@ -241,7 +243,6 @@ export class PeopleCloudComponent implements OnInit, OnChanges {
if (!this.isMultipleMode()) {
this.removeUser.emit();
}
this.clearError();
}
}),
debounceTime(500),

View File

@@ -64,6 +64,7 @@
<adf-cloud-people fxFlex #peopleInput *ngIf="currentUser"
[appName]="appName"
[preSelectUsers]="[currentUser]"
[searchUserCtrl]="assigneeFormControl"
(selectUser)="onAssigneeSelect($event)"
[title]="'ADF_TASK_LIST.START_TASK.FORM.LABEL.ASSIGNEE'"
(removeUser)="onAssigneeRemove()"></adf-cloud-people>
@@ -74,6 +75,7 @@
[mode]="'multiple'"
[title]="'ADF_CLOUD_TASK_LIST.START_TASK.FORM.LABEL.CANDIDATE_GROUP'"
[appName]="appName"
[searchGroupsControl]="candidateUserFormControl"
(selectGroup)="onCandidateGroupSelect($event)"
(removeGroup)="onCandidateGroupRemove($event)">
</adf-cloud-group>
@@ -96,7 +98,7 @@
<button
color="primary"
type="submit"
[disabled]="dateError || !taskForm.valid || submitted || assignee.hasError() || candidateGroups.hasError()"
[disabled]="!canStartTask()"
mat-button
id="button-start">
{{'ADF_CLOUD_TASK_LIST.START_TASK.FORM.ACTION.START'|translate}}

View File

@@ -153,6 +153,18 @@ describe('StartTaskCloudComponent', () => {
expect(createNewTaskSpy).toHaveBeenCalledWith(taskRequest);
});
}));
it('should cannot start a task if assigne or candidate group is invalid', async(() => {
component.taskForm.controls['name'].setValue('fakeName');
fixture.detectChanges();
fixture.whenStable().then( () => {
const createTaskButton = <HTMLElement> element.querySelector('#button-start');
component.assignee.searchUserCtrl.setValue('');
component.candidateGroups.searchGroupsControl.setValue('');
fixture.detectChanges();
expect(createTaskButton.hasAttribute('disabled')).toEqual(true);
});
}));
});
it('should select logged in user as assignee by default', () => {

View File

@@ -99,6 +99,9 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy {
formKey: string;
private assigneeForm: AbstractControl = new FormControl('', [Validators.required]);
private groupForm: AbstractControl = new FormControl('');
private localeSub: Subscription;
private createTaskSub: Subscription;
@@ -190,9 +193,13 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy {
onAssigneeSelect(assignee: IdentityUserModel) {
this.assigneeName = assignee ? assignee.username : '';
this.groupForm.clearValidators();
this.groupForm.updateValueAndValidity();
}
onAssigneeRemove() {
this.groupForm.setValidators(Validators.required);
this.groupForm.updateValueAndValidity();
this.assigneeName = '';
}
@@ -210,6 +217,14 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy {
}
}
canStartTask(): boolean {
return !(this.dateError ||
!this.taskForm.valid ||
this.submitted ||
this.assignee.hasError() ||
this.candidateGroups.hasError());
}
public whitespaceValidator(control: FormControl) {
const isWhitespace = (control.value || '').trim().length === 0;
const isValid = control.value.length === 0 || !isWhitespace;
@@ -224,6 +239,14 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy {
return this.taskForm.get('priority');
}
get assigneeFormControl(): AbstractControl {
return this.assigneeForm;
}
get candidateUserFormControl(): AbstractControl {
return this.groupForm;
}
onFormSelect(formKey: string) {
this.formKey = formKey || '';
}