]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp
Merge branch 'stg-2.409' into stg-2.409-radius
[stg.git] / projects / stargazer / plugins / configuration / sgconfig / parser_users.cpp
index ce07b09452b0ad8ebf8d5c64a607e798af473d9a..5707b726200e97b5792646496667f6ffe7aa2755 100644 (file)
@@ -594,58 +594,20 @@ int CHG_USER::ApplyChanges()
 
     if (!m_ucr.tariffName.empty())
     {
-        const TARIFF * tariff = u->GetTariff();
         const TARIFF * newTariff = m_tariffs.FindByName(m_ucr.tariffName.const_data());
         if (newTariff)
         {
-        switch (tariff->GetChangePolicy())
+            const TARIFF * tariff = u->GetTariff();
+            std::string message = tariff->TariffChangeIsAllowed(*newTariff, stgTime);
+            if (message.empty())
             {
-            case TARIFF::ALLOW:
-                {
                 if (!u->GetProperty().tariffName.Set(m_ucr.tariffName.const_data(), &m_currAdmin, m_login, &m_store))
                     return -1;
                 u->ResetNextTariff();
-                break;
-                }
-            case TARIFF::TO_CHEAP:
-                {
-                if (newTariff->GetFee() < tariff->GetFee())
-                    {
-                    if (!u->GetProperty().tariffName.Set(m_ucr.tariffName.const_data(), &m_currAdmin, m_login, &m_store))
-                        return -1;
-                u->ResetNextTariff();
-                    }
-                else
-                    GetStgLogger()("Tariff change is prohibited for user %s due to the policy %s. Current tariff %s is more cheap than new tariff %s.",
-                                 u->GetLogin().c_str(),
-                                 TARIFF::ChangePolicyToString(tariff->GetChangePolicy()).c_str(),
-                                 u->GetTariff()->GetName().c_str(),
-                                 newTariff->GetName().c_str());
-                break;
-                }
-            case TARIFF::TO_EXPENSIVE:
-                {
-                if (newTariff->GetFee() > tariff->GetFee())
-                {
-                     if (!u->GetProperty().tariffName.Set(m_ucr.tariffName.const_data(), &m_currAdmin, m_login, &m_store))
-                        return -1;
-                u->ResetNextTariff();
-                }
-                else
-                    GetStgLogger()("Tariff change is prohibited for user %s due to the policy %s. Current tariff %s is more expensive than new tariff %s.",
-                                 u->GetLogin().c_str(),
-                                 TARIFF::ChangePolicyToString(tariff->GetChangePolicy()).c_str(),
-                                 u->GetTariff()->GetName().c_str(),
-                                 newTariff->GetName().c_str());
-                break;
-                }
-            case TARIFF::DENY:
-                {
-                GetStgLogger()("Tariff change is prohibited for user %s. Tariff %s.",
-                             u->GetLogin().c_str(),
-                             u->GetTariff()->GetName().c_str());
-                break;
-                }
+            }
+            else
+            {
+                GetStgLogger()("Tariff change is prohibited for user %s. %s", u->GetLogin().c_str(), message.c_str());
             }
         }
         else