소스 검색

fix(keys): allow PATCH scope:null to clear a key's scope

Fszontagh 1 개월 전
부모
커밋
5d4c30b6ad
1개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. 4 1
      src/handlers/keys.cpp

+ 4 - 1
src/handlers/keys.cpp

@@ -4,7 +4,10 @@
 namespace svapi {
 
 static std::optional<KeyScope> parseScope(const nlohmann::json& body, bool admin) {
-    if (!body.contains("scope")) return std::nullopt;
+    // Absent OR explicit null ⇒ no scope. For PATCH, the caller only invokes this
+    // when "scope" is present, so a null value yields nullopt which the double-optional
+    // wrapper turns into "clear the scope" (outer engaged, inner nullopt).
+    if (!body.contains("scope") || body["scope"].is_null()) return std::nullopt;
     if (admin) throw ApiError(ErrCode::Unprocessable, "validation", "admin keys cannot be scoped");
     const auto& sj = body["scope"];
     if (!sj.is_object()) throw ApiError(ErrCode::Unprocessable, "validation", "scope must be an object");