Hi!
I am developing a SAP CAP App for the BTP right now and want to use Fiori Elements for my UI.
using { PLTRoleBasedPermissions as rbp} from './external/PLTRoleBasedPermissions';
service AuthServices @(path : '/auth') @(requires: 'authenticated-user')
{
@readonly
entity Roles as projection on rbp.RBPRole{
key roleId,
permissions : redirected to permissions
};
entity permissions as projection on rbp.RBPBasicPermission;
}For this service (the code is just a small part of it) I have my auth-services.js file where I implement the call of the Roles entity.Now my Fiori-Elements App calls the Roles entity and only wants to select one role ("/auth/Roles(12345)") - since this service will only be used in this Fiori-Elements App I would like to expand automatically towards permissions and want to filter them. This works - from my point of view - totally fine. When I output the result via "localhost:4004/auth/Roles(12345)" I only get the role and when I add "?$expand=permissions" I only get the permissions I want. but for some reason, when I use that in the Fiori-Elements App (List-Object Report) I get the complete list of permissions... unfiltered. Here my 2 functions to read the permissions + reading the roles (and filtering them)
Does anyone know why and what I could do here or why Fiori-Elements takes the unfiltered result? (and please don't judge my JavaScript too hard.. still a newbe here... somehow I couldn't do the filtering better :( )
this.on('READ', permissions, async req => await role_srv.run(req.query));
this.on('READ', Roles, async (req) => {
const permission_ids = readCriticalAuth();
if (permission_ids.length !== 0 && req.query.SELECT.one !== true && req.query.SELECT.where == undefined) {
req.query.SELECT.where = [{ ref: ['permissions', 'permissionId'] }, 'in', { list: permission_ids }];
} else if (permission_ids.length !== 0 && req.query.SELECT.one !== true) {
req.query.SELECT.where.push('and', { ref: ['permissions', 'permissionId'] }, 'in', { list: permission_ids });
}
// expand when we are requesting one specific role
if (req.query.SELECT.one == true && req.query.SELECT.columns !== undefined)
req.query.SELECT.columns.push({ ref: ['permissions'], expand: ['*'] });
// get all the roles + permission
let out = await role_srv.run(req.query);
if (req.query.SELECT.one == true && out.permissions !== undefined) {
let permission_output = [];
for (let index = 0; index < permission_ids.length; index++) {
let criticalPermissionId = permission_ids[index];
for (let out_permission_index = 0; out_permission_index < out.permissions.length; out_permission_index++) {
const out_permission = out.permissions[out_permission_index];
if (out_permission.permissionId == criticalPermissionId) {
permission_output.push(out_permission);
}
}
}
out.permissions = permission_output;
}
console.info(out);
return out;
});