project QadFinancials > class BRole > method AddGenCodeGroupToRoles

Description

When a resource is created for a new generalized code group, this resource will be added to any role that already gives access to all existing resources for generalized code groups.


Parameters


icResourceIDsinputcharacter
icResourceURIsinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BResource.AdditionalUpdates


program code (program1/brole.p)

if lookup ("urn:gencodegroup:APP",icResourceURIs) > 0
then do:
    /* ================================================================= */
    /* Add this group to ALL roles.                                      */
    /* ================================================================= */
    <M-53 run DataLoad
       (input  '' (icRowids), 
        input  '' (icPkeys), 
        input  '' (icObjectIds), 
        input  '' (icFreeform), 
        input  yes (ilKeepPrevious), 
        output viFcReturnSuper (oiReturnStatus)) in BRole>

    for each tRole on error undo, throw:
    
        if not can-find (first tRoleResource where
                               tRoleResource.Role_ID     = tRole.Role_ID and
                               tRoleResource.Resource_ID = integer (entry(lookup("urn:gencodegroup:APP",icResourceURIs),icResourceIDs)))
        then do:
            <M-34 run AddDetailLine
               (input  'RoleResource' (icTable), 
                input  tRole.tc_Rowid (icParentRowid), 
                output viFcReturnSuper (oiReturnStatus)) in BRole>
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then return.
    
            assign tRoleResource.Role_ID               = tRole.Role_ID
                   tRoleResource.Resource_ID           = integer (entry(lookup("urn:gencodegroup:APP",icResourceURIs),icResourceIDs))
                   tRoleResource.tcResourceURI         = ""
                   tRoleResource.RoleResourceIsDefault = no.
        end.
    end.
end.

if icResourceURIs <> "urn:gencodegroup:APP"
then do:
    /* ================================================================= */
    /* Lookup all roles that give access to at least one gencode group.  */
    /* ================================================================= */
    <Q-43 run ResourceInfo (all) (Read) (NoCache)
       (input 'urn:gencodegroup:*', (URImatches)
        output dataset tqResourceInfo) in BResource>
    
    find first tqResourceInfo where tqResourceInfo.tcResourceURI <> "urn:gencodegroup:APP" no-error.
    if available tqResourceInfo
    then do:
        <Q-20 run RolesForResource (all) (Read) (NoCache)
           (input tqResourceInfo.tiResource_ID, (ResourceID)
            input '', (ResourceURI)
            input 0, (RoleID)
            output dataset tqRolesForResource) in BResource>
        
        if can-find (first tqRolesForResource)
        then do:
            empty temp-table tRolesForExport.
            for each tqRolesForResource on error undo, throw:
                create tRolesForExport.
                assign tRolesForExport.tiRole_ID = tqRolesForResource.tiRole_ID.
            end.
            
            ROLE: for each tRolesForExport on error undo, throw:
            
                /* ================================================================= */
                /* Skip this role if a gencode group exists that is not included in  */
                /* the role permissions.                                             */
                /* ================================================================= */
                for each tqResourceInfo on error undo, throw:
                    <Q-39 run RolesForResource (all) (Read) (NoCache)
                       (input tqResourceInfo.tiResource_ID, (ResourceID)
                        input '', (ResourceURI)
                        input tRolesForExport.tiRole_ID, (RoleID)
                        output dataset tqRolesForResource) in BResource>
                    if not can-find (first tqRolesForResource)
                    then next ROLE.
                end.
                
                /* ================================================================= */
                /* Add the gencode groups in permissions data.                       */
                /* ================================================================= */
                if lookup ("urn:gencodegroup:APP",icResourceURIs) = 0
                then do:
                    <M-67 run DataLoad
                       (input  '' (icRowids), 
                        input  string(trolesforExport.tiRole_ID) (icPkeys), 
                        input  '' (icObjectIds), 
                        input  '' (icFreeform), 
                        input  yes (ilKeepPrevious), 
                        output viFcReturnSuper (oiReturnStatus)) in BRole>
                    if viFcReturnSuper <> 0
                    then oiReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0
                    then return.
                end.
                
                find first tRole where tRole.Role_ID = trolesforExport.tiRole_ID.
                
                do viRidis = 1 to num-entries(icResourceIDs):
                
                    if not can-find (first tRoleResource where
                                           tRoleResource.Role_ID     = tRole.Role_ID and
                                           tRoleResource.Resource_ID = integer (entry(viRidis,icResourceIDs)))
                    then do:
                        <M-89 run AddDetailLine
                           (input  'RoleResource' (icTable), 
                            input  tRole.tc_Rowid (icParentRowid), 
                            output viFcReturnSuper (oiReturnStatus)) in BRole>
                        if viFcReturnSuper <> 0
                        then oiReturnStatus = viFcReturnSuper.
                        if viFcReturnSuper < 0
                        then return.
                
                        assign tRoleResource.Role_ID               = tRole.Role_ID
                               tRoleResource.Resource_ID           = integer (entry(viRidis,icResourceIDs))
                               tRoleResource.tcResourceURI         = ""
                               tRoleResource.RoleResourceIsDefault = no.
                    end.
                end.
            end.
        end.
    end.
end.

<M-94 run ValidateBC  (output viFcReturnSuper (oiReturnStatus)) in BRole>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

<M-86 run AdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BRole>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

<M-69 run DataSave  (output viFcReturnSuper (oiReturnStatus)) in BRole>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.


finally:
    empty temp-table tRolesForExport.
end finally.