[DEV] continue integration rights

This commit is contained in:
Edouard DUPIN 2023-05-14 23:54:50 +02:00
parent 2d134fbb95
commit 9ec2f4f336
7 changed files with 146 additions and 35 deletions

View File

@ -82,6 +82,32 @@ public class UserResource {
}
return SqlWrapper.get(UserAuth.class, userId);
}
@GET
@Path("{userId}/application/{applicationId}/rights")
@RolesAllowed("ADMIN")
public List<Right> getApplicationRight(@Context SecurityContext sc,
@PathParam("userId") long userId,
@PathParam("applicationId") long applicationId) throws Exception {
return SqlWrapper.getsWhere(Right.class, List.of(
new WhereCondition("applicationId", "=", applicationId),
new WhereCondition("userId", "=", userId)),
false);
}
@PUT
@Path("{userId}/application/{applicationId}/rights")
@RolesAllowed("ADMIN")
public List<Right> patchApplicationRight(@Context SecurityContext sc,
@PathParam("userId") long userId,
@PathParam("applicationId") long applicationId, Map<String, Object> data) throws Exception {
logger.info("get data from FRONT: {}", data);
/*
return SqlWrapper.getsWhere(Right.class, List.of(
new WhereCondition("applicationId", "=", applicationId),
new WhereCondition("userId", "=", userId)),
false);
*/
return null;
}
// TODO: check this it might be deprecated ...

View File

@ -6,10 +6,12 @@
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ApplicationModel, ApplicationService, SettingsService } from 'base/service';
import { AdminUserService, ApplicationModel, ApplicationService, ApplicationUserRight, SettingsService } from 'base/service';
import { ApplicationRightModel } from 'base/service/application';
import { SettingType, SettingsItem } from '../manage-accounts/manage-accounts';
import { UserService } from 'common/service';
import { isUndefined } from 'common/utils';
import { AsyncActionState } from 'common/component';
@ -24,14 +26,16 @@ export class applicationUserRightEditScene implements OnInit {
applicationId: number = undefined;
userId: number = undefined;
application: ApplicationModel;
rowRight: ApplicationRightModel[];
rowRight: ApplicationRightModel[] = [];
applicationName: string;
userName: string;
userRights: ApplicationUserRight[] = [];
constructor(
private settingService: SettingsService,
private applicationService: ApplicationService,
private userService: UserService,
private userAdminService: AdminUserService,
private activatedRoute: ActivatedRoute,
private cdr: ChangeDetectorRef,
) { }
@ -65,14 +69,25 @@ export class applicationUserRightEditScene implements OnInit {
});
*/
this.applicationService
.getApplicationRights(this.applicationId)
.getRights(this.applicationId)
.then((response: ApplicationRightModel[]) => {
console.log(`??? get full response: ${JSON.stringify(response, null, 4)}`);
console.log(`getRights OK response: ${JSON.stringify(response, null, 4)}`);
self.rowRight = response;
this.configureEditInput();
self.configureEditInput();
})
.catch((error: any) => {
console.log(`??? get ERROR response: ${JSON.stringify(error, null, 4)}`);
console.log(`getRights ERROR response: ${JSON.stringify(error, null, 4)}`);
});
this.userAdminService
.getApplicationRights(this.userId, this.applicationId)
.then((userRights: ApplicationUserRight[]) => {
console.log(`getApplicationRights OK response: ${JSON.stringify(userRights, null, 4)}`);
self.userRights = userRights;
self.configureEditInput();
})
.catch((error: any) => {
console.log(`getApplicationRights ERROR response: ${JSON.stringify(error, null, 4)}`);
});
// get all the user connected on it
/*
@ -114,14 +129,35 @@ export class applicationUserRightEditScene implements OnInit {
const tmp = [];
for (let iii = 0; iii < this.rowRight.length; iii++) {
const elem = this.rowRight[iii];
let value = undefined;
for (let jjj = 0; jjj < this.userRights.length; jjj++) {
const elemRight = this.userRights[jjj];
if (elemRight.rightDescriptionId == elem.id) {
value = elemRight.value;
break;
}
}
// TODO: maybe transfer this in the SERVER API....
if (!isUndefined(value)) {
if (elem.type === "BOOLEAN") {
value = value.toLowerCase() == 'true';
} else if (elem.type === "STRING") {
// nothing to do...
} else if (elem.type === "LONG" || elem.type === "NUMBER") {
value = Number(value);
} else {
console.error(`Can not interpret type of the input value model: ${elem.type}`);
}
}
tmp.push({
type: SettingType.BOOLEAN,
title: elem.title,
description: elem.description,
key: elem.key,
value: false,
value: value,
});
}
console.log(`New menu: ${JSON.stringify(tmp, null, 4)}`);
this.editMenu = tmp;
this.cdr.detectChanges();
}
@ -145,29 +181,27 @@ export class applicationUserRightEditScene implements OnInit {
* Request the creation of a new application.
*/
onUpdate(): void {
/*
this.updateState = AsyncActionState.LOADING;
let self = this;
this.applicationService.update(this.id, this.dataUpdate)
.then(
(data: ApplicationModel) => {
self.updateState = AsyncActionState.DONE;
console.log(`Get new application data: ${JSON.stringify(data, null, 2)}`);
self.application = data;
self.configureEditInput()
setTimeout(() => {
this.updateState = undefined;
}, 3000);
}
).catch(
(error: any) => {
self.updateState = AsyncActionState.FAIL;
setTimeout(() => {
self.updateState = undefined;
}, 3000);
}
);
*/
console.log(`update requested: : ${JSON.stringify(this.dataUpdate, null, 2)}`);
this.userAdminService
.updateApplicationRights(this.userId, this.applicationId, this.dataUpdate)
.then((userRights: ApplicationUserRight[]) => {
console.log(`getApplicationRights OK response: ${JSON.stringify(userRights, null, 4)}`);
self.userRights = userRights;
self.updateState = AsyncActionState.DONE;
self.configureEditInput()
setTimeout(() => {
this.updateState = undefined;
}, 3000);
})
.catch((error: any) => {
console.log(`getApplicationRights ERROR response: ${JSON.stringify(error, null, 4)}`);
self.updateState = AsyncActionState.FAIL;
setTimeout(() => {
self.updateState = undefined;
}, 3000);
});
}
}

