Skip to content

Commit

Permalink
HPCC-33203: Improve work unit list filtering by WUID
Browse files Browse the repository at this point in the history
Return an empty list when a user-entered WUID filter doesn't correspond to a
a defined work unit.

Signed-off-by: Tim Klemm <[email protected]>
  • Loading branch information
Tim Klemm authored and Tim Klemm committed Jan 13, 2025
1 parent 4a8ecb4 commit e90b965
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
10 changes: 5 additions & 5 deletions common/workunit/workunit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion common/workunit/workunit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion common/workunit/workunit.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 14 additions & 7 deletions esp/services/ws_workunits/ws_workunitsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IEspECLWorkunit> info= createECLWorkunit("","");
WsWuInfo winfo(context, wuid);
WsWuInfo winfo(context, cw);
winfo.getCommon(*info, 0);
IArrayOf<IEspECLWorkunit> 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<IWorkUnitFactory> wf = getWorkUnitFactory(context.querySecManager(), context.queryUser());
Owned<IConstWorkUnit> 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)
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e90b965

Please sign in to comment.