Quantcast
Channel: Vishy
Viewing all articles
Browse latest Browse all 27

Coding Code – Security role creator – II

$
0
0

Here is a variation of code that creates a duplicate of all standard roles and removes the human resources related duties from these duplicated roles.

static void DuplicateAllStandardRolesAndRemoveHR(Args _args)
{
    #AOT

    int             counter;
    int             numOfRolesDuplicated;

    TreeNode        securityRolesNode;
    int             sourceSecRolesCounter;

    TreeNode        securityRole, nextSecurityRole;
    str             securityRoleName;

    TreeNode        duplicatedSecurityRole;
    str             duplicatedSecurityRoleName;

    TreeNode        duplicatedSecurityRoleDuties;
    int             duplicatedSecRoleDutiesCount;
    int             counterDup;

    TreeNode        duty, nextDuty;
    str             dutyName;

    // Initialize first security role to copy duties from
    securityRolesNode = TreeNode::findNode(#SecRolesPath);
    sourceSecRolesCounter = securityRolesNode.AOTchildNodeCount();

    securityRole = securityRolesNode.AOTfirstChild();
    for(counter = 1; counter<=sourceSecRolesCounter; counter++)
    {
        nextSecurityRole = securityRole.AOTnextSibling();
        securityRoleName = securityRole.AOTname();
        if((subStr(securityRoleName, 1, 1) != '-') &&
           (securityRoleName != 'SystemUser') &&
           (subStr(securityRoleName, 1, 3) != 'sys') &&
           (subStr(securityRoleName, 1, 6) != 'retail') &&
           (subStr(securityRoleName, 1, 4) != 'copy') &&
           (subStr(securityRoleName, 1, 3) != 'Hcm')
          )
        {
            numOfRolesDuplicated++;
            duplicatedSecurityRole = securityRole.AOTDuplicate();
            duplicatedSecurityRoleName = duplicatedSecurityRole.AOTname();
            duplicatedSecurityRoleName = subStr(duplicatedSecurityRoleName, 7, strLen(duplicatedSecurityRoleName) - 6) + 'NoHR';
            duplicatedSecurityRole.AOTsetProperty('name', duplicatedSecurityRoleName);
            duplicatedSecurityRole.AOTsave();

            duplicatedSecurityRoleDuties = TreeNode::findNode(#SecRolesPath + '\\' + duplicatedSecurityRoleName + '\\Duties');
            duplicatedSecRoleDutiesCount = duplicatedSecurityRoleDuties.AOTchildNodeCount();
            duty = duplicatedSecurityRoleDuties.AOTfirstChild();
            for(counterDup = 1; counterDup <= duplicatedSecRoleDutiesCount; counterDup++)
            {
                nextDuty = duty.AOTnextSibling();
                // Delete the duty if this starts with HCM or JMG
                dutyName = duty.AOTname();
                if((subStr(dutyName, 1, 3) == 'HCM') || (subStr(dutyName, 1, 3) == 'JMG'))
                {
                    // This duty needs to be deleted
                    duty.AOTdelete();
                }
                duty = nextDuty;
            }
            duplicatedSecurityRole.AOTsave();
        }
        securityRole = nextSecurityRole;
    }
}


Viewing all articles
Browse latest Browse all 27

Trending Articles