diff --git a/common/workunit/workunit.cpp b/common/workunit/workunit.cpp index bbe0159aede..f5ab340d4ae 100644 --- a/common/workunit/workunit.cpp +++ b/common/workunit/workunit.cpp @@ -5304,7 +5304,7 @@ bool CWorkUnitFactory::deleteWorkUnit(const char * wuid, ISecManager *secmgr, IS return deleteWorkUnitEx(wuid, false, secmgr, secuser); } -IConstWorkUnit* CWorkUnitFactory::openWorkUnit(const char *wuid, ISecManager *secmgr, ISecUser *secuser) +IConstWorkUnit* CWorkUnitFactory::openWorkUnit(const char *wuid, ISecManager *secmgr, ISecUser *secuser, bool expected) { StringBuffer wuidStr(wuid); wuidStr.trim(); @@ -5330,7 +5330,7 @@ IConstWorkUnit* CWorkUnitFactory::openWorkUnit(const char *wuid, ISecManager *se } else { - if (workUnitTraceLevel > 0) + if (expected && workUnitTraceLevel > 0) IERRLOG("openWorkUnit %s not found", wuidStr.str()); return NULL; } @@ -6722,11 +6722,11 @@ class CSecureWorkUnitFactory : implements IWorkUnitFactory, public CInterface if (!secUser) secUser = defaultSecUser.get(); return baseFactory->deleteWorkUnitEx(wuid, throwException, secMgr, secUser); } - virtual IConstWorkUnit* openWorkUnit(const char *wuid, ISecManager *secMgr, ISecUser *secUser) + virtual IConstWorkUnit* openWorkUnit(const char *wuid, ISecManager *secMgr, ISecUser *secUser, bool expected) { if (!secMgr) secMgr = defaultSecMgr.get(); if (!secUser) secUser = defaultSecUser.get(); - return baseFactory->openWorkUnit(wuid, secMgr, secUser); + return baseFactory->openWorkUnit(wuid, secMgr, secUser, expected); } virtual IWorkUnit* updateWorkUnit(const char *wuid, ISecManager *secMgr, ISecUser *secUser) { @@ -6888,7 +6888,7 @@ class CUnexpectedWorkUnitFactory : implements IWorkUnitFactory, public CInterfac { throwUnexpected(); } - virtual IConstWorkUnit* openWorkUnit(const char *wuid, ISecManager *secMgr, ISecUser *secUser) override + virtual IConstWorkUnit* openWorkUnit(const char *wuid, ISecManager *secMgr, ISecUser *secUser, bool expected) override { throwUnexpected(); } diff --git a/common/workunit/workunit.hpp b/common/workunit/workunit.hpp index 0ae02fc3e6f..debaf1321a6 100644 --- a/common/workunit/workunit.hpp +++ b/common/workunit/workunit.hpp @@ -1560,7 +1560,7 @@ interface IWorkUnitFactory : extends IPluggableFactory const char *importDir, const char *app, const char *user, ISecManager *secMgr, ISecUser *secUser) = 0; virtual bool deleteWorkUnit(const char *wuid, ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0; virtual bool deleteWorkUnitEx(const char *wuid, bool throwException, ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0; - virtual IConstWorkUnit * openWorkUnit(const char *wuid, ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0; + virtual IConstWorkUnit * openWorkUnit(const char *wuid, ISecManager *secmgr = NULL, ISecUser *secuser = NULL, bool expected = true) = 0; virtual IConstWorkUnitIterator * getWorkUnitsByOwner(const char * owner, ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0; virtual IWorkUnit * updateWorkUnit(const char * wuid, ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0; virtual bool restoreWorkUnit(const char *base, const char *wuid, bool restoreAssociatedFiles) = 0; diff --git a/common/workunit/workunit.ipp b/common/workunit/workunit.ipp index 63d0d6dd11c..c5220312e32 100644 --- a/common/workunit/workunit.ipp +++ b/common/workunit/workunit.ipp @@ -595,7 +595,7 @@ public: const char *importDir, const char *app, const char *user, ISecManager *secMgr, ISecUser *secUser); virtual bool deleteWorkUnit(const char * wuid, ISecManager *secmgr, ISecUser *secuser); virtual bool deleteWorkUnitEx(const char * wuid, bool throwException, ISecManager *secmgr, ISecUser *secuser); - virtual IConstWorkUnit * openWorkUnit(const char * wuid, ISecManager *secmgr, ISecUser *secuser); + virtual IConstWorkUnit * openWorkUnit(const char * wuid, ISecManager *secmgr, ISecUser *secuser, bool expected); virtual IWorkUnit * updateWorkUnit(const char * wuid, ISecManager *secmgr, ISecUser *secuser); virtual bool restoreWorkUnit(const char *base, const char *wuid, bool restoreAssociated); virtual int setTracingLevel(int newlevel); diff --git a/esp/services/ws_workunits/ws_workunitsService.cpp b/esp/services/ws_workunits/ws_workunitsService.cpp index aa54fc9712a..42588462c86 100644 --- a/esp/services/ws_workunits/ws_workunitsService.cpp +++ b/esp/services/ws_workunits/ws_workunitsService.cpp @@ -1708,17 +1708,27 @@ bool CWsWorkunitsEx::onWUResultView(IEspContext &context, IEspWUResultViewReques } -void doWUQueryBySingleWuid(IEspContext &context, const char *wuid, IEspWUQueryResponse &resp) +void doWUQueryBySingleWU(IEspContext &context, IConstWorkUnit *cw, IEspWUQueryResponse &resp) { Owned info= createECLWorkunit("",""); - WsWuInfo winfo(context, wuid); + WsWuInfo winfo(context, cw); winfo.getCommon(*info, 0); IArrayOf results; results.append(*info.getClear()); resp.setWorkunits(results); resp.setPageSize(1); resp.setCount(1); - PROGLOG("getWUInfo: %s", wuid); + PROGLOG("getWUInfo: %s", cw->queryWuid()); +} + +void doWUQueryBySingleWuid(IEspContext &context, const char *wuid, IEspWUQueryResponse &resp) +{ + Owned wf = getWorkUnitFactory(context.querySecManager(), context.queryUser()); + Owned cw = wf->openWorkUnit(wuid, nullptr, nullptr, false); + if (!cw) + return; + ensureWsWorkunitAccess(context, *cw, SecAccess_Read); + doWUQueryBySingleWU(context, cw, resp); } void doWUQueryByFile(IEspContext &context, const char *logicalFile, IEspWUQueryResponse &resp) @@ -1739,7 +1749,7 @@ void doWUQueryByFile(IEspContext &context, const char *logicalFile, IEspWUQueryR "Cannot access the workunit for file %s. Resource %s : Permission denied. Read Access Required.", logicalFile, secAccessFeature.str()); - doWUQueryBySingleWuid(context, wuid.str(), resp); + doWUQueryBySingleWU(context, cw, resp); resp.setFirst(false); resp.setPageSize(1); @@ -2592,10 +2602,7 @@ bool CWsWorkunitsEx::onWUQuery(IEspContext &context, IEspWUQueryRequest & req, I if (req.getType() && strieq(req.getType(), "archived workunits")) doWUQueryFromArchive(context, sashaServerIp.get(), sashaServerPort, *archivedWuCache, awusCacheMinutes, req, resp); else if(notEmpty(wuid) && looksLikeAWuid(wuid, 'W')) - { - ensureWsWorkunitAccess(context, wuid, SecAccess_Read); doWUQueryBySingleWuid(context, wuid, resp); - } else if (notEmpty(req.getLogicalFile()) && req.getLogicalFileSearchType() && strieq(req.getLogicalFileSearchType(), "Created")) doWUQueryByFile(context, req.getLogicalFile(), resp); else