]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp
Ticket. The stgTime argument added in TariffChangeIsAllowed() function
[stg.git] / projects / stargazer / plugins / configuration / rpcconfig / user_helper.cpp
index 89c41587f8527862de5932bbc4cbe52e63ab0c37..ac6e72615a95e43ec6da8feacc7fe796be59f042 100644 (file)
@@ -433,13 +433,27 @@ if ((it = structVal.find("tariff")) != structVal.end())
         tariff = tariff.substr(0, pos);
         }
 
         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, stgTime);
+        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))
 
     if (nextTariff != "" &&
         tariffs->FindByName(nextTariff))