]> git.stg.codes - stg.git/commitdiff
ticket 37. The newTariff, currentTariff objects added, if (newTariff)
authorElena Mamontova <helenh463@gmail.com>
Thu, 11 Aug 2016 10:13:36 +0000 (13:13 +0300)
committerElena Mamontova <helenh463@gmail.com>
Thu, 11 Aug 2016 10:13:36 +0000 (13:13 +0300)
checking and TariffChangeIsAllowed() function call added in the
SetUserInfo() function.

projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp

index 89c41587f8527862de5932bbc4cbe52e63ab0c37..0e7ac9d66e13091d8ecf2091a2392400e6f317a0 100644 (file)
@@ -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))