project BLF > class Business Component > method ApiActivitiesAreAllowed
Description
check if a user has security rights for a list of activities
Parameters
icUserLogin | input | character | |
icCompanyCode | input | character | |
icActivityCodes | input | character | comma separated list |
ocAllowed | output | character | comma separated list of true or false according to the input activity codes |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/business.p)
if icActivityCodes = ""
or icActivityCodes = ?
then return.
if oiReturnStatus = 0
then oiReturnStatus = -98.
if icUserLogin = ""
or icUserLogin = ?
then icUserLogin = vcUserLogin.
if icUserLogin = vcUserLogin
then viUserId = viUsrId.
else do:
<Q-4 run UserPrim (all) (Read) (NoCache)
(input ?, (UsrId)
input icUserLogin, (UsrLogin)
output dataset tqUserPrim) in BUser >
find first tqUserPrim where
tqUserPrim.tcUsrLogin = icUserLogin no-error.
if not available tqUserPrim
then do:
assign vcMessage = trim(#T-10'Unknown User':40(467)T-10#)
oiReturnStatus = -1.
<M-11 run SetMessage
(input vcMessage (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-299':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in database>
return.
end.
viUserId = tqUserPrim.tiUsr_ID.
end.
if icCompanyCode = ""
or icCompanyCode = ?
then assign icCompanyCode = vcCompanyCode.
if icCompanyCode = vcCompanyCode
then assign viCyId = viCompanyId.
else do:
<Q-5 run CompanyPrim (all) (Read) (NoCache)
(input ?, (LookupCompanyId)
input icCompanyCode, (CompanyCode)
output dataset tqCompanyPrim) in BCompany >
find first tqCompanyPrim where
tqCompanyPrim.tcCompanyCode = icCompanyCode no-error.
if available tqCompanyPrim
then assign viCyID = tqCompanyPrim.tiCompany_ID.
else do:
assign vcMessage = trim(#T-13'Unknown Company':40(8912)T-13#)
oiReturnStatus = -1.
<M-12 run SetMessage
(input vcMessage (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-300':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in database>
return.
end.
end.
/*get resources/activities for the current component*/
<Q-6 run BusComponentForResources (all) (Read) (NoCache)
(input vcFcComponentName, (BusComponentCode)
output dataset tqBusComponentForResources) in BBusinessComponent >
<Q-8 run RoleResourceByResUserComp
(Start) in BRole >
do viFcCount1 = 1 to num-entries(icActivityCodes):
assign vcActCode = entry(viFcCount1,icActivityCodes).
find first tqBusComponentForResources where
tqBusComponentForResources.tcBusComponentCode = vcFcComponentName and
tqBusComponentForResources.tcBusActivityCode = vcActCode
no-error.
if not available tqBusComponentForResources
then do:
/*activity does not exist*/
assign ocAllowed = ocAllowed + ',false'.
next.
end.
if tqBusComponentForResources.tiResource_ID = 0 or tqBusComponentForResources.tiResource_ID = ?
then do:
/*activity does not exist*/
assign ocAllowed = ocAllowed + ',false'.
next.
end.
/*look if the user company combination has access to this resource*/
<Q-7 run RoleResourceByResUserComp (all) (Read) (NoCache)
(input tqBusComponentForResources.tiResource_ID, (ResourceId)
input viCyID, (CompanyId)
input viUserId, (UserId)
output dataset tqRoleResourceByResUserComp) in BRole >
find first tqRoleResourceByResUserComp no-error.
if available tqRoleResourceByResUserComp
then do:
/*allowed*/
assign ocAllowed = ocAllowed + ',true'.
next.
end.
else do:
/*not allowed*/
assign ocAllowed = ocAllowed + ',false'.
next.
end.
end.
<Q-9 run RoleResourceByResUserComp
(Stop) in BRole >
ocAllowed = trim(ocAllowed,',').
if oiReturnStatus = -98
then oiReturnStatus = 0.
Sample code: how to call this method through RPCRequestService (QXtend Inbound)
define temp-table ttContext no-undo
field propertyQualifier as character
field propertyName as character
field propertyValue as character
index entityContext is primary unique
propertyQualifier
propertyName
index propertyQualifier
propertyQualifier.
define dataset dsContext for ttContext.
define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.
/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
ttContext.propertyValue = "business".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiActivitiesAreAllowed".
create ttContext.
assign ttContext.propertyName = "applicationId"
ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
ttContext.propertyValue = "".
/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/business.apiactivitiesareallowed.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icUserLogin = <parameter value>
vhParameter::icCompanyCode = <parameter value>
vhParameter::icActivityCodes = <parameter value>.
/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").
if not vhServer:connected()
then do:
message "Could not connect AppServer" view-as alert-box error title "Error".
return.
end.
/* Run */
assign vhContextDS = dataset dsContext:handle.
run program/rpcrequestservice.p on vhServer
(input-output dataset-handle vhContextDS by-reference,
output dataset-handle vhExceptionDS,
input dataset-handle vhInputDS by-reference,
input-output dataset-handle vhInputOutputDS by-reference,
output dataset-handle vhOutputDS).
/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).
if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).
/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.
if valid-handle(vhInputDS)
then delete object vhInputDS.
if valid-handle(vhOutputDS)
then delete object vhOutputDS.
if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.