project QadFinancials > class BRole > method GetRoleAndPermissionsData

Description

returns the Role table and the RolePermissions table for in the treeview


Parameters


ovBRoleoutputdataset
tRolePermissionsoutputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program/brole.p)

define buffer btqMenuDetailForMenuFolders for tqMenuDetailForMenuFolders.

<ANCESTOR-CODE>

if oiReturnStatus = 0 
then assign oiReturnStatus = -98.

empty temp-table tRolePermissions.

if current-language = '' or current-language = '?' or current-language = ?
then assign current-language = 'US':U.

/* ===================================================================================== */
/* Get all available resources and the linked mnd_det records                            */
/* It is possible that 1 resource has multiple occurrences in the tRolePermissions table */
/* It is possible that a resource has no mnd_det record linked at all                    */
/* ===================================================================================== */

/* get menu folders */
<Q-2 run MenuDetailForMenuFolders (all) (Read) (NoCache)
   (input current-language, (LngCode)
    output dataset tqMenuDetailForMenuFolders) in BMfgMenu >

/* BLF-4014 workaround for the issue where operator begins 'A.' cannot be used on Oracle dataserver */
for each tqMenuDetailForMenuFolders where
         tqMenuDetailForMenuFolders.tcmnd_exec begins "A" and
         tqMenuDetailForMenuFolders.tcmnd_exec <> "A" and
         not tqMenuDetailForMenuFolders.tcmnd_exec begins "A.":
    delete tqMenuDetailForMenuFolders.
end.