View File

@ -39,7 +39,7 @@ export class HomeScene implements OnInit {
self.transferToApplicationThatRequiredTheSSO2(result.url, result.jwt);
})
.catch((error: any) => {
console.error(`Can not retreive the application interface: ${error}`);
console.error(`Can not retrieve the application interface: ${error}`);
});
}

View File

@ -32,6 +32,10 @@ interface MessageAnswer_USER_CONNECT {
avatar: string;
}
*/
export interface ApplicationUserRight {
rightDescriptionId: number;
value: string;
}
@Injectable()
export class AdminUserService {
@ -350,5 +354,51 @@ export class AdminUserService {
});
});
}
// !!!!! la fonction ci dessous ne retourne pas des élément bijectif avec la fuction courente et c'est un problème...
getApplicationRights(userId: number, applicationId: number): Promise<ApplicationUserRight[]> {
const self = this;
return new Promise((resolve, reject) => {
this.http
.requestJson({
server: 'karso',
endPoint: `users/${userId}/application/${applicationId}/rights`,
requestType: HTTPRequestModel.GET,
accept: HTTPMimeType.JSON,
contentType: HTTPMimeType.JSON,
})
.then((response: ModelResponseHttp) => {
console.log(
`Get user Rights: ${JSON.stringify(response.data)}`
);
resolve(response.data);
})
.catch((error: any) => {
reject(`return ERROR ${JSON.stringify(error, null, 2)}`);
});
});
}
updateApplicationRights(userId: number, applicationId: number, dataUpdate: object): Promise<ApplicationUserRight[]> {
const self = this;
return new Promise((resolve, reject) => {
this.http
.requestJson({
server: 'karso',
endPoint: `users/${userId}/application/${applicationId}/rights`,
requestType: HTTPRequestModel.PUT,
accept: HTTPMimeType.JSON,
contentType: HTTPMimeType.JSON,
body: dataUpdate
})
.then((response: ModelResponseHttp) => {
console.log(
`Get user Rights: ${JSON.stringify(response.data)}`
);
resolve(response.data);
})
.catch((error: any) => {
reject(`return ERROR ${JSON.stringify(error, null, 2)}`);
});
});
}
}

View File

@ -59,7 +59,7 @@ export class ApplicationService {
console.log('Start ApplicationService');
}
getApplicationRights(applicationId: number): Promise<ApplicationRightModel[]> {
getRights(applicationId: number): Promise<ApplicationRightModel[]> {
const self = this;
return new Promise((resolve, reject) => {
this.http

View File

@ -1,6 +1,6 @@
import { AdminUserService } from './admin-user';
import { AdminUserService, ApplicationUserRight } from './admin-user';
import { ApplicationModel, ApplicationService } from './application';
import { ApplicationTokenService } from './application-token';
import { SettingsService } from './settings';
export { AdminUserService, ApplicationService, SettingsService, ApplicationModel, ApplicationTokenService };
export { AdminUserService, ApplicationService, SettingsService, ApplicationModel, ApplicationTokenService, ApplicationUserRight };

View File

@ -56,7 +56,7 @@ export interface ModelResponseHttp {
@Injectable()
export class HttpWrapperService {
private displayReturn: boolean = false;
constructor(private http: HttpClient, private session: SessionService) {}
constructor(private http: HttpClient, private session: SessionService) { }
addTokenIfNeeded(headerOption: any): any {
const token = this.session.getToken();
@ -72,7 +72,7 @@ export class HttpWrapperService {
//uriRest:string, headerOption:any, params:any): Promise<{status:number, data:any}> {
//console.log(`-------------------------------------------------------\nHTTP-wrapper GET '${ properties.endPoint }'\n\t\tparams=${ JSON.stringify(properties, null, 2)}`);
let connectionAdresse = this.createRESTCall2({
let connectionAddresses = this.createRESTCall2({
server: properties.server,
api: properties.endPoint,
inputOptions: properties.params,
@ -100,7 +100,8 @@ export class HttpWrapperService {
if (properties.contentType === HTTPMimeType.JSON) {
body = JSON.stringify(properties.body);
}
const result = fetch(connectionAdresse, {
console.log(`Call ${connectionAddresses}`)
const result = fetch(connectionAddresses, {
method: properties.requestType,
headers,
body,