| 17 | REGISTER_URLHANDLER("/v1/objects", DeleteObjectHandler); |
| 18 | |
| 19 | bool DeleteObjectHandler::HandleRequest( |
| 20 | const WaitGroup::Ptr& waitGroup, |
| 21 | const HttpApiRequest& request, |
| 22 | HttpApiResponse& response, |
| 23 | boost::asio::yield_context& yc |
| 24 | ) |
| 25 | { |
| 26 | namespace http = boost::beast::http; |
| 27 | |
| 28 | auto url = request.Url(); |
| 29 | auto user = request.User(); |
| 30 | auto params = request.Params(); |
| 31 | |
| 32 | if (url->GetPath().size() < 3 || url->GetPath().size() > 4) |
| 33 | return false; |
| 34 | |
| 35 | if (request.method() != http::verb::delete_) |
| 36 | return false; |
| 37 | |
| 38 | Type::Ptr type = FilterUtility::TypeFromPluralName(url->GetPath()[2]); |
| 39 | |
| 40 | if (!type) { |
| 41 | HttpUtility::SendJsonError(response, params, 400, "Invalid type specified."); |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | QueryDescription qd; |
| 46 | qd.Types.insert(type->GetName()); |
| 47 | qd.Permission = "objects/delete/" + type->GetName(); |
| 48 | |
| 49 | params->Set("type", type->GetName()); |
| 50 | |
| 51 | if (url->GetPath().size() >= 4) { |
| 52 | String attr = type->GetName(); |
| 53 | boost::algorithm::to_lower(attr); |
| 54 | params->Set(attr, url->GetPath()[3]); |
| 55 | } |
| 56 | |
| 57 | std::vector<Value> objs; |
| 58 | |
| 59 | try { |
| 60 | objs = FilterUtility::GetFilterTargets(qd, params, user); |
| 61 | } catch (const MissingPermissionError& ex) { |
| 62 | HttpUtility::SendJsonError(response, params, 403, ex.what()); |
| 63 | return true; |
| 64 | } catch (const std::exception& ex) { |
| 65 | HttpUtility::SendJsonError(response, params, 404, |
| 66 | "No objects found.", |
| 67 | DiagnosticInformation(ex)); |
| 68 | return true; |
| 69 | } |
| 70 | |
| 71 | bool cascade = HttpUtility::GetLastParameter(params, "cascade"); |
| 72 | bool verbose = HttpUtility::GetLastParameter(params, "verbose"); |
| 73 | |
| 74 | ConfigObjectsSharedLock lock (std::try_to_lock); |
| 75 | |
| 76 | if (!lock) { |
nothing calls this directly
no test coverage detected