diff --git a/openapi/owprov.yaml b/openapi/owprov.yaml index 1949381..42937cb 100644 --- a/openapi/owprov.yaml +++ b/openapi/owprov.yaml @@ -1558,12 +1558,6 @@ paths: type: string format: uuid required: true - - in: query - name: claimer - schema: - type: string - format: uuid - required: false requestBody: description: Information used to create the new entity content: @@ -1595,6 +1589,17 @@ paths: schema: type: boolean required: false + - in: query + name: claimer + schema: + type: string + format: uuid + required: false + - in: query + name: claimId + schema: + type: string + required: false requestBody: description: Information used to modify the new entity content: diff --git a/src/RESTAPI/RESTAPI_db_helpers.h b/src/RESTAPI/RESTAPI_db_helpers.h index 12bc376..e298cfa 100644 --- a/src/RESTAPI/RESTAPI_db_helpers.h +++ b/src/RESTAPI/RESTAPI_db_helpers.h @@ -154,6 +154,28 @@ namespace OpenWifi { return R.ReturnObject(Answer); } +// ReturnRecordListInventoryDB()), +// ProvObjects::InventoryTag>("taglist",StorageService()->InventoryDB(),*this ); + + template void ReturnRecordList(const char *ArrayName,DB & DBInstance, RESTAPIHandler & R) { + Poco::JSON::Array ObjArr; + for(const auto &i:R.SelectedRecords()) { + ProvObjects::InventoryTag E; + if(DBInstance.GetRecord("serialNumber",i,E)) { + Poco::JSON::Object Obj; + E.to_json(Obj); + if(R.NeedAdditionalInfo()) + AddExtendedInfo(E,Obj); + ObjArr.add(Obj); + } else { + return R.BadRequest(RESTAPI::Errors::UnknownId + i); + } + } + Poco::JSON::Object Answer; + Answer.set(ArrayName, ObjArr); + return R.ReturnObject(Answer); + } + template void ReturnRecordList(const char *ArrayName,DB & DBInstance, RESTAPIHandler & R) { Poco::JSON::Array ObjArr; for(const auto &i:R.SelectedRecords()) { diff --git a/src/RESTAPI/RESTAPI_inventory_handler.cpp b/src/RESTAPI/RESTAPI_inventory_handler.cpp index 2a54b5f..deb8301 100644 --- a/src/RESTAPI/RESTAPI_inventory_handler.cpp +++ b/src/RESTAPI/RESTAPI_inventory_handler.cpp @@ -216,30 +216,40 @@ namespace OpenWifi{ InternalError(RESTAPI::Errors::RecordNotCreated); } - void RESTAPI_inventory_handler::DoPut() { - ProvObjects::InventoryTag Existing; + void RESTAPI_inventory_handler::PerformClaim(const std::string &SerialNumber, const std::string &Claimer, const std::string & ClaimId) { - std::string Claimer; - if(HasParameter("claimer",Claimer) && !Claimer.empty()) { - if(UserInfo_.userinfo.userRole==SecurityObjects::SUBSCRIBER && Claimer!=UserInfo_.userinfo.id) { - return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights, ACCESS_DENIED); - } + if(UserInfo_.userinfo.userRole==SecurityObjects::SUBSCRIBER && Claimer!=UserInfo_.userinfo.id) { + return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights, ACCESS_DENIED); + } - if(UserInfo_.userinfo.userRole!=SecurityObjects::SUBSCRIBER) { - if(!SDK::Sec::Subscriber::Exists(this, Claimer)) { - return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); - } + if(UserInfo_.userinfo.userRole!=SecurityObjects::SUBSCRIBER) { + if(!SDK::Sec::Subscriber::Exists(this, Claimer)) { + return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); } } + // if the device exists, check the status to see if we would follow this claim. + + + } + + void RESTAPI_inventory_handler::DoPut() { + std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,""); - if(SerialNumber.empty() || !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER,SerialNumber,Existing)) { - if(Claimer.empty()) - return NotFound(); - // try claiming this device. + std::string Claimer; + if(HasParameter("claimer",Claimer)) { + std::string ClaimId; + if(!HasParameter("claimId",ClaimId) || SerialNumber.empty() || Claimer.empty()) { + return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); + } + return PerformClaim(SerialNumber, Claimer, ClaimId); } + ProvObjects::InventoryTag Existing; + if(SerialNumber.empty() || !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER,SerialNumber,Existing)) { + return NotFound(); + } auto RawObject = ParseStream(); ProvObjects::InventoryTag NewObject; diff --git a/src/RESTAPI/RESTAPI_inventory_handler.h b/src/RESTAPI/RESTAPI_inventory_handler.h index bec3d8f..34b3166 100644 --- a/src/RESTAPI/RESTAPI_inventory_handler.h +++ b/src/RESTAPI/RESTAPI_inventory_handler.h @@ -31,6 +31,7 @@ namespace OpenWifi { void DoPost() final; void DoPut() final; void DoDelete() final; + void PerformClaim(const std::string &SerialNumber, const std::string & Claimer , const std::string & ClaimId); InventoryDB &DB_; }; } diff --git a/src/RESTAPI/RESTAPI_inventory_list_handler.cpp b/src/RESTAPI/RESTAPI_inventory_list_handler.cpp index 39f4731..200c9cb 100644 --- a/src/RESTAPI/RESTAPI_inventory_list_handler.cpp +++ b/src/RESTAPI/RESTAPI_inventory_list_handler.cpp @@ -50,8 +50,7 @@ namespace OpenWifi{ } if(!QB_.Select.empty()) { - return ReturnRecordListInventoryDB()), - ProvObjects::InventoryTag>("taglist",StorageService()->InventoryDB(),*this ); + return ReturnRecordListInventoryDB())>("taglist",StorageService()->InventoryDB(),*this ); } else if(HasParameter("entity",UUID)) { if(QB_.CountOnly) { auto C = StorageService()->InventoryDB().Count( StorageService()->InventoryDB().OP("entity",ORM::EQ,UUID)); diff --git a/src/framework/RESTAPI_errors.h b/src/framework/RESTAPI_errors.h index 061ba9a..c35f2fa 100644 --- a/src/framework/RESTAPI_errors.h +++ b/src/framework/RESTAPI_errors.h @@ -14,7 +14,7 @@ namespace OpenWifi::RESTAPI::Errors { static const std::string CouldNotBeDeleted{"Element could not be deleted."}; static const std::string NameMustBeSet{"The name property must be set."}; static const std::string ConfigBlockInvalid{"Configuration block type invalid."}; - static const std::string UnknownId{"Unknown management policy."}; + static const std::string UnknownId{"Unknown UUID."}; static const std::string InvalidDeviceTypes{"Unknown or invalid device type(s)."}; static const std::string RecordNotCreated{"Record could not be created."}; static const std::string RecordNotUpdated{"Record could not be updated."};