mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-11-01 19:17:47 +00:00
Fixing inventory select bug.
This commit is contained in:
@@ -1558,12 +1558,6 @@ paths:
|
|||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
required: true
|
required: true
|
||||||
- in: query
|
|
||||||
name: claimer
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
format: uuid
|
|
||||||
required: false
|
|
||||||
requestBody:
|
requestBody:
|
||||||
description: Information used to create the new entity
|
description: Information used to create the new entity
|
||||||
content:
|
content:
|
||||||
@@ -1595,6 +1589,17 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
type: boolean
|
type: boolean
|
||||||
required: false
|
required: false
|
||||||
|
- in: query
|
||||||
|
name: claimer
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
required: false
|
||||||
|
- in: query
|
||||||
|
name: claimId
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
requestBody:
|
requestBody:
|
||||||
description: Information used to modify the new entity
|
description: Information used to modify the new entity
|
||||||
content:
|
content:
|
||||||
|
|||||||
@@ -154,6 +154,28 @@ namespace OpenWifi {
|
|||||||
return R.ReturnObject(Answer);
|
return R.ReturnObject(Answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReturnRecordList<decltype(StorageService()->InventoryDB()),
|
||||||
|
// ProvObjects::InventoryTag>("taglist",StorageService()->InventoryDB(),*this );
|
||||||
|
|
||||||
|
template <typename DB> 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 <typename DB, typename Record> void ReturnRecordList(const char *ArrayName,DB & DBInstance, RESTAPIHandler & R) {
|
template <typename DB, typename Record> void ReturnRecordList(const char *ArrayName,DB & DBInstance, RESTAPIHandler & R) {
|
||||||
Poco::JSON::Array ObjArr;
|
Poco::JSON::Array ObjArr;
|
||||||
for(const auto &i:R.SelectedRecords()) {
|
for(const auto &i:R.SelectedRecords()) {
|
||||||
|
|||||||
@@ -216,30 +216,40 @@ namespace OpenWifi{
|
|||||||
InternalError(RESTAPI::Errors::RecordNotCreated);
|
InternalError(RESTAPI::Errors::RecordNotCreated);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RESTAPI_inventory_handler::DoPut() {
|
void RESTAPI_inventory_handler::PerformClaim(const std::string &SerialNumber, const std::string &Claimer, const std::string & ClaimId) {
|
||||||
ProvObjects::InventoryTag Existing;
|
|
||||||
|
|
||||||
std::string Claimer;
|
if(UserInfo_.userinfo.userRole==SecurityObjects::SUBSCRIBER && Claimer!=UserInfo_.userinfo.id) {
|
||||||
if(HasParameter("claimer",Claimer) && !Claimer.empty()) {
|
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(UserInfo_.userinfo.userRole!=SecurityObjects::SUBSCRIBER) {
|
||||||
if(!SDK::Sec::Subscriber::Exists(this, Claimer)) {
|
if(!SDK::Sec::Subscriber::Exists(this, Claimer)) {
|
||||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
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,"");
|
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();
|
auto RawObject = ParseStream();
|
||||||
ProvObjects::InventoryTag NewObject;
|
ProvObjects::InventoryTag NewObject;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ namespace OpenWifi {
|
|||||||
void DoPost() final;
|
void DoPost() final;
|
||||||
void DoPut() final;
|
void DoPut() final;
|
||||||
void DoDelete() final;
|
void DoDelete() final;
|
||||||
|
void PerformClaim(const std::string &SerialNumber, const std::string & Claimer , const std::string & ClaimId);
|
||||||
InventoryDB &DB_;
|
InventoryDB &DB_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,8 +50,7 @@ namespace OpenWifi{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!QB_.Select.empty()) {
|
if(!QB_.Select.empty()) {
|
||||||
return ReturnRecordList<decltype(StorageService()->InventoryDB()),
|
return ReturnRecordList<decltype(StorageService()->InventoryDB())>("taglist",StorageService()->InventoryDB(),*this );
|
||||||
ProvObjects::InventoryTag>("taglist",StorageService()->InventoryDB(),*this );
|
|
||||||
} else if(HasParameter("entity",UUID)) {
|
} else if(HasParameter("entity",UUID)) {
|
||||||
if(QB_.CountOnly) {
|
if(QB_.CountOnly) {
|
||||||
auto C = StorageService()->InventoryDB().Count( StorageService()->InventoryDB().OP("entity",ORM::EQ,UUID));
|
auto C = StorageService()->InventoryDB().Count( StorageService()->InventoryDB().OP("entity",ORM::EQ,UUID));
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace OpenWifi::RESTAPI::Errors {
|
|||||||
static const std::string CouldNotBeDeleted{"Element could not be deleted."};
|
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 NameMustBeSet{"The name property must be set."};
|
||||||
static const std::string ConfigBlockInvalid{"Configuration block type invalid."};
|
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 InvalidDeviceTypes{"Unknown or invalid device type(s)."};
|
||||||
static const std::string RecordNotCreated{"Record could not be created."};
|
static const std::string RecordNotCreated{"Record could not be created."};
|
||||||
static const std::string RecordNotUpdated{"Record could not be updated."};
|
static const std::string RecordNotUpdated{"Record could not be updated."};
|
||||||
|
|||||||
Reference in New Issue
Block a user