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

View File

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

View File

@@ -112,6 +112,31 @@ namespace OpenWifi {
return true; 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 } // namespace OpenWifi
template <> template <>

View File

@@ -26,6 +26,7 @@ namespace OpenWifi {
bool GetByIP(const std::string &IP, std::string &uuid); bool GetByIP(const std::string &IP, std::string &uuid);
bool Upgrade(uint32_t from, uint32_t &to) override; bool Upgrade(uint32_t from, uint32_t &to) override;
bool EvaluateDeviceRules(const std::string &id, ProvObjects::DeviceRules &Rules); 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: private:
}; };