Get Role-duty-privilege-entry point access level

Get all entry point of one privilege

public void insertPrivilegAndEntryPoint(str _UserId)
{
    SecurityTask  securityTask;
    SecuritySubTask subTask;
    SecurityTaskEntryPoint  taskEntryPoint;
    SecurableObject         securableObject;

    while select Name, AOTName from tmpTable where tmpTable.Type == enum2str(SecurityTaskType::duty)
    {
        select RecId from securityTask where securityTask.aotname == tmpTable.AOTname;
        //get all privilege under Duty
        while select SecuritySubTask from subTask where subTask.SecurityTask == securityTask.RecId
        {
            //get privilege name
            select securityTask  where securityTask.RecId == subTask.SecuritySubTask
                && securityTask.Type == SecurityTaskType::Privilege ;
            
            this.insertEntryPoint(securityTask, _UserId);
            /*
            while select taskEntryPoint  where taskEntryPoint.SecurityTask == securityTask.RecId
            {
                select * from securableObject  where securableObject.RecId == taskEntryPoint.EntryPoint;

                    tmpTable.UserId      = _UserId;
                    tmpTable.Name        = securityTask.Name;
                    tmpTable.AOTName     = securityTask.AotName;
                    tmpTable.Type        = enum2str(securityTaskType::Privilege);
                    tmpTable.EPName      = securableObject.Name + securableObject.ChildName;
                    tmpTable.EPType      = enum2str(securableObject.Type);
                    tmpTable.AccessLevel = enum2str(taskEntryPoint.PermissionGroup);
                    tmpTable.insert();
            }
            */
        }
    }

}
private void insertEntryPoint(SecurityTask  _securityTask, str _userId)
{        
    #AOT

    Treenode dutyRoot,duty, Privilege;   
  
    Privilege = TreeNode::findNode(#SecPrivilegesPath
    +"\\" + _securityTask.AotName
    + "\\");

    dutyRoot = Privilege.AOTfirstChild();

    duty = dutyRoot.AOTfirstChild();   
    while(duty.AOTnextSibling())
    {
        //info(strFmt("  - %1,", duty.treeNodeName()));                            
        tmpTable.UserId      = _UserId;
        tmpTable.Name        = _securityTask.Name;
        tmpTable.AOTName     = _securityTask.AotName;
        tmpTable.Type        = enum2str(securityTaskType::Privilege);
        tmpTable.EPName      = duty.treeNodeName();
        tmpTable.EPType      = duty.AOTgetProperty('ObjectType');
        tmpTable.AccessLevel = duty.AOTgetProperty('AccessLevel');
        tmpTable.insert();
        duty = duty.AOTnextSibling();
    }
}
//get roleDuty or rolePrivilege Mapping
static void Job31(Args _args)
{
    SecurityRole            securityRole, securityRole1;
    SecurityUserRole        securityUserRole;
    SecurityTask            securityTask;
    SecuritySubTask         securitySubTask;
    SecurityRoleTaskGrant   securityRoleTaskGrant;
    UserInfo            userInfo;

    select id from userInfo where userInfo.id == 'annal';
    while select * from securityRole
            join securityUserRole
                where securityRole.RecId == SecurityUserRole.SecurityRole
                        && SecurityUserRole.User == userInfo.id
            {
                while select securityRoleTaskGrant
                    where securityRoleTaskGrant.SecurityRole == securityRole.RecId
                {
                    while select securityTask
                       where securityTask.RecId == securityRoleTaskGrant.SecurityTask
                        && securityTask.Type == SecurityTaskType::Duty // change type to get duty or privilege under a role
                        {
                            info(strFmt("%1 , %2,  %3", securityRole.AotName,securityTask.AotName));


                        }
                }
            }


}

Get privilege under role

image.png

Get duty under role

image.png
static void Job7(Args _args)
{
SecurityTaskEntryPoint  taskEntryPoint;
SecurityRole            role;
SecurityRoleTaskGrant   taskGrant;
SecuritySubTask         subTask;
SecurityTask            privilege;
str privName;
str dutyName;
str entrName;
str accessLevel;
;

while select taskEntryPoint
join subTask
    where subTask.SecuritySubTask == taskEntryPoint.SecurityTask
join taskGrant
    where taskGrant.SecurityTask == subTask.SecurityTask
join role
    where role.RecId == taskGrant.SecurityRole
    &&  role.AotName == 'LedgerAccountant'
    //|| role.AotName like 'System*'
{
     if (subTask.RecId)
    {
        switch (taskEntryPoint.PermissionGroup)
        {
            case AccessRight::View:
                accessLevel = "Read";
                break;
            case AccessRight::Edit:
                accessLevel = "Edit";
                break;
            case AccessRight::Add:
                accessLevel = "Create";
                break;
            case AccessRight::Delete:
                accessLevel = "Full Control";
                break;
            default:
                accessLevel = "";
                break;
        }
    }

    select privilege
        where privilege.RecId == taskGrant.SecurityTask
        && SecurityTaskType::Duty == privilege.Type;
    dutyName = privilege.AotName;

    select privilege
        where privilege.RecId == subTask.SecuritySubTask
        && SecurityTaskType::Privilege == privilege.Type;
    privName = privilege.AotName;

    info(strFmt("EP: %1, Pr: '%2', Du: %3, Ro: %4, Ac: %5", taskEntryPoint.EntryPoint, privName, dutyName, role.AotName, accessLevel));
    }
}

你可能感兴趣的:(Get Role-duty-privilege-entry point access level)