kjell1906
(Kjell Dirdal)
April 4, 2018, 7:49am
#1
Does someone have an idea how to get result from cubaApp.getPermission()?
My code is as follow but this.permissionInfo is null or undefined.
private subject = new Subject<any>();
private userInfo: UserInfo;
private cubaApp: CubaApp;
private permissionInfo: PermissionInfo[];
constructor(private storageService: StorageService,
private alertService: AlertService,
private cubaIntegrationService: CubaIntegrationService) {
this.cubaApp = cubaIntegrationService.getCubaApp();
this.userInfo = this.storageService.getCurrentUser();
this.loadUserInfo();
}
loadUserInfo(): void {
this.cubaApp.getUserInfo()
.then(value => {
this.userInfo = value;
this.storageService.setCurrentUser(value);
this.subject.next({ userInfo: this.getCurrentUser() });
})
.catch(() => {
this.alertService.error('Can\'t obtain UserInfo');
});
this.cubaApp.getPermissions()
.then(value => {
this.permissionInfo = value;
})
.catch(() => {
this.alertService.error('Can\'t obtain PermissionInfo');
});
}
isAnonymous(): boolean {
return this.userInfo == null || this.userInfo.login === 'anonymous';
}
getCurrentUser(): UserInfo {
return this.isAnonymous() ? null : this.userInfo;
}
onUserInfoChanged(): Observable<any> {
return this.subject.asObservable();
}
getPermissionInfo(): PermissionInfo[] {
return this.permissionInfo ? null : this.permissionInfo;
}
minaev
(Vladislav Minaev)
April 4, 2018, 3:54pm
#3
Could you check if there are any explicitly specified permissions? Otherwise REST API returns an empty array.
kjell1906
(Kjell Dirdal)
April 4, 2018, 4:21pm
#4
So, if I am logged in as admin with default. Then there is an empty array. An if I make changes changes will be reflected in an filled array?
Is it normal to call this when getting userinfo or shall I use own service?
minaev
(Vladislav Minaev)
April 4, 2018, 5:29pm
#5
REST API returns compilation of permissions of all roles assigned to current user. If you change user (login/logout) or make any changes in roles you should load permissions again.
kjell1906
(Kjell Dirdal)
April 4, 2018, 7:07pm
#6
The reason was that the result from json never left the service. If I added the permissionInfo in storage service then I got the data out of the service.
minaev
(Vladislav Minaev)
April 5, 2018, 8:09am
#7
Sorry, I don’t get your last question. Could you please clarify what the problem is? I guess you are talking about Angular services?
kjell1906
(Kjell Dirdal)
April 5, 2018, 10:23am
#8
I have manged to solve the problem.
What I do miss is the actual name of entities, menu item and screen names. Is it possible to get these or are they in language files?
minaev
(Vladislav Minaev)
April 5, 2018, 11:41am
#9
Here is an example of permissions returned by REST
[
{
"type": "SCREEN",
"target": "sec$User.browse",
"value": "ALLOW",
"intValue": 1
},
{
"type": "ENTITY_OP",
"target": "sec$Filter:read",
"value": "ALLOW",
"intValue": 1
},
{
"type": "ENTITY_ATTR",
"target": "sec$SessionLogEntry:clientType",
"value": "MODIFY",
"intValue": 2
},
{
"type": "SPECIFIC",
"target": "cuba.restApi.enabled",
"value": "ALLOW",
"intValue": 1
}
]
So we have screen id in SCREEN
permissions and can parse entity name in ENTITY_OP
and ENTITY_ATTR
permissions.
kjell1906
(Kjell Dirdal)
April 5, 2018, 11:53am
#10
Sure.
{
"type": "SCREEN",
"target": "sec$User.browse",
"value": "ALLOW",
"intValue": 1
}
Is it any opportunity to get Entity Name or is this Entity Name in the language resource files.