SUPPORT-9225: fix blocking requests
This commit is contained in:
parent
204c3ee741
commit
305ee2378e
6 changed files with 47 additions and 22 deletions
|
|
@ -26,11 +26,14 @@ import {EditRolesData} from "./dto/edit/EditRolesData";
|
|||
import {ResetPasswordAccount} from "./dto/password/ResetPasswordAccount";
|
||||
import {ResetPasswordData} from "./dto/password/ResetPasswordData";
|
||||
import {ProcessRequest} from "./dto/ProcessRequest";
|
||||
import {StatusUpdateService} from "../../../modules/app/service/status-update.service";
|
||||
import {ApplicationStatus} from "../enum/ApplicationStatus";
|
||||
|
||||
@AnalyticalScope(SaveButton)
|
||||
export class UserManagementService extends Behavior {
|
||||
|
||||
private static PROCESS_START_PATH = '/service/wf/service/start';
|
||||
private static USER_BLOCK_PATH = "/service/idm/accounts/blocked/v1";
|
||||
|
||||
@NotNull()
|
||||
@ObjectRef()
|
||||
|
|
@ -42,6 +45,7 @@ export class UserManagementService extends Behavior {
|
|||
private sendToErvu: boolean = false;
|
||||
private rpc: UserApplicationListRpcService;
|
||||
private authService: AuthorizationService;
|
||||
private statusUpdateService: StatusUpdateService;
|
||||
|
||||
initialize() {
|
||||
super.initialize();
|
||||
|
|
@ -49,6 +53,7 @@ export class UserManagementService extends Behavior {
|
|||
this.httpClient = this.injector.get(HttpClient);
|
||||
this.rpc = this.getScript(UserApplicationListRpcService);
|
||||
this.authService = this.injector.get(AuthorizationService);
|
||||
this.statusUpdateService = this.injector.get(StatusUpdateService);
|
||||
this.onClickFunction = () => {
|
||||
if (!this.authService.hasRole('security_administrator') || !this.sendToErvu) {
|
||||
return;
|
||||
|
|
@ -120,10 +125,10 @@ export class UserManagementService extends Behavior {
|
|||
});
|
||||
break;
|
||||
case ApplicationKind.BLOCK_USER:
|
||||
//TODO delete request
|
||||
this.doBlockingRequest([accountId], appNumber, true);
|
||||
break;
|
||||
case ApplicationKind.UNBLOCK_USER:
|
||||
//TODO post request
|
||||
this.doBlockingRequest([accountId], appNumber, false);
|
||||
break;
|
||||
case ApplicationKind.RESET_PASSWORD:
|
||||
let resetPasswordAccount = new ResetPasswordAccount();
|
||||
|
|
@ -175,15 +180,36 @@ export class UserManagementService extends Behavior {
|
|||
this.rpc.saveTraceId(response.traceId, appNumber);
|
||||
}
|
||||
else {
|
||||
this.rpc.saveAgreedStatus(appNumber);
|
||||
this.saveStatus(ApplicationStatus.AGREED, appNumber);
|
||||
}
|
||||
})
|
||||
.catch(reason => {
|
||||
console.error("Error while executing request:", reason.toString());
|
||||
this.rpc.saveAgreedStatus(appNumber);
|
||||
this.saveStatus(ApplicationStatus.AGREED, appNumber);
|
||||
});
|
||||
}
|
||||
|
||||
private doBlockingRequest(ids: string[], appNumber: number, block: boolean): void {
|
||||
const url = window.location.origin + UserManagementService.USER_BLOCK_PATH;
|
||||
let method = block ? 'delete' : 'post';
|
||||
this.httpClient.request(method, url, { body: ids }).toPromise()
|
||||
.then((response: any) => {
|
||||
console.log(response);
|
||||
let status = response.ok ? ApplicationStatus.ACCEPTED : ApplicationStatus.AGREED;
|
||||
this.saveStatus(status, appNumber);
|
||||
})
|
||||
.catch(reason => {
|
||||
console.error("Error while executing request:", reason.toString());
|
||||
this.saveStatus(ApplicationStatus.AGREED, appNumber);
|
||||
});
|
||||
}
|
||||
|
||||
private saveStatus(status: string, appNumber: number): void {
|
||||
this.rpc.saveStatus(status, appNumber)
|
||||
.then(() => this.statusUpdateService.publishStatus(appNumber, status === 'ACCEPTED'))
|
||||
.catch(err => console.log('failed to update application status', err));
|
||||
}
|
||||
|
||||
bindEvents() {
|
||||
super.bindEvents();
|
||||
this.button.addClickListener(this.onClickFunction);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
export enum ApplicationStatus {
|
||||
AGREED = 'AGREED',
|
||||
ACCEPTED = 'ACCEPTED'
|
||||
}
|
||||
|
|
@ -18,11 +18,15 @@ export class StatusUpdateService {
|
|||
public update(responseObj: any): void {
|
||||
this.httpClient.put<number>('status', responseObj)
|
||||
.toPromise()
|
||||
.then(appNumber => this.statusMessage.next(
|
||||
{
|
||||
appNumber: appNumber,
|
||||
status: responseObj.className === 'update' ? ApplicationStatus.ACCEPTED : ApplicationStatus.AGREED
|
||||
}))
|
||||
.then(appNumber => this.publishStatus(appNumber, responseObj.className === 'update'))
|
||||
.catch(err => console.log('failed to update application status', err));
|
||||
}
|
||||
|
||||
public publishStatus(appNumber: number, accepted: boolean) {
|
||||
this.statusMessage.next(
|
||||
{
|
||||
appNumber: appNumber,
|
||||
status: accepted ? ApplicationStatus.ACCEPTED : ApplicationStatus.AGREED
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue