From 625a7eafbeb1e7f57e4f79a782e8d163e5fa4770 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 30 Jul 2015 08:30:17 +0200 Subject: [PATCH] Fix URL parameters for filters refs #9077 --- lib/remote/filterutility.cpp | 25 ++++++++++++++++--------- lib/remote/statusqueryhandler.cpp | 6 ------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/remote/filterutility.cpp b/lib/remote/filterutility.cpp index 26d893cfb..2764b2c0e 100644 --- a/lib/remote/filterutility.cpp +++ b/lib/remote/filterutility.cpp @@ -75,7 +75,7 @@ std::vector FilterUtility::GetFilterTargets(const QueryDescr boost::algorithm::to_lower(attr); if (query->Contains(attr)) { - String name = query->Get(attr); + String name = HttpUtility::GetLastParameter(query, attr); DynamicObject::Ptr obj = GetObjectByTypeAndName(type->GetName(), name); if (!obj) BOOST_THROW_EXCEPTION(std::invalid_argument("Object does not exist.")); @@ -87,21 +87,28 @@ std::vector FilterUtility::GetFilterTargets(const QueryDescr if (query->Contains(attr)) { Array::Ptr names = query->Get(attr); - ObjectLock olock(names); - BOOST_FOREACH(const String& name, names) { - DynamicObject::Ptr obj = GetObjectByTypeAndName(type->GetName(), name); - if (!obj) - BOOST_THROW_EXCEPTION(std::invalid_argument("Object does not exist.")); - result.push_back(obj); + if (names) { + ObjectLock olock(names); + BOOST_FOREACH(const String& name, names) { + DynamicObject::Ptr obj = GetObjectByTypeAndName(type->GetName(), name); + if (!obj) + BOOST_THROW_EXCEPTION(std::invalid_argument("Object does not exist.")); + result.push_back(obj); + } } } } - if (query->Contains("filter")) { + if (query->Contains("filter") || result.empty()) { if (!query->Contains("type")) BOOST_THROW_EXCEPTION(std::invalid_argument("Type must be specified when using a filter.")); - String filter = HttpUtility::GetLastParameter(query, "filter"); + String filter; + if (!query->Contains("filter")) + filter = "true"; + else + filter = HttpUtility::GetLastParameter(query, "filter"); + String type = HttpUtility::GetLastParameter(query, "type"); Log(LogInformation, "FilterUtility", filter); diff --git a/lib/remote/statusqueryhandler.cpp b/lib/remote/statusqueryhandler.cpp index d78dac78f..d66d36240 100644 --- a/lib/remote/statusqueryhandler.cpp +++ b/lib/remote/statusqueryhandler.cpp @@ -52,8 +52,6 @@ bool StatusQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re String attr = type->GetName(); boost::algorithm::to_lower(attr); params->Set(attr, request.RequestUrl->GetPath()[2]); - } else if (!params->Contains("filter")) { - params->Set("filter", "true"); } std::vector objs = FilterUtility::GetFilterTargets(qd, params); @@ -78,10 +76,6 @@ bool StatusQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re Dictionary::Ptr result1 = new Dictionary(); for (int fid = 0; fid < type->GetFieldCount(); fid++) { Field field = type->GetFieldInfo(fid); - - if ((field.Attributes & (FAConfig|FAState)) == 0) - continue; - String aname = prefix + "." + field.Name; if (!attrs.empty() && attrs.find(aname) == attrs.end()) continue;