stephb9959
2023-07-10 13:13:05 -07:00
parent 0437031d78
commit 8dde169148
6 changed files with 48 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13)
project(owprov VERSION 2.10.0)
project(owprov VERSION 2.11.0)
set(CMAKE_CXX_STANDARD 17)

2
build
View File

@@ -1 +1 @@
32
2

View File

@@ -90,9 +90,9 @@ namespace OpenWifi {
}
if (!Existing.contacts.empty()) {
for (const auto &i : Existing.contacts)
for (const auto &contact_uuid : Existing.contacts)
StorageService()->ContactDB().DeleteInUse(
"id", i, StorageService()->VenueDB().Prefix(), UUID);
"id", contact_uuid, StorageService()->VenueDB().Prefix(), UUID);
}
if (!Existing.location.empty())
StorageService()->LocationDB().DeleteInUse("id", Existing.location,
@@ -101,9 +101,9 @@ namespace OpenWifi {
StorageService()->PolicyDB().DeleteInUse("id", Existing.managementPolicy,
StorageService()->VenueDB().Prefix(), UUID);
if (!Existing.deviceConfiguration.empty()) {
for (auto &i : Existing.deviceConfiguration)
for (auto &configuration_uuid : Existing.deviceConfiguration)
StorageService()->ConfigurationDB().DeleteInUse(
"id", i, StorageService()->VenueDB().Prefix(), UUID);
"id", configuration_uuid, StorageService()->VenueDB().Prefix(), UUID);
}
if (!Existing.parent.empty())
StorageService()->VenueDB().DeleteChild("id", Existing.parent, UUID);
@@ -157,6 +157,10 @@ namespace OpenWifi {
return BadRequest(RESTAPI::Errors::EntityMustExist);
}
if(StorageService()->VenueDB().DoesVenueNameAlreadyExist(NewObject.info.name,NewObject.entity, NewObject.parent)) {
return BadRequest(RESTAPI::Errors::VenuesNameAlreadyExists);
}
if (!NewObject.contacts.empty()) {
for (const auto &i : NewObject.contacts) {
if (!StorageService()->ContactDB().Exists("id", i)) {
@@ -432,7 +436,7 @@ namespace OpenWifi {
std::string MoveFromEntity, MoveToEntity;
if (AssignIfPresent(RawObject, "entity", MoveToEntity)) {
if (!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id", MoveToEntity)) {
if (MoveToEntity.empty() || !StorageService()->EntityDB().Exists("id", MoveToEntity)) {
return BadRequest(RESTAPI::Errors::EntityMustExist);
}
MoveFromEntity = Existing.entity;
@@ -441,7 +445,7 @@ namespace OpenWifi {
std::string MoveToVenue, MoveFromVenue;
if (AssignIfPresent(RawObject, "venue", MoveToVenue)) {
if (!MoveToVenue.empty() && !StorageService()->VenueDB().Exists("id", MoveToVenue)) {
if (MoveToVenue.empty() || !StorageService()->VenueDB().Exists("id", MoveToVenue)) {
return BadRequest(RESTAPI::Errors::VenueMustExist);
}
MoveFromVenue = Existing.parent;
@@ -450,7 +454,7 @@ namespace OpenWifi {
std::string MoveFromLocation, MoveToLocation;
if (AssignIfPresent(RawObject, "location", MoveToLocation)) {
if (!MoveToLocation.empty() &&
if (MoveToLocation.empty() ||
!StorageService()->LocationDB().Exists("id", MoveToLocation)) {
return BadRequest(RESTAPI::Errors::LocationMustExist);
}
@@ -460,8 +464,8 @@ namespace OpenWifi {
Types::UUIDvec_t MoveFromContacts, MoveToContacts;
if (AssignIfPresent(RawObject, "contacts", MoveToContacts)) {
for (const auto &i : NewObject.contacts) {
if (!StorageService()->ContactDB().Exists("id", i)) {
for (const auto &contact : NewObject.contacts) {
if (!StorageService()->ContactDB().Exists("id", contact)) {
return BadRequest(RESTAPI::Errors::ContactMustExist);
}
}
@@ -471,7 +475,7 @@ namespace OpenWifi {
std::string MoveFromPolicy, MoveToPolicy;
if (AssignIfPresent(RawObject, "managementPolicy", MoveToPolicy)) {
if (!MoveToPolicy.empty() && !StorageService()->PolicyDB().Exists("id", MoveToPolicy)) {
if (MoveToPolicy.empty() || !StorageService()->PolicyDB().Exists("id", MoveToPolicy)) {
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
MoveFromPolicy = Existing.managementPolicy;
@@ -481,8 +485,8 @@ namespace OpenWifi {
Types::UUIDvec_t MoveToConfigurations, MoveFromConfigurations;
if (RawObject->has("deviceConfiguration")) {
MoveToConfigurations = NewObject.deviceConfiguration;
for (auto &i : MoveToConfigurations) {
if (!StorageService()->ConfigurationDB().Exists("id", i)) {
for (auto &configuration : MoveToConfigurations) {
if (!StorageService()->ConfigurationDB().Exists("id", configuration)) {
return BadRequest(RESTAPI::Errors::ConfigurationMustExist);
}
}

View File

@@ -400,6 +400,10 @@ namespace OpenWifi::RESTAPI::Errors {
static const struct msg SimulatedDeviceNotSupported {
1171, "Command not supported on simulated device."
};
static const struct msg VenuesNameAlreadyExists {
1172, "Venue name already exists."
};
static const struct msg SimulationDoesNotExist {
7000, "Simulation Instance ID does not exist."

View File

@@ -112,6 +112,31 @@ namespace OpenWifi {
return true;
}
bool VenueDB::DoesVenueNameAlreadyExist(const std::string &name, const std::string &entity_uuid, const std::string &parent_uuid) {
std::string Statement;
if(!entity_uuid.empty()) {
Statement = fmt::format("select count(*) from venues where entity='{}' and upper(name)='{}'",
entity_uuid, Poco::toUpper(name));
} else {
Statement = fmt::format("select count(*) from venues where parent='{}' and upper(name)='{}'",
parent_uuid, Poco::toUpper(name));
}
std::uint64_t RecordCount = 0;
try {
Poco::Data::Session Session = Pool_.get();
Poco::Data::Statement Command(Session);
Command << Statement,
Poco::Data::Keywords::into(RecordCount);
Command.execute();
} catch (...) {
}
return RecordCount!=0;
}
} // namespace OpenWifi
template <>

View File

@@ -26,6 +26,7 @@ namespace OpenWifi {
bool GetByIP(const std::string &IP, std::string &uuid);
bool Upgrade(uint32_t from, uint32_t &to) override;
bool EvaluateDeviceRules(const std::string &id, ProvObjects::DeviceRules &Rules);
bool DoesVenueNameAlreadyExist(const std::string &name, const std::string &entity_uuid, const std::string &parent_uuid);
private:
};