//#import Util.js
//#import $owl_orgs:services/modelService.jsx
//#import $owl_org_modules:services/modelService.jsx
//#import $owl_roles:services/modelService.jsx
//#import $owl_permission:services/modelService.jsx
//#import session.js
//#import $owl_backend_session:services/modelService.jsx

function getPermissions(roleId){
    var searchArgs = {
        roleId: roleId
    }
    var sr = owl_permissionService.search("0",searchArgs,null,0,10000,null);
    // $.log("getPermissions,roleId=" + roleId + ",tableId=" + tableId);
    if(sr.state==='ok'){
        // $.log("getPermissions,roleId=" + roleId + ",tableId=" + tableId + ", length=" + sr.list.length);
        return sr.list;
    }
    return [];
}

function main(){
    var params = JSON.parse($body);
    var isid = SessionService.getSessionId(request);
    var sessionId = 'owl_backend_session_' + isid;

    var session = owl_backend_sessionService.get(sessionId);
    var roleId = params.rroleId || session.roleId ;

    var permissions = getPermissions(roleId);
    var ret = {
        state:'ok',
        permissions:permissions
    }
    out.print(JSON.stringify(ret));


}
main();