/* Validate the correctness of the menu folders first */
for each tqMenuDetailForMenuFolders :

    /* ============================================================================================================== */
    /* Check on duplicate root levels - this is to avoid the .Net message "An entry with the same key already exists" */
    /* The following is not allowed (but the menu maintenance does not raise on error on this)                        */
    /* mnd_nbr mnd_select                                                                                             */
    /* A.x        a                                                                                                   */
    /* A.y        a                                                                                                   */
    /* a                                                                                                              */
    /* ============================================================================================================== */
    if tqMenuDetailForMenuFolders.tcmnd_nbr begins 'A.'
    then do:

        assign viNbrOfRootEntries = 0
               vcDuplicateEntry   = ''.
        for each btqMenuDetailForMenuFolders where
                 btqMenuDetailForMenuFolders.tcmnd_nbr begins 'A.' and                                                
                 btqMenuDetailForMenuFolders.timnd_select = tqMenuDetailForMenuFolders.timnd_select
                 by btqMenuDetailForMenuFolders.tcmnd_nbr
                 :
            assign viNbrOfRootEntries = viNbrOfRootEntries + 1
                   vcDuplicateEntry = vcDuplicateEntry + 
                                      (if viNbrOfRootEntries > 1 then '  ' else '') +
                                      btqMenuDetailForMenuFolders.tcmnd_nbr.
        end. /* for each btqMenuDetailForMenuFolders */

        if viNbrOfRootEntries > 1                                                    
        then do:
            assign vcLocalMessage =  trim (substitute (#T-42'There are more entries found for the root level '&1'. You can check the menu entries '&2' with menu maintenance.':255(371622100)T-42#, string (tqMenuDetailForMenuFolders.timnd_select), vcDuplicateEntry)).
            <M-49 run SetMessage
               (input  vcLocalMessage (icMessage), 
                input  '' (icArguments), 
                input  '' (icFieldName), 
                input  '' (icFieldValue), 
                input  'E' (icType), 
                input  3 (iiSeverity), 
                input  '' (icRowid), 
                input  'qadfin-541314':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BRole>
            assign oiReturnStatus = -1.
            return.
        end. 
    end.

    if  tqMenuDetailForMenuFolders.tcmnd_nbr = '' or
        tqMenuDetailForMenuFolders.tcmnd_nbr = '0' or
        tqMenuDetailForMenuFolders.tcmnd_nbr begins 'A' or
        tqMenuDetailForMenuFolders.tcmnd_exec matches '*.p' /* program starting with a number like 123abc.p */
    then next.

    if tqMenuDetailForMenuFolders.tcmnd_exec <> tqMenuDetailForMenuFolders.tcmnd_nbr + '.' + string (tqMenuDetailForMenuFolders.timnd_select)
    then do :
        assign vcLocalMessage = 
            trim (subst (#T-57'There is an invalid menu definition for the entry: &1. Use 'Menu System Maintenance' to validate and correct.':255(981357041)T-57#,tqMenuDetailForMenuFolders.tcmnd_nbr + "." + string (tqMenuDetailForMenuFolders.timnd_select))).

        <M-30 run SetMessage
           (input  vcLocalMessage (icMessage), 
            input  '' (icArguments), 
            input  '' (icFieldName), 
            input  '' (icFieldValue), 
            input  'E' (icType), 
            input  3 (iiSeverity), 
            input  '' (icRowid), 
            input  'qadfin-799019':U (icFcMsgNumber), 
            input  'mnd_exec should correspond with mnd_nbr.mnd_select' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  'mnd_exec=' + tqMenuDetailForMenuFolders.tcmnd_exec (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BRole>
        assign oiReturnStatus = -1.
        return.
    end.

end. /* for each tqMenuDetailForMenuFolders */


<Q-9 run ResourceInfo (all) (Read) (NoCache)
   (input '', (URImatches)
    output dataset tqResourceInfo) in BResource>

<Q-10 run MenuDetailByAll (all) (Read) (NoCache)
    (output dataset tqMenuDetailByAll) in BMfgMenu >

<Q-11 run MenuDetailTranslationInfo (all) (Read) (NoCache)
   (input current-language, (LngCode)
    output dataset tqMenuDetailTranslationInfo) in BMfgMenu >

<Q-71 run BusComponentForAllCategory (all) (Read) (NoCache)  (output dataset tqBusComponentForAllCategory) in BBusinessComponent >

for each tqResourceInfo :
   if tqResourceInfo.tcResourceURI matches '*ObjectSecurity' or
      tqResourceInfo.tcResourceURI matches '*ReturnToSender'       
   then delete tqResourceInfo.
end.

/* ===================================================================================================== */
/* Now we know all resources and where they are on the menu. We will create now a record in the output   */
/* dataset.                                                                                              */
/* ===================================================================================================== */
for each tRole:

    create tRolePermissions.
    assign tRolePermissions.tcLabel = trim(#T-3'Secured items on menu':255(63693)T-3#)
           tRolePermissions.tcMenuNbr = 'root':U
           tRolePermissions.tcResourceURI = ''
           tRolePermissions.tiMenuSelect = 1
           tRolePermissions.tiResource_ID = 0
           tRolePermissions.tiRole_ID = tRole.Role_ID
           tRolePermissions.tlRoleResourceLinked = false
           tRolePermissions.tcMenuExec = 'A':U
           tRolePermissions.tlChanged  = false.

    create tRolePermissions.
    assign tRolePermissions.tcLabel = trim(#T-4'Secured items not on menu':255(63694)T-4#)
           tRolePermissions.tcMenuNbr = 'root':U
           tRolePermissions.tcResourceURI = ''
           tRolePermissions.tiMenuSelect = 2
           tRolePermissions.tiResource_ID = 0
           tRolePermissions.tiRole_ID = tRole.Role_ID
           tRolePermissions.tlRoleResourceLinked = false
           tRolePermissions.tcMenuExec = 'B':U
           tRolePermissions.tlChanged  = false.
    
    assign viFcCount1 = 0
           viFcCount2 = 0
           vlgcg      = yes.

    /* go through each resource - with 0,1 or mulitople mnd_det records linked to it */
    for each tqResourceInfo by tqResourceInfo.tcResourceURI :

        /* check if linked already */
        assign vlLinked = no.
        for first tRoleResource where
                  tRoleResource.tc_ParentRowid = tRole.tc_Rowid and
                  tRoleResource.Resource_ID    = tqResourceInfo.tiResource_ID 
                  :
            assign vlLinked = yes.
        end.

        assign vlMenuLinked = no.
        /* Go through all menu entries for this resource */
        for each tqMenuDetailByAll where
                 tqMenuDetailByAll.tcmnd_uri = tqResourceInfo.tcResourceURI
                 :

            assign vlMenuLinked = true.

            /* Get mnt_det for translation */
            find first tqMenuDetailTranslationInfo where
                       tqMenuDetailTranslationInfo.tcmnt_nbr    = tqMenuDetailByAll.tcmnd_nbr and
                       tqMenuDetailTranslationInfo.timnt_select = tqMenuDetailByAll.timnd_select
                       no-error.

            create tRolePermissions.
            assign tRolePermissions.tcLabel = (if available tqMenuDetailTranslationInfo
                                               then tqMenuDetailTranslationInfo.tcmnt_label
                                               else tqMenuDetailByAll.tcmnd_label )                                                                                                 
                   tRolePermissions.tcMenuNbr            = tqMenuDetailByAll.tcmnd_nbr
                   tRolePermissions.tiMenuSelect         = tqMenuDetailByAll.timnd_select
                   tRolePermissions.tcResourceURI        = tqResourceInfo.tcResourceURI                   
                   tRolePermissions.tiResource_ID        = tqResourceInfo.tiResource_ID
                   tRolePermissions.tiRole_ID            = tRole.Role_ID
                   tRolePermissions.tlRoleResourceLinked = vlLinked
                   tRolePermissions.tcMenuExec           = tqMenuDetailByAll.tcmnd_exec
                   tRolePermissions.tlChanged            = false.

            /* Place the URI between brackets */                                                        
            assign tRolePermissions.tcLabel = tRolePermissions.tcLabel + ' (' + 
                                              tqResourceInfo.tcResourceURI + ')'.
    
            /* Place the menu structure between brackets */                                                        
            assign tRolePermissions.tcLabel = tRolePermissions.tcLabel + ' (':U + 
                                              trim (tRolePermissions.tcMenuNbr) + '.':U +
                                              trim (string (tRolePermissions.tiMenuSelect)) + ')':U.

            /* Place the menu security level between brackets */
            if tqResourceInfo.tcResourceType = {&RESOURCE-TYPE-ACTIVITY}
            then assign tRolePermissions.tcLabel = tRolePermissions.tcLabel + ' [' +
                                                   trim (#T-12'Entity':255(56602)T-12#) + ']'.

            else if tqResourceInfo.tcResourceType = {&RESOURCE-TYPE-MENU}
            then assign tRolePermissions.tcLabel = tRolePermissions.tcLabel + ' [' +
                                                   trim (#T-13'Domain':20(60834)T-13#) + ']'.


        end. /* for each tqMenuDetailByAll */

        if not vlMenuLinked
        then do :
            
            /* Skip reports that are not in the menu. */
            if tqResourceInfo.tcResourceURI begins "urn:cbf:"
            then if can-find (first tqBusComponentForAllCategory where
                                    tqBusComponentForAllCategory.tcBusComponentCode = entry(1,entry(3,tqResourceInfo.tcResourceURI,":"),".") and
                                    tqBusComponentForAllCategory.tcBusComponentCategory = "Reports")
                 then next.
            
            if tqResourceInfo.tcResourceURI begins "urn:gencodegroup:"
            then do:
                if vlgcg
                then do:
                    assign viFcCount1 = 0
                           viFcCount2 = viFcCount2 + 1.
                           vlgcg = no.
    
                    create tRolePermissions.
                    assign tRolePermissions.tcLabel              = #T-66'Generalized Code Groups':40(645423447)T-66#
                           tRolePermissions.tcMenuNbr            = 'B':U
                           tRolePermissions.tcResourceURI        = ''
                           tRolePermissions.tiMenuSelect         = viFcCount2
                           tRolePermissions.tiResource_ID        = 0
                           tRolePermissions.tiRole_ID            = tRole.Role_ID
                           tRolePermissions.tlRoleResourceLinked = false
                           tRolePermissions.tcMenuExec           = 'B.':U + string(viFcCount2)
                           tRolePermissions.tlChanged            = false.
                end.
            end.
            else
            if vcCompNameT <> substring(tqResourceInfo.tcResourceURI,1,index(tqResourceInfo.tcResourceURI,'.':U) - 1,"CHARACTER":U)
            then do:
                assign viFcCount1 = 0
                       viFcCount2 = viFcCount2 + 1
                       vcCompNameT = substring(tqResourceInfo.tcResourceURI,1,index(tqResourceInfo.tcResourceURI,'.':U) - 1,"CHARACTER":U).

                create tRolePermissions.
                assign tRolePermissions.tcLabel              = substring(vcCompNameT,r-index(vcCompNameT,':':U) + 1, -1, "CHARACTER":U) /* Should be translatable ? */                       
                       tRolePermissions.tcMenuNbr            = 'B':U
                       tRolePermissions.tcResourceURI        = ''
                       tRolePermissions.tiMenuSelect         = viFcCount2
                       tRolePermissions.tiResource_ID        = 0
                       tRolePermissions.tiRole_ID            = tRole.Role_ID
                       tRolePermissions.tlRoleResourceLinked = false
                       tRolePermissions.tcMenuExec           = 'B.':U + string(viFcCount2)
                       tRolePermissions.tlChanged            = false.
            end.
            assign viFcCount1 = viFcCount1 + 1.
           
            create tRolePermissions.
            assign tRolePermissions.tcLabel              = tqResourceInfo.tcResourceLabel
                   tRolePermissions.tcMenuNbr            = 'B.':U + string(viFcCount2)                                                
                   tRolePermissions.tcResourceURI        = tqResourceInfo.tcResourceURI
                   tRolePermissions.tiMenuSelect         = viFcCount1                                                   
                   tRolePermissions.tiResource_ID        = tqResourceInfo.tiResource_ID
                   tRolePermissions.tiRole_ID            = tRole.Role_ID
                   tRolePermissions.tlRoleResourceLinked = vlLinked
                   tRolePermissions.tcMenuExec           = 'B.':U + string(viFcCount2) + ".":U + string(viFcCount1)                                                 
                   tRolePermissions.tlChanged            = false.
    
            /* Place the URI between brackets */                                                        
            assign tRolePermissions.tcLabel = tRolePermissions.tcLabel + ' (' + 
                                              tqResourceInfo.tcResourceURI + ')'.

            if tqResourceInfo.tcResourceType = {&RESOURCE-TYPE-ACTIVITY}
            then assign tRolePermissions.tcLabel = tRolePermissions.tcLabel + ' [' +
                                                   trim (#T-6'Entity':255(56602)T-6#) + ']'.

            else 
            if tqResourceInfo.tcResourceType = {&RESOURCE-TYPE-MENU}
            then assign tRolePermissions.tcLabel = tRolePermissions.tcLabel + ' [' + 
                                                   trim (#T-8'Domain':20(60834)T-8#) + ']'.
        end. /* if not vlMenuLinked */
    end. /* for each tqResourceInfo */

    /* Add the Memu Folders and assign the tlRoleResourceLinked  */
    define buffer btRolePermissions for tRolePermissions.
    for each tqMenuDetailForMenuFolders by tqMenuDetailForMenuFolders.tiLevel descending :

        /* skip the upper root level */
        if  tqMenuDetailForMenuFolders.tcmnd_nbr = ''
        then next.
    
        /*take appshell menu structure*/
        if tqMenuDetailForMenuFolders.tcmnd_nbr = "0"
        then next.

        /* In case no children found, skip it */
        if not can-find (first btRolePermissions where
                               btRolePermissions.tcMenuNbr = tqMenuDetailForMenuFolders.tcmnd_exec)
        then next.
        
        create tRolePermissions.
        assign tRolePermissions.tcLabel              = (if tqMenuDetailForMenuFolders.tcmnt_label <> ? and 
                                                           tqMenuDetailForMenuFolders.tcmnt_label <> '' 
                                                        then tqMenuDetailForMenuFolders.tcmnt_label 
                                                        else tqMenuDetailForMenuFolders.tcmnd_label)
               tRolePermissions.tcMenuNbr            = tqMenuDetailForMenuFolders.tcmnd_nbr
               tRolePermissions.tcResourceURI        = ''
               tRolePermissions.tiMenuSelect         = tqMenuDetailForMenuFolders.timnd_select
               tRolePermissions.tiResource_ID        = 0
               tRolePermissions.tiRole_ID            = tRole.Role_ID
               tRolePermissions.tlRoleResourceLinked = 
                            not can-find (first btRolePermissions where
                                                btRolePermissions.tcMenuNbr            = tqMenuDetailForMenuFolders.tcmnd_exec and
                                                btRolePermissions.tlRoleResourceLinked = false) 
               tRolePermissions.tcMenuExec           = tqMenuDetailForMenuFolders.tcmnd_exec
               tRolePermissions.tlChanged  = false.
    
        /* Place the menu structure between brackets */                                                        
        if tRolePermissions.tcMenuExec <> 'A':U and not tRolePermissions.tcMenuExec begins 'A.':U 
        then  assign tRolePermissions.tcLabel = 
                tRolePermissions.tcLabel + ' (':U +
                   (if tRolePermissions.tcMenuNbr = 'A':U or tRolePermissions.tcMenuNbr begins 'A.':U 
                    then '':U 
                    else (trim (tRolePermissions.tcMenuNbr) + '.':U)) + 
               trim (string (tRolePermissions.tiMenuSelect)) + 
               ')':U.

    end. /*for each tqMenuDetailForMenuFolders:*/

    /* Assign the tlRoleResourceLinked to the Not-On-Menu Folders */
    for each tRolePermissions where
             tRolePermissions.tcMenuNbr  = 'B' :

         assign tRolePermissions.tlRoleResourceLinked = 
                            not can-find (first btRolePermissions where
                                                btRolePermissions.tcMenuNbr            = tRolePermissions.tcMenuExec and
                                                btRolePermissions.tlRoleResourceLinked = false). 

    end. /* for each tRolePermissions */

end. /*for each tRole:*/

if oiReturnStatus = -98
then assign oiReturnStatus = 0.