@ -17,7 +17,40 @@ from . import SettingsTemplate
# # # # # # # # # # # #
# v 1.2.0 Functionallity
# # # # # # # # # # # #
# Generate CP
# Generate JS when page init
def HiddenJSInitGenerate ( inRequest , inGSettings ) :
dUAC = inRequest . UACClientCheck # Alias.
lUACCPTemplateKeyList = [ " pyOpenRPADict " , " CPKeyDict " ]
lL = inGSettings [ " Logger " ] # Alias for logger
lJSInitResultStr = " "
lRenderFunctionsRobotDict = inGSettings [ " CPDict " ]
for lItemKeyStr in lRenderFunctionsRobotDict :
lItemDict = lRenderFunctionsRobotDict [ lItemKeyStr ]
lJSInitGeneratorDef = lItemDict . get ( " JSInitGeneratorDef " , None )
lUACBool = dUAC ( inRoleKeyList = lUACCPTemplateKeyList + [ lItemKeyStr ] ) # Check if render function is applicable User Access Rights (UAC)
if lItemKeyStr == " VersionCheck " : lUACBool = True # For backward compatibility for the old fron version which not reload page when new orch version is comming
if lUACBool : # Run function if UAC is TRUE
# JSONGeneratorDef
if lJSInitGeneratorDef is not None : # Call def (inRequest, inGSettings) or def (inGSettings)
lJSResult = None
lDEFSignature = signature ( lJSInitGeneratorDef ) # Get signature of the def
lDEFARGLen = len ( lDEFSignature . parameters . keys ( ) ) # get count of the def args
try :
if lDEFARGLen == 1 : # def (inGSettings)
lJSResult = lJSInitGeneratorDef ( inGSettings )
elif lDEFARGLen == 2 : # def (inRequest, inGSettings)
lJSResult = lJSInitGeneratorDef ( inRequest , inGSettings )
elif lDEFARGLen == 0 : # def ()
lJSResult = lJSInitGeneratorDef ( )
if type ( lJSResult ) is str :
lJSInitResultStr + = " ; " + lJSResult # Add delimiter to some cases
else :
if lL : lL . warning ( f " JSInitGenerator return bad type: { str ( type ( lJSResult ) ) } , CP Key { lItemKeyStr } " )
except Exception as e :
if lL : lL . exception ( f " Error in control panel JSInitGeneratorDef. CP Key { lItemKeyStr } . Exception are below " )
return lJSInitResultStr
# Generate CP HTML + JSON
# Return {"Key":{"",""}}
def HiddenCPDictGenerate ( inRequest , inGSettings ) :
dUAC = inRequest . UACClientCheck # Alias.
@ -25,37 +58,61 @@ def HiddenCPDictGenerate(inRequest, inGSettings):
lL = inGSettings [ " Logger " ] # Alias for logger
# Create result JSON
lCPDict = { }
lRenderFunctionsRobotList = inGSettings [ " ControlPanelDict " ] [ " RobotList " ]
for lItem in lRenderFunctionsRobotList :
lUACBool = dUAC ( inRoleKeyList = lUACCPTemplateKeyList + [ lItem [ " KeyStr " ] ] ) # Check if render function is applicable User Access Rights (UAC)
if lItem [ " KeyStr " ] == " VersionCheck " : lUACBool = True # For backward compatibility for the old fron version which not reload page when new orch version is comming
#if inGSettings["Server"]["AccessUsers"]["FlagCredentialsAsk"] is True:
# lUserRights = inGSettings["Server"]["AccessUsers"]["RuleDomainUserDict"][(inRequest.OpenRPA["Domain"].upper(), inRequest.OpenRPA["User"].upper())]
# if len(lUserRights["ControlPanelKeyAllowedList"]) > 0 and lItem["KeyStr"] not in lUserRights["ControlPanelKeyAllowedList"]:
# lUACBool = False # UAC Check is not passed - False for user
lRenderFunctionsRobotDict = inGSettings [ " CPDict " ]
for lItemKeyStr in lRenderFunctionsRobotDict :
lItemDict = lRenderFunctionsRobotDict [ lItemKeyStr ]
lItemHTMLRenderDef = lItemDict . get ( " HTMLRenderDef " , None )
lItemJSONGeneratorDef = lItemDict . get ( " JSONGeneratorDef " , None )
lUACBool = dUAC ( inRoleKeyList = lUACCPTemplateKeyList + [ lItemKeyStr ] ) # Check if render function is applicable User Access Rights (UAC)
if lItemKeyStr == " VersionCheck " : lUACBool = True # For backward compatibility for the old fron version which not reload page when new orch version is comming
if lUACBool : # Run function if UAC is TRUE
# Выполнить вызов и записать результат
# Call def (inRequest, inGSettings) or def (inGSettings)
lItemResultDict = None
lDEFSignature = signature ( lItem [ " RenderFunction " ] ) # Get signature of the def
lCPItemDict = { " HTMLStr " : None , " JSONDict " : None }
# HTMLRenderDef
if lItemHTMLRenderDef is not None : # Call def (inRequest, inGSettings) or def (inGSettings)
lHTMLResult = None
lDEFSignature = signature ( lItemHTMLRenderDef ) # Get signature of the def
lDEFARGLen = len ( lDEFSignature . parameters . keys ( ) ) # get count of the def args
try :
if lDEFARGLen == 1 : # def (inGSettings)
lItemResultDict = lItem [ " RenderFunction " ] ( inGSettings )
lHTMLResult = lItemHTMLRenderDef ( inGSettings )
elif lDEFARGLen == 2 : # def (inRequest, inGSettings)
lItemResultDict = lItem [ " RenderFunction " ] ( inRequest , inGSettings )
lHTMLResult = lItemHTMLRenderDef ( inRequest , inGSettings )
elif lDEFARGLen == 0 : # def ()
lItemResultDict = lItem [ " RenderFunction " ] ( )
lHTMLResult = lItemHTMLRenderDef ( )
# RunFunction
# lResultJSON["RenderRobotList"].append(lItemResultDict)
# Backward compatibility up to 1.2.0 - call HTML generator if result has no "HTMLStr"
if " HTMLStr " in lItemResultDict or " DataDict " in lItemResultDict :
lCPDict [ lItem [ " KeyStr " ] ] = lItemResultDict # new version
if type ( lHTMLResult ) is str :
lCPItemDict [ " HTMLStr " ] = lHTMLResult
elif " HTMLStr " in lHTMLResult or " JSONDict " in lHTMLResult :
lCPItemDict = lHTMLResult # new version
else :
# Call backward compatibility HTML generator
lCPDict [ lItem [ " KeyStr " ] ] = { " HTMLStr " : Basic . HTMLControlPanelBC ( inCPDict = lItemResultDict ) , " DataDict " : { } }
lCPItemDict [ " HTMLStr " ] = Basic . HTMLControlPanelBC ( inCPDict = lHTMLResult )
except Exception as e :
if lL : lL . exception ( f " Error in control panel. CP item { lItem } . Exception is below " )
if lL : lL . exception ( f " Error in control panel HTMLRenderDef. CP Key { lItemKeyStr } . Exception are below " )
# JSONGeneratorDef
if lItemJSONGeneratorDef is not None : # Call def (inRequest, inGSettings) or def (inGSettings)
lJSONResult = None
lDEFSignature = signature ( lItemJSONGeneratorDef ) # Get signature of the def
lDEFARGLen = len ( lDEFSignature . parameters . keys ( ) ) # get count of the def args
try :
if lDEFARGLen == 1 : # def (inGSettings)
lJSONResult = lItemJSONGeneratorDef ( inGSettings )
elif lDEFARGLen == 2 : # def (inRequest, inGSettings)
lJSONResult = lItemJSONGeneratorDef ( inRequest , inGSettings )
elif lDEFARGLen == 0 : # def ()
lJSONResult = lItemJSONGeneratorDef ( )
# RunFunction
# Backward compatibility up to 1.2.0 - call HTML generator if result has no "HTMLStr"
lType = type ( lJSONResult )
if lType is str or lJSONResult is None or lType is int or lType is list or lType is dict or lType is bool or lType is float :
lCPItemDict [ " JSONDict " ] = lJSONResult
else :
if lL : lL . warning ( f " JSONGenerator return bad type: { str ( type ( lJSONResult ) ) } , CP Key { lItemKeyStr } " )
except Exception as e :
if lL : lL . exception ( f " Error in control panel JSONGeneratorDef. CP Key { lItemKeyStr } . Exception are below " )
# Insert CPItemDict in result CPDict
lCPDict [ lItemKeyStr ] = lCPItemDict
return lCPDict
# Return {"Key":{"",""}}
@ -141,6 +198,14 @@ def pyOpenRPA_ServerData(inRequest,inGSettings):
inResponseDict [ " Body " ] = bytes ( message , " utf8 " )
return lResult
# GET
# /pyOpenRPA/ServerJSInit return JavaScript to init on page
def pyOpenRPA_ServerJSInit ( inRequest , inGSettings ) :
lResultStr = HiddenJSInitGenerate ( inRequest = inRequest , inGSettings = inGSettings )
inResponseDict = inRequest . OpenRPAResponseDict
# Write content as utf-8 data
inResponseDict [ " Body " ] = bytes ( lResultStr , " utf8 " )
#v1.2.0 Send data container to the client from the server
# /pyOpenRPA/ServerLog return {"HashStr" , "ServerLogList": ["row 1", "row 2"]}
# Client: mGlobal.pyOpenRPA.ServerLogListHashStr
@ -313,6 +378,7 @@ def SettingsUpdate(inGlobalConfiguration):
{ " Method " : " POST " , " URL " : " /Orchestrator/UserRoleHierarchyGet " , " MatchType " : " Equal " , " ResponseDefRequestGlobal " : BackwardCompatibility . v1_2_0_UserRoleHierarchyGet , " ResponseContentType " : " application/json " } ,
# New way of the v.1.2.0 functionallity (all defs by the URL from /pyOpenRPA/...)
{ " Method " : " POST " , " URL " : " /pyOpenRPA/ServerData " , " MatchType " : " Equal " , " ResponseDefRequestGlobal " : pyOpenRPA_ServerData , " ResponseContentType " : " application/json " } ,
{ " Method " : " GET " , " URL " : " /pyOpenRPA/ServerJSInit " , " MatchType " : " Equal " , " ResponseDefRequestGlobal " : pyOpenRPA_ServerJSInit , " ResponseContentType " : " application/javascript " } ,
{ " Method " : " POST " , " URL " : " /pyOpenRPA/ServerLog " , " MatchType " : " Equal " , " ResponseDefRequestGlobal " : pyOpenRPA_ServerLog , " ResponseContentType " : " application/json " } ,
{ " Method " : " GET " , " URL " : " /pyOpenRPA/Screenshot " , " MatchType " : " BeginWith " , " ResponseDefRequestGlobal " : pyOpenRPA_Screenshot , " ResponseContentType " : " image/png " } ,
{ " Method " : " POST " , " URL " : " /pyOpenRPA/Processor " , " MatchType " : " Equal " , " ResponseDefRequestGlobal " : pyOpenRPA_Processor , " ResponseContentType " : " application/json " } ,