]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp
Add tariff change policy description.
[stg.git] / projects / stargazer / plugins / configuration / rpcconfig / users_methods.cpp
index 5adbf44131905750cfa52fefbf1398b0842b2dd0..3242240f769fe4c75664942cd727d5396fec6477 100644 (file)
@@ -88,7 +88,7 @@ if (users->FindByName(login, &u))
     *retvalPtr = xmlrpc_c::value_boolean(true);
     return;
     }
     *retvalPtr = xmlrpc_c::value_boolean(true);
     return;
     }
-    
+
 *retvalPtr = xmlrpc_c::value_boolean(false);
 return;
 }
 *retvalPtr = xmlrpc_c::value_boolean(false);
 return;
 }
@@ -381,16 +381,29 @@ if (tariffs->FindByName(tariff))
         }
     else
         {
         }
     else
         {
-        if (u->GetProperty().tariffName.Set(tariff,
+        const TARIFF * newTariff = tariffs->FindByName(tariff);
+        if (newTariff)
+            {
+            const TARIFF * currentTariff = u->GetTariff();
+            std::string message = currentTariff->TariffChangeIsAllowed(*newTariff, stgTime);
+            if (message.empty())
+                {
+                if (u->GetProperty().tariffName.Set(tariff,
                                             admin,
                                             login,
                                             store,
                                             comment))
                                             admin,
                                             login,
                                             store,
                                             comment))
-            {
-            u->ResetNextTariff();
-            u->WriteConf();
-            *retvalPtr = xmlrpc_c::value_boolean(true);
-            return;
+                    {
+                    u->ResetNextTariff();
+                    u->WriteConf();
+                    *retvalPtr = xmlrpc_c::value_boolean(true);
+                    return;
+                    }
+                }
+            else
+                {
+                GetStgLogger()("Tariff change is prohibited for user %s. %s", u->GetLogin().c_str(), message.c_str());
+                }
             }
         }
     }
             }
         }
     }