From f3fdcb0f6bbadb858028223c53e2813ebb347de3 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 30 Sep 2015 13:26:19 +0200 Subject: [PATCH] Fix: /v1/objects/ returns an HTTP error when there are no objects of that type fixes #10253 --- lib/remote/filterutility.cpp | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/remote/filterutility.cpp b/lib/remote/filterutility.cpp index 2e3797aef..5070e2771 100644 --- a/lib/remote/filterutility.cpp +++ b/lib/remote/filterutility.cpp @@ -34,15 +34,21 @@ Type::Ptr FilterUtility::TypeFromPluralName(const String& pluralName) String uname = pluralName; boost::algorithm::to_lower(uname); - BOOST_FOREACH(const ConfigType::Ptr& dtype, ConfigType::GetTypes()) { - Type::Ptr type = Type::GetByName(dtype->GetName()); - ASSERT(type); + { + Dictionary::Ptr globals = ScriptGlobal::GetGlobals(); + ObjectLock olock(globals); + BOOST_FOREACH(const Dictionary::Pair& kv, globals) { + if (!kv.second.IsObjectType()) + continue; + + Type::Ptr type = kv.second; - String pname = type->GetPluralName(); - boost::algorithm::to_lower(pname); + String pname = type->GetPluralName(); + boost::algorithm::to_lower(pname); - if (uname == pname) - return type; + if (uname == pname) + return type; + } } return Type::Ptr(); @@ -51,10 +57,11 @@ Type::Ptr FilterUtility::TypeFromPluralName(const String& pluralName) void ConfigObjectTargetProvider::FindTargets(const String& type, const boost::function& addTarget) const { ConfigType::Ptr dtype = ConfigType::GetByName(type); - ASSERT(dtype); - BOOST_FOREACH(const ConfigObject::Ptr& object, dtype->GetObjects()) { - addTarget(object); + if (dtype) { + BOOST_FOREACH(const ConfigObject::Ptr& object, dtype->GetObjects()) { + addTarget(object); + } } } @@ -70,7 +77,12 @@ Value ConfigObjectTargetProvider::GetTargetByName(const String& type, const Stri bool ConfigObjectTargetProvider::IsValidType(const String& type) const { - return ConfigType::GetByName(type) != ConfigType::Ptr(); + Type::Ptr ptype = Type::GetByName(type); + + if (!ptype) + return false; + + return ConfigObject::TypeInstance->IsAssignableFrom(ptype); } String ConfigObjectTargetProvider::GetPluralName(const String& type) const -- 2.40.0