From: Elena Mamontova Date: Thu, 11 Aug 2016 10:13:36 +0000 (+0300) Subject: ticket 37. The newTariff, currentTariff objects added, if (newTariff) X-Git-Tag: 2.409~118 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/d116ec3c7dda1d4ce516330a3aed74ea0b3dfdb8?ds=inline ticket 37. The newTariff, currentTariff objects added, if (newTariff) checking and TariffChangeIsAllowed() function call added in the SetUserInfo() function. --- diff --git a/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp b/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp index 89c41587..0e7ac9d6 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp @@ -433,13 +433,27 @@ if ((it = structVal.find("tariff")) != structVal.end()) tariff = tariff.substr(0, pos); } - if (tariffs->FindByName(tariff)) - if (ptr->GetProperty().tariffName.Get() != tariff) - if (!ptr->GetProperty().tariffName.Set(tariff, - admin, - login, - &store)) - return true; + const TARIFF * newTariff = tariffs->FindByName(tariff); + if (newTariff) + { + const TARIFF * currentTariff = ptr->GetTariff(); + std::string message = currentTariff->TariffChangeIsAllowed(*newTariff); + if (message.empty()) + { + if (ptr->GetProperty().tariffName.Get() != tariff) + { + if (!ptr->GetProperty().tariffName.Set(tariff, + admin, + login, + &store)) + return true; + } + } + else + { + GetStgLogger()("Tariff change is prohibited for user %s. %s", ptr->GetLogin().c_str(), message.c_str()); + } + } if (nextTariff != "" && tariffs->FindByName(nextTariff))