dev-fastapi
Иван Маслов 2 years ago
parent dd420cc3d2
commit d58008833b

@ -36,19 +36,20 @@ import asyncio
# v 1.2.0 Functionallity # v 1.2.0 Functionallity
# # # # # # # # # # # # # # # # # # # # # # # #
# Generate JS when page init # Generate JS when page init
def HiddenJSInitGenerate(inRequest, inGSettings): def HiddenJSInitGenerate(inAuthTokenStr):
dUAC = inRequest.UACClientCheck # Alias. inGSettings = __Orchestrator__.GSettingsGet()
dUAC = lambda inKeyList: __Orchestrator__.WebUserUACCheck(inAuthTokenStr=inAuthTokenStr, inKeyList=inKeyList)
lUACCPTemplateKeyList=["pyOpenRPADict","CPKeyDict"] lUACCPTemplateKeyList=["pyOpenRPADict","CPKeyDict"]
lL = inGSettings["Logger"] # Alias for logger lL = inGSettings["Logger"] # Alias for logger
lJSInitResultStr = "" lJSInitResultStr = ""
lRenderFunctionsRobotDict = inGSettings["ServerDict"]["ControlPanelDict"] lRenderFunctionsRobotDict = inGSettings["ServerDict"]["ControlPanelDict"]
for lItemKeyStr in lRenderFunctionsRobotDict: for lItemKeyStr in lRenderFunctionsRobotDict:
lItemDict = lRenderFunctionsRobotDict[lItemKeyStr] lItemDict = lRenderFunctionsRobotDict[lItemKeyStr]
lUACBool = dUAC(inRoleKeyList=lUACCPTemplateKeyList+[lItemKeyStr]) # Check if render function is applicable User Access Rights (UAC) lUACBool = dUAC(inKeyList=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 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 if lUACBool: # Run function if UAC is TRUE
# JSONGeneratorDef # JSONGeneratorDef
lJSInitResultStr = lJSInitResultStr + ";" + lItemDict.OnInitJSStr(inRequest=inRequest) lJSInitResultStr = lJSInitResultStr + ";" + lItemDict.OnInitJSStr(inAuthTokenStr=inAuthTokenStr)
return lJSInitResultStr return lJSInitResultStr
# Generate CP HTML + JSON # Generate CP HTML + JSON
@ -135,7 +136,7 @@ def HiddenAgentDictGenerate(inAuthTokenStr):
@app.post("/orpa/client/server-data",response_class=JSONResponse, tags=["Client"]) @app.post("/orpa/client/server-data",response_class=JSONResponse, tags=["Client"])
#{"Method": "POST", "URL": "/orpa/client/server-data", "MatchType": "Equal","ResponseDefRequestGlobal": pyOpenRPA_ServerData, "ResponseContentType": "application/json"}, #{"Method": "POST", "URL": "/orpa/client/server-data", "MatchType": "Equal","ResponseDefRequestGlobal": pyOpenRPA_ServerData, "ResponseContentType": "application/json"},
async def pyOpenRPA_ServerData(inRequest: Request, inAuthTokenStr:str=Depends(__Orchestrator__.WebAuthDefGet())): async def pyOpenRPA_ServerData(inRequest: Request, inAuthTokenStr:str=Depends(IdentifyAuthorize)):
inGSettings = __Orchestrator__.GSettingsGet() inGSettings = __Orchestrator__.GSettingsGet()
# Extract the hash value from request # Extract the hash value from request
lValueStr = await inRequest.body() lValueStr = await inRequest.body()
@ -164,13 +165,13 @@ async def pyOpenRPA_ServerData(inRequest: Request, inAuthTokenStr:str=Depends(__
# GET # GET
# /pyOpenRPA/ServerJSInit return JavaScript to init on page # /pyOpenRPA/ServerJSInit return JavaScript to init on page
def pyOpenRPA_ServerJSInit(inRequest,inGSettings): @app.get("/orpa/client/server-js-init",response_class=PlainTextResponse, tags=["Client"])
lResultStr = HiddenJSInitGenerate(inRequest=inRequest, inGSettings=inGSettings) def pyOpenRPA_ServerJSInit(inRequest: Request, inAuthTokenStr:str=Depends(IdentifyAuthorize)):
inResponseDict = inRequest.OpenRPAResponseDict lResultStr = HiddenJSInitGenerate(inAuthTokenStr=inAuthTokenStr)
if lResultStr is None: if lResultStr is None:
lResultStr = "" lResultStr = ""
# Write content as utf-8 data # Write content as utf-8 data
inResponseDict["Body"] = bytes(lResultStr, "utf8") return lResultStr
#v1.2.0 Send data container to the client from the server #v1.2.0 Send data container to the client from the server
# /pyOpenRPA/ServerLog return {"HashStr" , "ServerLogList": ["row 1", "row 2"]} # /pyOpenRPA/ServerLog return {"HashStr" , "ServerLogList": ["row 1", "row 2"]}
@ -191,7 +192,7 @@ async def pyOpenRPA_ServerLog(inRequest: Request, inAuthTokenStr:str=Depends(Ide
if lValueStr!=lServerLogListHashStr and lServerLogListHashStr!= "" and lServerLogListHashStr!= None: # Case if Hash is not equal Fix because None can be obtained without JSON decode if lValueStr!=lServerLogListHashStr and lServerLogListHashStr!= "" and lServerLogListHashStr!= None: # Case if Hash is not equal Fix because None can be obtained without JSON decode
lFlagDoGenerateBool = False lFlagDoGenerateBool = False
else: # Case Hashes are equal else: # Case Hashes are equal
asyncio.sleep(inGSDict["Client"]["DumpLogListRefreshIntervalSecFloat"]) await asyncio.sleep(inGSDict["Client"]["DumpLogListRefreshIntervalSecFloat"])
# Return the result if Hash is changed # Return the result if Hash is changed
lResult = {"HashStr": lServerLogListHashStr, "ServerLogList": lServerLogList} lResult = {"HashStr": lServerLogListHashStr, "ServerLogList": lServerLogList}
return lResult return lResult
@ -516,7 +517,7 @@ def SettingsUpdate():
{"Method": "POST", "URL": "/orpa/client/user-role-hierarchy-get", "MatchType": "Equal","ResponseDefRequestGlobal": BackwardCompatibility.v1_2_0_UserRoleHierarchyGet, "ResponseContentType": "application/json"}, {"Method": "POST", "URL": "/orpa/client/user-role-hierarchy-get", "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/...) # New way of the v.1.2.0 functionallity (all defs by the URL from /pyOpenRPA/...)
#{"Method": "POST", "URL": "/orpa/client/server-data", "MatchType": "Equal","ResponseDefRequestGlobal": pyOpenRPA_ServerData, "ResponseContentType": "application/json"}, #{"Method": "POST", "URL": "/orpa/client/server-data", "MatchType": "Equal","ResponseDefRequestGlobal": pyOpenRPA_ServerData, "ResponseContentType": "application/json"},
{"Method": "GET", "URL": "/orpa/client/server-js-init", "MatchType": "Equal","ResponseDefRequestGlobal": pyOpenRPA_ServerJSInit, "ResponseContentType": "application/javascript"}, #{"Method": "GET", "URL": "/orpa/client/server-js-init", "MatchType": "Equal","ResponseDefRequestGlobal": pyOpenRPA_ServerJSInit, "ResponseContentType": "application/javascript"},
#{"Method": "POST", "URL": "/orpa/client/server-log", "MatchType": "Equal","ResponseDefRequestGlobal": pyOpenRPA_ServerLog, "ResponseContentType": "application/json"}, #{"Method": "POST", "URL": "/orpa/client/server-log", "MatchType": "Equal","ResponseDefRequestGlobal": pyOpenRPA_ServerLog, "ResponseContentType": "application/json"},
#{"Method": "GET", "URL": "/orpa/client/screenshot-get", "MatchType": "Equal", "ResponseDefRequestGlobal": pyOpenRPA_Screenshot, "ResponseContentType": "image/png"}, #{"Method": "GET", "URL": "/orpa/client/screenshot-get", "MatchType": "Equal", "ResponseDefRequestGlobal": pyOpenRPA_Screenshot, "ResponseContentType": "image/png"},
# API # API

@ -1118,6 +1118,7 @@ def WebUserUACHierarchyGet(inAuthTokenStr: str=None) -> dict:
:type inAuthTokenStr: str, опционально :type inAuthTokenStr: str, опционально
:return: UAC словарь доступа или {}, что означает полный доступ :return: UAC словарь доступа или {}, что означает полный доступ
""" """
if inAuthTokenStr is None: return {}
lDomainUpperStr = WebUserDomainGet(inAuthTokenStr=inAuthTokenStr).upper() lDomainUpperStr = WebUserDomainGet(inAuthTokenStr=inAuthTokenStr).upper()
lUserUpperStr = WebUserLoginGet(inAuthTokenStr=inAuthTokenStr).upper() lUserUpperStr = WebUserLoginGet(inAuthTokenStr=inAuthTokenStr).upper()
if lUserUpperStr is None: return {} if lUserUpperStr is None: return {}

Loading…
Cancel
Save