Skip to content

Commit

Permalink
Merge pull request #1044 from Crown-Commercial-Service/p3-sprint3-cod…
Browse files Browse the repository at this point in the history
…e-climate-issue

P3 sprint3 code climate issue
  • Loading branch information
ajithmuthukumar-bc authored Jan 20, 2023
2 parents e8a4386 + 3c79639 commit 84c8f61
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,10 @@ export class ViewPendingVerificationComponent implements OnInit {
10
).subscribe({
next: async (orgListResponse: OrganisationAuditListResponse) => {
if (orgListResponse != null) {
if(orgListResponse.organisationAuditList.length != 0){
let orgDetails = orgListResponse.organisationAuditList.find((element)=> element.organisationId === this.routeDetails.organisationId )
if(orgDetails === undefined){
this.getVerifiedOrg()
} else {
this.routeDetails = orgDetails
this.getSchemesDetails()
}
if (orgListResponse != null && orgListResponse.organisationAuditList.length != 0) {
this.checkPendingOrganisation(orgListResponse)
} else {
this.getVerifiedOrg()
}
}
},
error: (error: any) => {
Expand All @@ -262,6 +254,16 @@ export class ViewPendingVerificationComponent implements OnInit {
});
}

private checkPendingOrganisation(orgListResponse: OrganisationAuditListResponse){
let orgDetails = orgListResponse.organisationAuditList.find((element)=> element.organisationId === this.routeDetails.organisationId )
if(orgDetails === undefined){
this.getVerifiedOrg()
} else {
this.routeDetails = orgDetails
this.getSchemesDetails()
}
}

getVerifiedOrg() {
this.wrapperBuyerAndBothService.getVerifiedOrg(
this.organisationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,8 @@ export class ViewVerifiedOrgComponent implements OnInit {
).subscribe({
next: async (orgListResponse: OrganisationAuditListResponse) => {
this.getSchemeData()
if (orgListResponse != null) {
if (orgListResponse.organisationAuditList.length != 0) {
let orgDetails:any = orgListResponse.organisationAuditList.find((element) => element.organisationId === this.routeDetails.event.organisationId)
if (orgDetails != undefined) {
orgDetails.lastRoute ="view-verified"
this.router.navigateByUrl(
'pending-verification?data=' + btoa(JSON.stringify(orgDetails))
);
}

}
if (orgListResponse != null && orgListResponse.organisationAuditList.length != 0) {
this.verficatingOrgnisation(orgListResponse)
}
},
error: (error: any) => {
Expand All @@ -279,6 +270,17 @@ export class ViewVerifiedOrgComponent implements OnInit {
});
}

private verficatingOrgnisation(orgListResponse: OrganisationAuditListResponse){
let orgDetails:any = orgListResponse.organisationAuditList.find((element) => element.organisationId === this.routeDetails.event.organisationId)
if (orgDetails != undefined) {
orgDetails.lastRoute ="view-verified"
this.router.navigateByUrl(
'pending-verification?data=' + btoa(JSON.stringify(orgDetails))
);
}
}


getVerifiedOrg() {
this.wrapperBuyerAndBothService.getVerifiedOrg(
this.organisationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class ManageUserAddSingleUserDetailComponent
public idpStatus = environment.appSetting.hideIDP
public approveRequiredRole: Role[];
public organisationDetails: any = {}
public pendingRoleDetails: any = []
public pendingRoleDetails: any = []
public selectedApproveRequiredRole: any = []
public pendingRoledeleteDetails: any = []
public detailsData: any = [
Expand All @@ -70,6 +70,7 @@ export class ManageUserAddSingleUserDetailComponent
public emailHaserror: boolean = false;
public MFA_Enabled: any = false;
ciiOrganisationId: string;
private selectedRoleIds: number[] = []
@ViewChildren('input') inputs!: QueryList<ElementRef>;
isInvalidDomain: boolean = false

Expand Down Expand Up @@ -312,27 +313,27 @@ export class ManageUserAddSingleUserDetailComponent
this.userProfileResponseInfo.detail.rolePermissionInfo.some(
(rp) => rp.roleId == role.roleId
);
if(!this.isEdit){
this.formGroup.addControl(
'orgRoleControl_' + role.roleId,
this.formBuilder.control(userRole ? true : '')
);
} else {
let PendinguserRole = this.pendingRoleDetails.some(
(pendingRole: any) => pendingRole.roleKey == role.roleKey
);
this.formGroup.addControl(
'orgRoleControl_' + role.roleId,
this.formBuilder.control(userRole ? true : PendinguserRole ? true : '')
);
if(userRole == true){
role.enabled = true
}
let filterRole = this.pendingRoleDetails.find((element: { roleKey: any; }) => element.roleKey == role.roleKey)
if (filterRole != undefined) {
role.pendingStatus = true
}
if (!this.isEdit) {
this.formGroup.addControl(
'orgRoleControl_' + role.roleId,
this.formBuilder.control(userRole ? true : '')
);
} else {
let PendinguserRole = this.pendingRoleDetails.some(
(pendingRole: any) => pendingRole.roleKey == role.roleKey
);
this.formGroup.addControl(
'orgRoleControl_' + role.roleId,
this.formBuilder.control(userRole ? true : PendinguserRole ? true : '')
);
if (userRole == true) {
role.enabled = true
}
let filterRole = this.pendingRoleDetails.find((element: { roleKey: any; }) => element.roleKey == role.roleKey)
if (filterRole != undefined) {
role.pendingStatus = true
}
}
//Edit mode Determin Login user whether Admin/Normal user.
if (
role.roleKey == 'ORG_ADMINISTRATOR' &&
Expand All @@ -347,7 +348,7 @@ export class ManageUserAddSingleUserDetailComponent

async getApprovalRequriedRoles() {
this.approveRequiredRole = await this.organisationGroupService
.getOrganisationApprovalRequiredRoles(this.organisationId)
.getOrganisationApprovalRequiredRoles()
.toPromise();
}

Expand Down Expand Up @@ -450,38 +451,53 @@ export class ManageUserAddSingleUserDetailComponent


getSelectedRoleIds(form: FormGroup) {
let selectedRoleIds: number[] = [];
this.selectedRoleIds = []
this.selectedApproveRequiredRole = []
const superAdminDomain = this.organisationDetails.detail.domainName.toLowerCase()
const userDomain = this.formGroup.get('userName')?.value.split("@")[1].toLowerCase()
this.orgRoles.map((role) => {
if (form.get('orgRoleControl_' + role.roleId)?.value === true) {
if(superAdminDomain != userDomain){
let filterRole = this.approveRequiredRole.find((element: { roleKey: any; }) => element.roleKey == role.roleKey)
if (filterRole === undefined) {
selectedRoleIds.push(role.roleId)
} else {
if(this.pendingRoleDetails.length != 0){
let filterAlreadyExistRole = this.pendingRoleDetails.find((element: { roleKey: any; }) => element.roleKey == role.roleKey)
if(filterAlreadyExistRole.roleKey != role.roleKey){
this.selectedApproveRequiredRole.push(role.roleId)
}
} else {
if(!role.enabled){
this.selectedApproveRequiredRole.push(role.roleId)
} else {
selectedRoleIds.push(role.roleId)
}
}
}
if (superAdminDomain != userDomain) {
this.invalidDomainConfig(role)
} else {
selectedRoleIds.push(role.roleId)
this.selectedRoleIds.push(role.roleId)
}
}
});
return selectedRoleIds;
return this.selectedRoleIds;
}

private invalidDomainConfig(role: any) {
let filterRole = this.approveRequiredRole.find((element: { roleKey: any; }) => element.roleKey == role.roleKey)
if (filterRole === undefined) {
this.selectedRoleIds.push(role.roleId)
} else {
this.pendingRolecheck(role)
}
}

private pendingRolecheck(role: any) {
if (this.pendingRoleDetails.length != 0) {
this.whenPendingRoleHavingLength(role)
} else {
this.whenPendingRoleNoLength(role)
}
}

private whenPendingRoleHavingLength(role: any) {
let filterAlreadyExistRole = this.pendingRoleDetails.find((element: { roleKey: any; }) => element.roleKey == role.roleKey)
if (filterAlreadyExistRole.roleKey != role.roleKey) {
this.selectedApproveRequiredRole.push(role.roleId)
}
}

private whenPendingRoleNoLength(role: any) {
if (!role.enabled) {
this.selectedApproveRequiredRole.push(role.roleId)
} else {
this.selectedRoleIds.push(role.roleId)
}
}

private submitPendingApproveRole(): void {
let selectedRolesDetails = {
Expand All @@ -491,24 +507,26 @@ export class ManageUserAddSingleUserDetailComponent
}
}
if (this.selectedApproveRequiredRole.length != 0 && this.isInvalidDomain) {
this.wrapperUserService.createPendingApproveRole(selectedRolesDetails).subscribe({
next: (roleInfo: UserEditResponseInfo) => {
if (this.pendingRoledeleteDetails.length != 0) {
this.deleteApprovePendingRole()
}
},
error: (err: any) => {
console.log(err)
},
});
} else {
if (this.pendingRoledeleteDetails.length != 0) {
this.deleteApprovePendingRole()
}
this.UpdatePendingApproveRole(selectedRolesDetails)
} else if (this.pendingRoledeleteDetails.length != 0) {
this.deleteApprovePendingRole()
}

}

private UpdatePendingApproveRole(selectedRolesDetails: any) {
this.wrapperUserService.createPendingApproveRole(selectedRolesDetails).subscribe({
next: (roleInfo: UserEditResponseInfo) => {
if (this.pendingRoledeleteDetails.length != 0) {
this.deleteApprovePendingRole()
}
},
error: (err: any) => {
console.log(err)
},
});
}

saveChanges(actionMode: string, form: FormGroup) {
if (actionMode === "update") {
this.updateUser(form);
Expand All @@ -527,16 +545,16 @@ export class ManageUserAddSingleUserDetailComponent
this.isInvalidDomain = true
let matchRoles: any = []
const selectedRole: any = this.selectedApproveRequiredRole
this.orgRoles.forEach((allRole:Role)=>{
this.approveRequiredRole.forEach((aRole:Role)=>{
if(allRole.roleKey === aRole.roleKey){
selectedRole.forEach((sRole: number)=>{
if(allRole.roleId === sRole){
this.orgRoles.forEach((allRole: Role) => {
this.approveRequiredRole.forEach((aRole: Role) => {
if (allRole.roleKey === aRole.roleKey) {
selectedRole.forEach((sRole: number) => {
if (allRole.roleId === sRole) {
matchRoles.push(aRole)
}
})
}
})
})
})
localStorage.setItem('user_approved_role', JSON.stringify(matchRoles));
}
Expand Down Expand Up @@ -749,9 +767,9 @@ export class ManageUserAddSingleUserDetailComponent
let data = {
isEdit: false,
groupId: groupId,
accessFrom:"users",
userEditStatus:this.isEdit,
isUserAccess:true
accessFrom: "users",
userEditStatus: this.isEdit,
isUserAccess: true
};
this.router.navigateByUrl(
'manage-groups/view?data=' + JSON.stringify(data),
Expand All @@ -762,31 +780,40 @@ export class ManageUserAddSingleUserDetailComponent
onUserRoleChecked(obj: any, isChecked: boolean) {
var roleKey = obj.roleKey;
if (isChecked == true) {
if (roleKey == 'ORG_ADMINISTRATOR') {
this.formGroup.controls['mfaEnabled'].setValue(true);
this.isAutoDisableMFA = true;
}
this.setMfaStatus(roleKey,true)
if (obj.pendingStatus === true) {
let filterRole = this.pendingRoledeleteDetails.find((element: number) => element == obj.roleId)
if (filterRole != undefined) {
this.pendingRoledeleteDetails.forEach((pRole:any,index:any)=>{
if(pRole === obj.roleId){
this.pendingRoledeleteDetails.splice(index,1)
}
})
}
this.removePendingRole(obj)
}
}
else if (isChecked == false) {
if (roleKey == 'ORG_ADMINISTRATOR') {
this.formGroup.controls['mfaEnabled'].setValue(false);
this.isAutoDisableMFA = false;
}
if (obj.pendingStatus === true) {
let filterRole = this.pendingRoledeleteDetails.find((element: number) => element == obj.roleId)
if (filterRole === undefined) {
this.pendingRoledeleteDetails.push(obj.roleId)
}
this.setMfaStatus(roleKey,false)
this.addPendingRole(obj)
}
}

private setMfaStatus(roleKey: any,status:boolean) {
if (roleKey == 'ORG_ADMINISTRATOR') {
this.formGroup.controls['mfaEnabled'].setValue(status);
this.isAutoDisableMFA = status;
}
}

private removePendingRole(obj: any) {
let filterRole = this.pendingRoledeleteDetails.find((element: number) => element == obj.roleId)
if (filterRole != undefined) {
this.pendingRoledeleteDetails.forEach((pRole: any, index: any) => {
if (pRole === obj.roleId) {
this.pendingRoledeleteDetails.splice(index, 1)
}
})
}
}

private addPendingRole(obj:any){
if (obj.pendingStatus === true) {
let filterRole = this.pendingRoledeleteDetails.find((element: number) => element == obj.roleId)
if (filterRole === undefined) {
this.pendingRoledeleteDetails.push(obj.roleId)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1 *ngIf="isEdit!=true" class="govuk-heading-xl page-title">{{ 'ADD_ANOTHER_CON
<h1 *ngIf="isEdit==true" class="govuk-heading-xl page-title">{{ 'EDIT_CONTACT_DETAILS' | translate }}</h1>
<div class="govuk-error-summary contact-form-error" aria-labelledby="error-summary-title" role="alert"
tabindex="-1" id="error-summary" data-module="govuk-error-summary"
*ngIf="!formValid(formGroup) && submitted || validator && submitted">
*ngIf="!formValid(formGroup) && submitted || validators && submitted">
<h2 class="govuk-error-summary__title" id="error-summary-title">
{{ 'ERROR_SUMMARY' | translate }}
</h2>
Expand Down Expand Up @@ -66,7 +66,7 @@ <h2 class="govuk-error-summary__title" id="error-summary-title">
<a href="javascript:;" onClick="return false;" (click)="setFocusForIntlTelComponent('web')"> {{
'ERROR_INVALID_WEB_ADD' | translate }} </a>
</li>
<li *ngIf="submitted && validator">
<li *ngIf="submitted && validators">
<a href="javascript:;" onClick="return false;"
(click)="setFocusForIntlTelComponent('email-checkbox')"> Enter at least one contact
detail from either email address, telephone number, mobile number, fax number or web
Expand Down Expand Up @@ -112,10 +112,10 @@ <h2 class="govuk-error-summary__title" id="error-summary-title">
<input #input formControlName="name" class="govuk-input" id="name" name="name" type="text" (input)="whiteSpaceValidator"
[class.govuk-input--error]="submitted && (formGroup.controls.name.errors?.required || formGroup.controls.name.errors?.pattern || formGroup.controls.name.errors?.minlength || formGroup.controls.name.errors?.maxlength)">
</div>
<div [class.govuk-form-group--error]="submitted && validator">
<div [class.govuk-form-group--error]="submitted && validators">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--m ng-tns-c265-1"> Enter at least
one of the following contact details </legend>
<span *ngIf="submitted && validator" id="name-error"
<span *ngIf="submitted && validators" id="name-error"
class="govuk-error-message ng-tns-c265-1 ng-star-inserted"><span
class="govuk-visually-hidden ng-tns-c265-1">Error:</span> Enter at least one contact
detail from either email address, telephone number, mobile number, fax number or web
Expand Down
Loading

0 comments on commit 84c8f61

Please sign in to comment.