diff --git a/3rdParty/TargomanDBM b/3rdParty/TargomanDBM index 84b4207d..f6c47e4a 160000 --- a/3rdParty/TargomanDBM +++ b/3rdParty/TargomanDBM @@ -1 +1 @@ -Subproject commit 84b4207df50db12494b618996b24e1f6f470a12d +Subproject commit f6c47e4ace7e59e6b0813a2a10930371b778f404 diff --git a/App/Server/appTargomanAPI.cpp b/App/Server/appTargomanAPI.cpp index cab2a8f8..58c2a215 100644 --- a/App/Server/appTargomanAPI.cpp +++ b/App/Server/appTargomanAPI.cpp @@ -57,14 +57,14 @@ void appTargomanAPI::slotExecute() { try { // ServerCommonConfigs::InstanceID.setFromVariant(QString("TAPI-%1").arg(Helpers::SecurityHelper::UUIDtoMD5())); ServerCommonConfigs::InstanceID.setFromVariant(QString("TAPI-%1").arg(QSysInfo::machineHostName())); - TargomanDebug(0) << "Instance-ID: " << ServerCommonConfigs::InstanceID.value(); + TargomanDebug(5) << "Instance-ID: " << ServerCommonConfigs::InstanceID.value(); QMap RequiredDBs; auto RegisterModule = [&RequiredDBs](intfPureModule *_module) { _module->setInstancePointer(); - TargomanDebug(0) << "Registering module <" << _module->moduleFullName() << ">"; + TargomanDebug(5) << "Registering module <" << _module->moduleFullName() << ">"; foreach (auto ModuleMethod, _module->listOfMethods()) RESTAPIRegistry::registerRESTAPI(ModuleMethod.Module, ModuleMethod.Method); diff --git a/Interfaces/AAA/Accounting_Interfaces.cpp b/Interfaces/AAA/Accounting_Interfaces.cpp index b7104679..e04ab02e 100644 --- a/Interfaces/AAA/Accounting_Interfaces.cpp +++ b/Interfaces/AAA/Accounting_Interfaces.cpp @@ -97,7 +97,7 @@ namespace Targoman::API::AAA { /******************************************************************/ /******************************************************************/ //key: schema -QMap intfAccountUnitsI18N::myInstance; +QMap intfAccountUnitsI18N::MyInstance; intfAccountUnitsI18N::intfAccountUnitsI18N( // bool _isTokenBase, @@ -115,7 +115,7 @@ intfAccountUnitsI18N::intfAccountUnitsI18N( ) // intfAccountORMBase(_isTokenBase) { - intfAccountUnitsI18N::myInstance[_schema] = this; + intfAccountUnitsI18N::MyInstance[_schema] = this; } /******************************************************************/ @@ -138,7 +138,7 @@ intfAccountUnits::intfAccountUnits( ORMSelectQuery intfAccountUnits::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const QString &_alias, Q_DECL_UNUSED bool _translate, Q_DECL_UNUSED bool _isRoot) { - intfAccountUnitsI18N::myInstance[this->Schema]->prepareFiltersList(); + intfAccountUnitsI18N::MyInstance[this->Schema]->prepareFiltersList(); ORMSelectQuery Query = intfSQLBasedModule::makeSelectQuery(APICALLBOOM_PARAM, _alias, _translate) .addCols(this->selectableColumnNames()) @@ -149,7 +149,7 @@ ORMSelectQuery intfAccountUnits::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBO .removeCols({ tblAccountUnitsBase::Fields::untName }) - .nestedLeftJoin(intfAccountUnitsI18N::myInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM) + .nestedLeftJoin(intfAccountUnitsI18N::MyInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM) .where({ tblAccountUnitsI18NBase::Fields::language, enuConditionOperator::Equal, APICALLBOOM_PARAM.language() }) , "lng_tblAccountUnits" , { "lng_tblAccountUnits", tblAccountUnitsI18NBase::Fields::pid, @@ -166,7 +166,7 @@ ORMSelectQuery intfAccountUnits::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBO ; } else { Query - .nestedLeftJoin(intfAccountUnitsI18N::myInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM) + .nestedLeftJoin(intfAccountUnitsI18N::MyInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM) .addCol(tblAccountUnitsI18NBase::Fields::pid) .addCol(DBExpression::VALUE(QString("CONCAT('[', GROUP_CONCAT(JSON_OBJECT(`language`, %1)), ']')") .arg(tblAccountUnitsI18NBase::Fields::untNameI18N)), @@ -212,7 +212,7 @@ bool IMPL_ORMDELETE_USER(intfAccountUnits) { /******************************************************************/ /******************************************************************/ //key: schema -QMap intfAccountProductsI18N::myInstance; +QMap intfAccountProductsI18N::MyInstance; intfAccountProductsI18N::intfAccountProductsI18N( // bool _isTokenBase, @@ -230,7 +230,7 @@ intfAccountProductsI18N::intfAccountProductsI18N( ) // intfAccountORMBase(_isTokenBase) { - intfAccountProductsI18N::myInstance[_schema] = this; + intfAccountProductsI18N::MyInstance[_schema] = this; } /******************************************************************/ @@ -252,7 +252,7 @@ intfAccountProducts::intfAccountProducts( { ; } ORMSelectQuery intfAccountProducts::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const QString &_alias, Q_DECL_UNUSED bool _translate, Q_DECL_UNUSED bool _isRoot) { - intfAccountProductsI18N::myInstance[this->Schema]->prepareFiltersList(); + intfAccountProductsI18N::MyInstance[this->Schema]->prepareFiltersList(); ORMSelectQuery Query = intfSQLBasedModule::makeSelectQuery(APICALLBOOM_PARAM, _alias, _translate) .addCols(this->selectableColumnNames()) @@ -273,7 +273,7 @@ ORMSelectQuery intfAccountProducts::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICAL tblAccountProductsBase::Fields::prdName, tblAccountProductsBase::Fields::prdDesc, }) - .nestedLeftJoin(intfAccountProductsI18N::myInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM) + .nestedLeftJoin(intfAccountProductsI18N::MyInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM) .where({ tblAccountProductsI18NBase::Fields::language, enuConditionOperator::Equal, APICALLBOOM_PARAM.language() }) , "lng_tblAccountProducts" , { "lng_tblAccountProducts", tblAccountProductsI18NBase::Fields::pid, @@ -296,7 +296,7 @@ ORMSelectQuery intfAccountProducts::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICAL ; } else { Query - .nestedLeftJoin(intfAccountProductsI18N::myInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM) + .nestedLeftJoin(intfAccountProductsI18N::MyInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM) .addCol(tblAccountProductsI18NBase::Fields::pid) .addCol(DBExpression::VALUE(QString("CONCAT('[', GROUP_CONCAT(JSON_OBJECT(`language`, %1)), ']')") .arg(tblAccountProductsI18NBase::Fields::prdNameI18N)), @@ -349,7 +349,7 @@ bool IMPL_ORMDELETE_USER(intfAccountProducts) { /******************************************************************/ /******************************************************************/ //key: schema -QMap intfAccountSaleablesI18N::myInstance; +QMap intfAccountSaleablesI18N::MyInstance; intfAccountSaleablesI18N::intfAccountSaleablesI18N( // bool _isTokenBase, @@ -367,10 +367,13 @@ intfAccountSaleablesI18N::intfAccountSaleablesI18N( ) // intfAccountORMBase(_isTokenBase) { - intfAccountSaleablesI18N::myInstance[_schema] = this; + intfAccountSaleablesI18N::MyInstance[_schema] = this; } /******************************************************************/ +//key: schema +QMap intfAccountSaleables::MyInstance; + intfAccountSaleables::intfAccountSaleables( // bool _isTokenBase, const QString& _schema, @@ -386,10 +389,12 @@ intfAccountSaleables::intfAccountSaleables( tblAccountSaleablesBase::Private::Indexes + _exclusiveIndexes ) // intfAccountORMBase(_isTokenBase) -{ ; } +{ + intfAccountSaleables::MyInstance[_schema] = this; +} ORMSelectQuery intfAccountSaleables::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const QString &_alias, Q_DECL_UNUSED bool _translate, Q_DECL_UNUSED bool _isRoot) { - intfAccountSaleablesI18N::myInstance[this->Schema]->prepareFiltersList(); + intfAccountSaleablesI18N::MyInstance[this->Schema]->prepareFiltersList(); ORMSelectQuery Query = intfSQLBasedModule::makeSelectQuery(APICALLBOOM_PARAM, _alias, _translate) .addCols(this->selectableColumnNames()) @@ -401,7 +406,7 @@ ORMSelectQuery intfAccountSaleables::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICA tblAccountSaleablesBase::Fields::slbName, tblAccountSaleablesBase::Fields::slbDesc, }) - .nestedLeftJoin(intfAccountSaleablesI18N::myInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM) + .nestedLeftJoin(intfAccountSaleablesI18N::MyInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM) .where({ tblAccountSaleablesI18NBase::Fields::language, enuConditionOperator::Equal, APICALLBOOM_PARAM.language() }) , "lng_tblAccountSaleables" , { "lng_tblAccountSaleables", tblAccountSaleablesI18NBase::Fields::pid, @@ -424,7 +429,7 @@ ORMSelectQuery intfAccountSaleables::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICA ; } else { Query - .nestedLeftJoin(intfAccountSaleablesI18N::myInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM) + .nestedLeftJoin(intfAccountSaleablesI18N::MyInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM) .addCol(tblAccountSaleablesI18NBase::Fields::pid) .addCol(DBExpression::VALUE(QString("CONCAT('[', GROUP_CONCAT(JSON_OBJECT(`language`, %1)), ']')") .arg(tblAccountSaleablesI18NBase::Fields::slbNameI18N)), @@ -508,7 +513,7 @@ bool IMPL_ORMDELETE_USER(intfAccountSaleables) { /******************************************************************/ //key: schema -QMap intfAccountSaleablesFiles::myInstance; +QMap intfAccountSaleablesFiles::MyInstance; intfAccountSaleablesFiles::intfAccountSaleablesFiles( // bool _isTokenBase, @@ -526,7 +531,7 @@ intfAccountSaleablesFiles::intfAccountSaleablesFiles( ) // intfAccountORMBase(_isTokenBase) { - intfAccountSaleablesFiles::myInstance[_schema] = this; + intfAccountSaleablesFiles::MyInstance[_schema] = this; } QVariant IMPL_ORMGET_ANONYMOUSE(intfAccountSaleablesFiles) { @@ -628,7 +633,7 @@ ORMSelectQuery intfAccountUserAssets::makeSelectQuery(INTFAPICALLBOOM_IMPL &APIC // ) tmpNeededFiles // ON tmpNeededFiles.slf_slbID = tblAccountUserAssets.uas_slbID - .nestedLeftJoin(intfAccountSaleablesFiles::myInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM, "", true, false) + .nestedLeftJoin(intfAccountSaleablesFiles::MyInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM, "", true, false) .addCol(tblAccountSaleablesFilesBase::Fields::slf_slbID, tblAccountSaleablesFilesBase::Fields::slf_slbID) .addCol(enuAggregation::SUM, tblAccountSaleablesFilesBase::Fields::slfMinCount, "MandatoryFilesCount") .where({ tblAccountSaleablesFilesBase::Fields::slfMinCount, enuConditionOperator::Greater, 0 }) @@ -663,7 +668,7 @@ ORMSelectQuery intfAccountUserAssets::makeSelectQuery(INTFAPICALLBOOM_IMPL &APIC // ON tmpProvidedFiles.uasufl_uasID = tblAccountUserAssets.uasID .nestedLeftJoin(ORMSelectQuery(APICALLBOOM_PARAM, - intfAccountUserAssetsFiles::myInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM, "", true, false) + intfAccountUserAssetsFiles::MyInstance[this->Schema]->makeSelectQuery(APICALLBOOM_PARAM, "", true, false) .addCol(tblAccountUserAssetsFilesBase::Fields::uasufl_uasID) .addCol(tblAccountUserAssetsFilesBase::Fields::uasufl_slfID) .addCol(tblAccountSaleablesFilesBase::Fields::slfMinCount) @@ -697,7 +702,20 @@ QVariant IMPL_ORMGET_USER(intfAccountUserAssets) { if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false) this->setSelfFilters({{tblAccountUserAssetsBase::Fields::uas_actorID, APICALLBOOM_PARAM.getActorID() }}, _filters); - return this->Select(GET_METHOD_ARGS_CALL_VALUES); + auto fnTouchQuery = [this, &_cols](ORMSelectQuery &_query) { + if (_cols.isEmpty()) + _query.addCols(this->selectableColumnNames()); + else { + _query.addCSVCols(_cols); + _cols = {}; + } + + _query.innerJoinWith(tblAccountUserAssetsBase::Relation::Saleable) + .addCols(intfAccountSaleables::MyInstance[this->Schema]->selectableColumnNames()) + ; + }; + + return this->Select(GET_METHOD_ARGS_CALL_VALUES, {}, 0, fnTouchQuery); } bool IMPL_REST_UPDATE(intfAccountUserAssets, setAsPrefered, ( @@ -738,7 +756,7 @@ bool IMPL_REST_UPDATE(intfAccountUserAssets, disablePackage, ( /******************************************************************/ //key: schema -QMap intfAccountUserAssetsFiles::myInstance; +QMap intfAccountUserAssetsFiles::MyInstance; intfAccountUserAssetsFiles::intfAccountUserAssetsFiles( // bool _isTokenBase, @@ -756,7 +774,7 @@ intfAccountUserAssetsFiles::intfAccountUserAssetsFiles( ) // intfAccountORMBase(_isTokenBase) { - intfAccountUserAssetsFiles::myInstance[_schema] = this; + intfAccountUserAssetsFiles::MyInstance[_schema] = this; } QVariant IMPL_ORMGET_USER(intfAccountUserAssetsFiles) { diff --git a/Interfaces/AAA/Accounting_Interfaces.h b/Interfaces/AAA/Accounting_Interfaces.h index b2b68b21..4107d410 100644 --- a/Interfaces/AAA/Accounting_Interfaces.h +++ b/Interfaces/AAA/Accounting_Interfaces.h @@ -60,7 +60,7 @@ class intfAccountUnitsI18N : public intfSQLBasedModule//, public intfAccountORMB public: //key: schema - static QMap myInstance; + static QMap MyInstance; // friend class intfAccountUnits; }; @@ -102,7 +102,7 @@ class intfAccountProductsI18N : public intfSQLBasedModule//, public intfAccountO public: //key: schema - static QMap myInstance; + static QMap MyInstance; // friend class intfAccountProducts; }; @@ -144,7 +144,7 @@ class intfAccountSaleablesI18N : public intfSQLBasedModule//, public intfAccount public: //key: schema - static QMap myInstance; + static QMap MyInstance; // friend class intfAccountSaleables; }; @@ -160,6 +160,10 @@ class intfAccountSaleables : public intfSQLBasedModule//, public intfAccountORMB const QList& _exclusiveRelations = {}, const QList& _exclusiveIndexes = {}); +public: + //key: schema + static QMap MyInstance; + public: virtual ORMSelectQuery makeSelectQuery(INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, const QString &_alias = {}, bool _translate = true, bool _isRoot = true); @@ -187,7 +191,7 @@ class intfAccountSaleablesFiles : public intfSQLBasedModule//, public intfAccoun public: //key: schema - static QMap myInstance; + static QMap MyInstance; // friend class intfAccountUserAssets; private slots: @@ -250,7 +254,7 @@ class intfAccountUserAssetsFiles : public intfSQLBasedModule//, public intfAccou public: //key: schema - static QMap myInstance; + static QMap MyInstance; // friend class intfAccountUserAssets; private slots: diff --git a/Interfaces/AAA/intfAccountingBasedModule.cpp b/Interfaces/AAA/intfAccountingBasedModule.cpp index e1a2bf2f..24593c1e 100644 --- a/Interfaces/AAA/intfAccountingBasedModule.cpp +++ b/Interfaces/AAA/intfAccountingBasedModule.cpp @@ -154,6 +154,9 @@ intfAccountingBasedModule::intfAccountingBasedModule( ServiceRegistry.insert(this->ServiceName, this); } +/******************************************************************\ +|** credit ********************************************************| +\******************************************************************/ stuActiveCredit intfAccountingBasedModule::activeAccountObject(quint64 _usrID) { return this->findBestMatchedCredit(_usrID); } @@ -172,7 +175,7 @@ void intfAccountingBasedModule::checkUsageIsAllowed( if (BestMatchedCredit.TTL == 0) ///@TODO: TTL must be checked throw exHTTPForbidden("[82] You don't have access to: " + this->ServiceName); - auto checkCredit = [](auto _usageIter, stuUsage _remaining, auto _type) { + auto CheckCredit = [](auto _usageIter, stuUsage _remaining, auto _type) { if (NULLABLE_HAS_VALUE(_remaining.PerDay) && *_remaining.PerDay - _usageIter.value() <= 0) throw exPaymentRequired(QString("You have not enough credit: <%1:Day:%2>").arg(_type).arg(_usageIter.key())); @@ -197,9 +200,9 @@ void intfAccountingBasedModule::checkUsageIsAllowed( continue; if (this->isUnlimited(BestMatchedCredit.MyLimitsOnParent) == false) - checkCredit(UsageIter, BestMatchedCredit.MyLimitsOnParent.value(UsageIter.key()), "Own"); + CheckCredit(UsageIter, BestMatchedCredit.MyLimitsOnParent.value(UsageIter.key()), "Own"); - checkCredit(UsageIter, ActiveCredit.Digested.Limits.value(UsageIter.key()), "Parent"); + CheckCredit(UsageIter, ActiveCredit.Digested.Limits.value(UsageIter.key()), "Parent"); } return; @@ -210,11 +213,12 @@ void intfAccountingBasedModule::checkUsageIsAllowed( for (auto UsageIter = _requestedUsage.begin(); UsageIter != _requestedUsage.end(); - UsageIter++) { + UsageIter++ + ) { if (ActiveCredit.Digested.Limits.contains(UsageIter.key()) == false) continue; - checkCredit(UsageIter, ActiveCredit.Digested.Limits.value(UsageIter.key()), "Self"); + CheckCredit(UsageIter, ActiveCredit.Digested.Limits.value(UsageIter.key()), "Self"); } } @@ -228,13 +232,13 @@ stuActiveCredit intfAccountingBasedModule::findBestMatchedCredit( QDateTime Now = ServiceCreditsInfo.DBCurrentDateTime; - auto effectiveStartDateTime = [Now](const stuAssetItem& _assetItem) -> QDateTime { + auto EffectiveStartDateTime = [Now](const stuAssetItem& _assetItem) -> QDateTime { return _assetItem.Product.prdValidFromHour //.isNull() == fasle ? QDateTime(Now.date()).addSecs(*_assetItem.Product.prdValidFromHour * 3600) : QDateTime(Now.date()); }; - auto effectiveEndDateTime = [Now](const stuAssetItem& _assetItem) -> QDateTime { + auto EffectiveEndDateTime = [Now](const stuAssetItem& _assetItem) -> QDateTime { if (NULLABLE_IS_NULL(_assetItem.Product.prdValidFromHour) || NULLABLE_IS_NULL(_assetItem.Product.prdValidToHour)) QDateTime(Now.date().addDays(1)); @@ -245,11 +249,11 @@ stuActiveCredit intfAccountingBasedModule::findBestMatchedCredit( : QDateTime(Now.date().addDays(1)).addSecs(*_assetItem.Product.prdValidToHour * 3600); }; - auto isInvalidPackage = [this, Now, effectiveStartDateTime, effectiveEndDateTime, _requestedUsage](const stuAssetItem& _assetItem) -> bool { + auto IsInvalidPackage = [this, Now, EffectiveStartDateTime, EffectiveEndDateTime, _requestedUsage](const stuAssetItem& _assetItem) -> bool { if ((_assetItem.Product.prdValidFromDate.isValid() && _assetItem.Product.prdValidFromDate > Now.date()) || (_assetItem.Product.prdValidToDate.isValid() && _assetItem.Product.prdValidToDate < Now.date()) - || (NULLABLE_HAS_VALUE(_assetItem.Product.prdValidFromHour) && Now < effectiveStartDateTime(_assetItem)) - || (NULLABLE_HAS_VALUE(_assetItem.Product.prdValidToHour) && Now > effectiveEndDateTime(_assetItem)) + || (NULLABLE_HAS_VALUE(_assetItem.Product.prdValidFromHour) && Now < EffectiveStartDateTime(_assetItem)) + || (NULLABLE_HAS_VALUE(_assetItem.Product.prdValidToHour) && Now > EffectiveEndDateTime(_assetItem)) || this->isEmpty(_assetItem.Digested.Limits) ) return false; @@ -275,13 +279,13 @@ stuActiveCredit intfAccountingBasedModule::findBestMatchedCredit( return true; }; - if (NULLABLE_HAS_VALUE(ServiceCreditsInfo.PreferedCredit) && isInvalidPackage(*ServiceCreditsInfo.PreferedCredit) == false) + if (NULLABLE_HAS_VALUE(ServiceCreditsInfo.PreferedCredit) && IsInvalidPackage(*ServiceCreditsInfo.PreferedCredit) == false) return stuActiveCredit(*ServiceCreditsInfo.PreferedCredit, NULLABLE_HAS_VALUE(ServiceCreditsInfo.ParentID), ServiceCreditsInfo.MyLimitsOnParent, -1); - auto comparePackages = [this, &effectiveEndDateTime] (const stuAssetItem& a, stuAssetItem& b) { + auto ComparePackages = [this, &EffectiveEndDateTime] (const stuAssetItem& a, stuAssetItem& b) { if (a.Product.prdValidToDate.isValid() && b.Product.prdValidToDate.isValid() == false) return -1; if (a.Product.prdValidToDate.isValid() == false && b.Product.prdValidToDate.isValid()) return 1; if (this->isUnlimited(a.Digested.Limits) && this->isUnlimited(b.Digested.Limits) == false) return -1; @@ -289,8 +293,8 @@ stuActiveCredit intfAccountingBasedModule::findBestMatchedCredit( if (NULLABLE_HAS_VALUE(a.Product.prdValidToHour) && NULLABLE_IS_NULL(b.Product.prdValidToHour)) return -1; if (NULLABLE_IS_NULL(a.Product.prdValidToHour) && NULLABLE_HAS_VALUE(b.Product.prdValidToHour)) return 1; if (NULLABLE_HAS_VALUE(a.Product.prdValidToHour) && NULLABLE_HAS_VALUE(b.Product.prdValidToHour)) { - if (effectiveEndDateTime(a) < effectiveEndDateTime(b)) return -1; - if (effectiveEndDateTime(a) > effectiveEndDateTime(b)) return 1; + if (EffectiveEndDateTime(a) < EffectiveEndDateTime(b)) return -1; + if (EffectiveEndDateTime(a) > EffectiveEndDateTime(b)) return 1; } if (a.Product.prdValidToDate.isValid() && b.Product.prdValidToDate.isValid() && a.Product.prdValidToDate != b.Product.prdValidToDate) return b.Product.prdValidToDate > a.Product.prdValidToDate ? -1 : 1; @@ -301,10 +305,11 @@ stuActiveCredit intfAccountingBasedModule::findBestMatchedCredit( for (auto AccountIter = ServiceCreditsInfo.ActiveCredits.begin(); AccountIter != ServiceCreditsInfo.ActiveCredits.end(); - AccountIter++) { + AccountIter++ + ) { const stuAssetItem& Item = AccountIter.value(); - if (isInvalidPackage(Item)) + if (IsInvalidPackage(Item)) continue; if (CandidateCredit.isEmpty()) { @@ -315,8 +320,9 @@ stuActiveCredit intfAccountingBasedModule::findBestMatchedCredit( bool Inserted = false; for (auto CandidateIter = CandidateCredit.begin(); CandidateIter != CandidateCredit.end(); - CandidateIter++) { - if (comparePackages(Item, *CandidateIter) <0) { + CandidateIter++ + ) { + if (ComparePackages(Item, *CandidateIter) < 0) { this->breakCredit(CandidateIter->Saleable.slbID); CandidateCredit.insert(CandidateIter, Item); Inserted = true; @@ -338,11 +344,11 @@ stuActiveCredit intfAccountingBasedModule::findBestMatchedCredit( QDateTime NextDigestTime; if (ActivePackage.Product.prdValidToDate.isNull() == false) { if (NULLABLE_HAS_VALUE(ActivePackage.Product.prdValidToHour)) - NextDigestTime = effectiveEndDateTime(ActivePackage); + NextDigestTime = EffectiveEndDateTime(ActivePackage); else NextDigestTime = QDateTime(ActivePackage.Product.prdValidToDate.addDays(1)); } else if (NULLABLE_HAS_VALUE(ActivePackage.Product.prdValidToHour)) - NextDigestTime = effectiveEndDateTime(ActivePackage); + NextDigestTime = EffectiveEndDateTime(ActivePackage); return stuActiveCredit(ActivePackage, NULLABLE_HAS_VALUE(ServiceCreditsInfo.ParentID), @@ -350,6 +356,9 @@ stuActiveCredit intfAccountingBasedModule::findBestMatchedCredit( NextDigestTime.isValid() ? (Now.msecsTo(NextDigestTime) / 1000) : -1); } +/******************************************************************\ +|** basket ********************************************************| +\******************************************************************/ Targoman::API::AAA::stuBasketActionResult IMPL_REST_POST(intfAccountingBasedModule, addToBasket, ( APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM, TAPI::SaleableCode_t _saleableCode, diff --git a/Interfaces/AAA/intfAccountingBasedModule.h b/Interfaces/AAA/intfAccountingBasedModule.h index 1c0adcbd..98d0ee9a 100644 --- a/Interfaces/AAA/intfAccountingBasedModule.h +++ b/Interfaces/AAA/intfAccountingBasedModule.h @@ -33,13 +33,7 @@ namespace Targoman::API::AAA { using namespace API; -//class intfAccountingBasedModuleBase -//{ -//public: -// virtual stuActiveCredit activeAccountObject(quint64 _usrID) = 0; -//}; - -class intfAccountingBasedModule : public intfSQLBasedModule //intfSQLBasedWithActionLogsModule +class intfAccountingBasedModule : public intfSQLBasedModule { Q_OBJECT diff --git a/Interfaces/Helpers/TokenHelper.cpp b/Interfaces/Helpers/TokenHelper.cpp index 2f4be2b0..1510f187 100644 --- a/Interfaces/Helpers/TokenHelper.cpp +++ b/Interfaces/Helpers/TokenHelper.cpp @@ -26,6 +26,28 @@ namespace Targoman::API::Helpers { +using namespace Targoman::Common::Configuration; + +tmplConfigurable TokenHelper::APITokenTTL( + TokenHelper::makeConfig("APITokenTTL"), + "Time to live for the api token in days", + static_cast(365), //1 year + ReturnTrueCrossValidator(), + "", + "DAYS", + "apitoken-ttl", + enuConfigSource::Arg | enuConfigSource::File); + +tmplConfigurable TokenHelper::TokenBinRefetchTime( + TokenHelper::makeConfig("TokenBinRefetchTime"), + "Token bin refetch cycle time in seconds", + static_cast(60), //1 minute + ReturnTrueCrossValidator(), + "", + "SEC", + "tokenbin-refetch-time", + enuConfigSource::Arg | enuConfigSource::File); + quint64 TokenHelper::LastFetchedTokenBinID = 0; qint64 TokenHelper::LastFetchedSecsSinceEpoch = 0; QMutex TokenHelper::Lock; @@ -34,11 +56,9 @@ QMap TokenHelper::TokenBanList; bool TokenHelper::UpdateTokenBinList() { - //every 1 minutes -#ifndef QT_DEBUG - if (QDateTime::currentSecsSinceEpoch() - TokenHelper::LastFetchedSecsSinceEpoch < 60) + if ((TokenHelper::TokenBinRefetchTime.value() > 0) + && (QDateTime::currentSecsSinceEpoch() - TokenHelper::LastFetchedSecsSinceEpoch < TokenHelper::TokenBinRefetchTime.value())) return true; -#endif QMutexLocker Locker(&TokenHelper::Lock); diff --git a/Interfaces/Helpers/TokenHelper.h b/Interfaces/Helpers/TokenHelper.h index f255bce8..1ffc38fa 100644 --- a/Interfaces/Helpers/TokenHelper.h +++ b/Interfaces/Helpers/TokenHelper.h @@ -28,6 +28,7 @@ #include #include #include "libTargomanCommon/Macros.h" +#include "libTargomanCommon/Configuration/tmplConfigurable.h" namespace Targoman::API::Helpers { @@ -46,6 +47,11 @@ struct stuTokenBanInfo { class TokenHelper { +public: + static inline QString makeConfig(const QString& _name) { return "/APIToken/" + _name; } + static Targoman::Common::Configuration::tmplConfigurable APITokenTTL; + static Targoman::Common::Configuration::tmplConfigurable TokenBinRefetchTime; + public: static bool UpdateTokenBinList(); static enuTokenBanType GetTokenBanType(const QString &_token); diff --git a/ModuleHelpers/MT/Interfaces/intfMTAccounting.h b/ModuleHelpers/MT/Interfaces/intfMTAccounting.h index 67c43302..4f8158ef 100644 --- a/ModuleHelpers/MT/Interfaces/intfMTAccounting.h +++ b/ModuleHelpers/MT/Interfaces/intfMTAccounting.h @@ -174,9 +174,9 @@ namespace tblAccountSaleablesMTBase { namespace Private { const QList ExtraORMFields = { - //ColName Type Validation Default UpBy Sort Filter Self Virt PK - { ExtraFields::slbValidityDurationInDays, S(quint32), QFV.integer(), 0, UPOwner }, - { ExtraFields::slbValidityWords, S(quint32), QFV.integer(), 0, UPOwner }, + //ColName Type Validation Default UpBy Sort Filter Self Virt PK + { ExtraFields::slbValidityDurationInDays, S(quint32), QFV.integer(), QRequired, UPOwner }, + { ExtraFields::slbValidityWords, S(quint32), QFV.integer(), QRequired, UPOwner }, }; inline const QList ExtraRelations(Q_DECL_UNUSED const QString& _schema) { diff --git a/ModuleHelpers/MT/MTHelper.cpp b/ModuleHelpers/MT/MTHelper.cpp index 5492a187..96d03a66 100644 --- a/ModuleHelpers/MT/MTHelper.cpp +++ b/ModuleHelpers/MT/MTHelper.cpp @@ -76,7 +76,7 @@ void MTHelper::registerGateway(const QString& _gatewayName, intfTranslatorGatewa if (MTHelper::RegisteredGateways.contains(_gatewayName)) throw Targoman::Common::exTargomanBase(QString("The class for gateway name `%1` has been already registered").arg(_gatewayName)); - TargomanDebug(0) << "registering MT gateway:" << _gatewayName; + TargomanDebug(5) << "registering MT gateway:" << _gatewayName; MTHelper::RegisteredGateways.insert(_gatewayName, _gateway); } @@ -112,7 +112,7 @@ void MTHelper::registerEngines() { continue; // throw exTargomanInitialization(QString("Engine %1 already registered").arg(Engine->fullName())); - TargomanDebug(0) << "registering MT engine:" + TargomanDebug(5) << "registering MT engine:" << Key << Server.SourceLang.value() << Server.DestLang.value() @@ -167,7 +167,278 @@ QVariantMap MTHelper::doTranslation( int& _translationTime ) { APICALLBOOM_PARAM.createScopeTiming("translate"); +throw exTargomanBase("not finished yet"); +/* + auto FnFindClassAndEngine = [this]( + QString _text, + const TranslationDir_t &_dir, + const QString &_engine, + bool _useSpecialClass, + QString &_class + ) -> clsEngine* { + clsEngine* TranslationEngine = nullptr; + _class = ""; + if (_useSpecialClass) { + _class = this->detectClass(_engine, _text, _dir.first); + + TranslationEngine = this->RegisteredEngines.value(stuEngineSpecs::makeFullName(_engine, _dir.first, _dir.second, _class)); + + if (TranslationEngine != nullptr) + return TranslationEngine; + } + + TranslationEngine = this->RegisteredEngines.value(stuEngineSpecs::makeFullName(_engine, _dir.first, _dir.second)); + if (TranslationEngine != nullptr) + return TranslationEngine; + + if (_dir.first == "en" || _dir.second == "en") + throw exHTTPInternalServerError(QString("Unable to find translator engine for %1_%2").arg(_dir.first).arg(_dir.second)); + + return nullptr; + }; + + //1: find _dir.first class end engine + QString Class; + clsEngine* TranslationEngine = FnFindClassAndEngine( + _text, + _dir, + _engine, + _useSpecialClass, + Class + ); + + if (TranslationEngine != nullptr) { + return this->internalDoTranslation( + APICALLBOOM_PARAM, + DerivedHelperSubmodules, + _text, + _dir, + _engine, + _useSpecialClass, + Class, + TranslationEngine, + _detailed, + _detokenize, + _preprocessTime, + _translationTime + ); + } + + //need more steps + QString TextToTranslate = _text; + TranslationDir_t Dir; + + //phase 1 + Dir = { _dir.first, "en" }; + TranslationEngine = FnFindClassAndEngine( + TextToTranslate, + Dir, + _engine, + _useSpecialClass, + Class + ); + + QVariantMap PreTranslateResult = this->internalDoTranslation( + APICALLBOOM_PARAM, + DerivedHelperSubmodules, + TextToTranslate, + Dir, + _engine, + _useSpecialClass, + Class, + TranslationEngine, + _detailed, + _detokenize, + _preprocessTime, + _translationTime + ); + + QVariantMap TranslationResultAsMap = PreTranslateResult[RESULTItems::TRANSLATION].toMap(); + if (TranslationResultAsMap.contains(RESULTItems::SIMPLE)) + TextToTranslate = TranslationResultAsMap[RESULTItems::SIMPLE].toString(); + else if (TranslationResultAsMap.contains(RESULTItems::SIMPLE)) + TextToTranslate = TranslationResultAsMap[RESULTItems::SIMPLE].toString(); +// else + + //phase 2 + Dir = { "en", _dir.second }; + TranslationEngine = FnFindClassAndEngine( + TextToTranslate, + Dir, + _engine, + _useSpecialClass, + Class + ); + + + + + + + + + + + struct stuTranslateStep { + QString FromLang; + QString ToLang; + QString Class; + clsEngine* Engine; + QString TranslatedText; + }; + QList TranslateSteps; + + if (_dir.first == "en" || _dir.second == "en") { + stuTranslateStep Step; + + Step.FromLang = _dir.first; + Step.ToLang = _dir.second; + Step.Engine = MTHelper::findEngine( + APICALLBOOM_PARAM, + _text, + _dir, + _engine, + _useSpecialClass, + Step.Class + ); + + TranslateSteps.append(Step); + } else { + + } + + + //find class and engine + QString Class; + clsEngine* TranslationEngine = MTHelper::findEngine( + APICALLBOOM_PARAM, + _text, + _dir, + _engine, + _useSpecialClass, + Class + ); + + if (TranslationEngine != nullptr) { + return this->internalDoTranslation( + APICALLBOOM_PARAM, + DerivedHelperSubmodules, + _text, + _dir, + _engine, + _useSpecialClass, + Class, + TranslationEngine, + _detailed, + _detokenize, + _preprocessTime, + _translationTime + ); + } + + + //-- pre + TranslationDir_t PreTranslateDir = { _dir.first, "en" }; + QString PreClass; + clsEngine* PreTranslationEngine = MTHelper::findEngine( + APICALLBOOM_PARAM, + _text, + PreTranslateDir, + _engine, + _useSpecialClass, + PreClass + ); + + //-- post + TranslationDir_t PostTranslateDir = { "en", _dir.second }; + QString PostClass; + clsEngine* PostTranslationEngine = MTHelper::findEngine( + APICALLBOOM_PARAM, + _text, + PostTranslateDir, + _engine, + _useSpecialClass, + PostClass + ); + + // + PreTranslateResult = this->internalDoTranslation( + APICALLBOOM_PARAM, + DerivedHelperSubmodules, + _text, + PreTranslateDir, + _engine, + _useSpecialClass, + PreClass, + PreTranslationEngine, + _detailed, + _detokenize, + _preprocessTime, + _translationTime + ); + + auto PostTranslateResult = this->internalDoTranslation( + APICALLBOOM_PARAM, + DerivedHelperSubmodules, + _text, + PostTranslateDir, + _engine, + _useSpecialClass, + PostClass, + PostTranslationEngine, + _detailed, + _detokenize, + _preprocessTime, + _translationTime + ); +*/ +} + +clsEngine* MTHelper::findEngine( + INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, + QString _text, + const TranslationDir_t& _dir, + const QString& _engine, + bool _useSpecialClass, + /*OUT*/ QString &_class +) { + clsEngine* TranslationEngine = nullptr; + + if (_useSpecialClass) { + _class = this->detectClass(_engine, _text, _dir.first); + + TranslationEngine = this->RegisteredEngines.value(stuEngineSpecs::makeFullName(_engine, _dir.first, _dir.second, _class)); + + if (TranslationEngine != nullptr) + return TranslationEngine; + } + + TranslationEngine = this->RegisteredEngines.value(stuEngineSpecs::makeFullName(_engine, _dir.first, _dir.second)); + if (TranslationEngine != nullptr) + return TranslationEngine; + + if (_dir.first == "en" || _dir.second == "en") + throw exHTTPInternalServerError(QString("Unable to find translator engine for %1_%2").arg(_dir.first).arg(_dir.second)); + + return nullptr; +} + +template +QVariantMap MTHelper::internalDoTranslation( + INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, + clsDerivedHelperSubmodules<_tokenActorType> &DerivedHelperSubmodules, + QString _text, + const TranslationDir_t& _dir, + const QString& _engine, + bool _useSpecialClass, + const QString &_class, + clsEngine* _translationEngine, + bool _detailed, + bool _detokenize, + int& _preprocessTime, + int& _translationTime +) { if (_detailed && Authorization::hasPriv(APICALLBOOM_PARAM/*, _privInfo*/, { TARGOMAN_PRIV_PREFIX + "Detailed" }) == false) throw exAuthorization("Not enought privileges to get detailed translation response."); @@ -181,23 +452,23 @@ QVariantMap MTHelper::doTranslation( QTime Timer; Timer.start(); - /*intfTranslatorGateway*/clsEngine* TranslationEngine = nullptr; - QString Class; +// clsEngine* TranslationEngine = nullptr; +// QString Class; - if (_useSpecialClass) { - Class = this->detectClass(_engine, _text, _dir.first); - TranslationEngine = this->RegisteredEngines.value(stuEngineSpecs::makeFullName(_engine, _dir.first, _dir.second, Class)); - } +// if (_useSpecialClass) { +// Class = this->detectClass(_engine, _text, _dir.first); +// TranslationEngine = this->RegisteredEngines.value(stuEngineSpecs::makeFullName(_engine, _dir.first, _dir.second, Class)); +// } - if (TranslationEngine == nullptr) { - TranslationEngine = this->RegisteredEngines.value(stuEngineSpecs::makeFullName(_engine, _dir.first, _dir.second)); +// if (TranslationEngine == nullptr) { +// TranslationEngine = this->RegisteredEngines.value(stuEngineSpecs::makeFullName(_engine, _dir.first, _dir.second)); - if (TranslationEngine == nullptr) - throw exHTTPInternalServerError("Unable to find generic translator engine"); - } +// if (TranslationEngine == nullptr) +// throw exHTTPInternalServerError("Unable to find generic translator engine"); +// } - if (TranslationEngine == nullptr) - throw exHTTPInternalServerError(QString("Unable to find %1 translator engine").arg(Class)); +// if (TranslationEngine == nullptr) +// throw exHTTPInternalServerError(QString("Unable to find %1 translator engine").arg(Class)); _text = this->preprocessText( APICALLBOOM_PARAM, @@ -209,11 +480,11 @@ QVariantMap MTHelper::doTranslation( _preprocessTime = Timer.elapsed(); Timer.restart(); - if (TranslationEngine->specs().SupportsIXML == false) + if (_translationEngine->specs().SupportsIXML == false) _text = TargomanTextProcessor::instance().ixml2Text(_text, false, false,false); /********************************/ - CachedTranslation = TranslationEngine->doTranslation( + CachedTranslation = _translationEngine->doTranslation( APICALLBOOM_PARAM, _text, _detailed, @@ -221,8 +492,8 @@ QVariantMap MTHelper::doTranslation( /********************************/ _translationTime = Timer.elapsed(); - if (Class.size() && Authorization::hasPriv(APICALLBOOM_PARAM/*, _privInfo*/, { TARGOMAN_PRIV_PREFIX + "ReportClass" })) - CachedTranslation[RESULTItems::CLASS] = Class; + if (_class.size() && Authorization::hasPriv(APICALLBOOM_PARAM/*, _privInfo*/, { TARGOMAN_PRIV_PREFIX + "ReportClass" })) + CachedTranslation[RESULTItems::CLASS] = _class; if (CachedTranslation.value(RESULTItems::ERRNO, 0).toInt() == 0) this->TranslationCache.insert(CacheKey, CachedTranslation); diff --git a/ModuleHelpers/MT/MTHelper.h b/ModuleHelpers/MT/MTHelper.h index 9bdc637b..5387520b 100644 --- a/ModuleHelpers/MT/MTHelper.h +++ b/ModuleHelpers/MT/MTHelper.h @@ -159,17 +159,44 @@ class MTHelper : public intfModuleHelper template QVariantMap doTranslation( INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, -// const QJsonObject& _privInfo, clsDerivedHelperSubmodules<_tokenActorType> &DerivedHelperSubmodules, QString _text, const TranslationDir_t& _dir, const QString& _engine, bool _useSpecialClass, - bool _detailed, bool _detokenize, + bool _detailed, + bool _detokenize, int& _preprocessTime, int& _translationTime ); +protected: + clsEngine* findEngine( + INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, + QString _text, + const TranslationDir_t& _dir, + const QString& _engine, + bool _useSpecialClass, + /*OUT*/ QString &_class + ); + + template + QVariantMap internalDoTranslation( + INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, + clsDerivedHelperSubmodules<_tokenActorType> &DerivedHelperSubmodules, + QString _text, + const TranslationDir_t& _dir, + const QString& _engine, + bool _useSpecialClass, + const QString &_class, + clsEngine* _translationEngine, + bool _detailed, + bool _detokenize, + int& _preprocessTime, + int& _translationTime + ); + +public: QString tokenize(const QString& _text, const QString& _lang); QString detokenize(const QString& _text, const QString& _lang); QString detectClass(const QString& _engine, const QString& _text, const QString& _lang); @@ -204,7 +231,7 @@ class MTHelper : public intfModuleHelper MTHelper(); Q_DISABLE_COPY(MTHelper) - QHash RegisteredEngines; + QHash RegisteredEngines; Targoman::Common::tmplBoundedCache TranslationCache; QList> CorrectionRule; QTime LastCorrectionRuleUpdateTime; diff --git a/Modules/Account/functionalTest/testAccount.hpp b/Modules/Account/functionalTest/testAccount.hpp index f7970eba..2efc30df 100644 --- a/Modules/Account/functionalTest/testAccount.hpp +++ b/Modules/Account/functionalTest/testAccount.hpp @@ -1651,7 +1651,7 @@ private slots: QVERIFY(Result.isValid()); - this->TokenJWT = Result.toString(); + this->TokenJWT = Result.toMap().value("token").toString(); QVERIFY(this->TokenJWT.isEmpty() == false); diff --git a/Modules/Account/moduleSrc/ORM/APITokens.cpp b/Modules/Account/moduleSrc/ORM/APITokens.cpp index f30962e8..a0fa5837 100644 --- a/Modules/Account/moduleSrc/ORM/APITokens.cpp +++ b/Modules/Account/moduleSrc/ORM/APITokens.cpp @@ -46,18 +46,6 @@ using namespace Helpers; using namespace Server; using namespace DBManager; -using namespace Targoman::Common::Configuration; - -tmplConfigurable APITokens::TTL( - APITokens::makeConfig("TTL"), - "Time to live for the api token in days", - static_cast(365), //1 year - ReturnTrueCrossValidator(), - "", - "TTL-DAYS", - "apitoken-ttl-days", - enuConfigSource::Arg | enuConfigSource::File); - /******************************************************/ TARGOMAN_API_SUBMODULE_IMPLEMENT(Account, APITokens); @@ -70,6 +58,11 @@ APITokens::APITokens() : tblAPITokens::Private::Indexes ) { ; } +//void APITokens::initializeModule() +//{ +// APITokenServices::instance().prepareFiltersList(); +//} + ORMSelectQuery APITokens::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const QString &_alias, Q_DECL_UNUSED bool _translate, Q_DECL_UNUSED bool _isRoot) { ORMSelectQuery Query = intfSQLBasedModule::makeSelectQuery(APICALLBOOM_PARAM, _alias, _translate); @@ -95,68 +88,8 @@ ORMSelectQuery APITokens::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBOOM_PARA return Query; } -//void APITokens::initializeModule() -//{ -// APITokenServices::instance().prepareFiltersList(); -//} - -QVariant IMPL_ORMGET_USER(APITokens) { - APITokenServices::instance().prepareFiltersList(); - - if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false) - this->setSelfFilters({{ tblAPITokens::Fields::apt_usrID, APICALLBOOM_PARAM.getActorID() }}, _filters); - - return this->Select(GET_METHOD_ARGS_CALL_VALUES); -} - -QVariant IMPL_REST_GET(APITokens, byService, ( - APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM, - QStringList _services, -// TAPI::PKsByPath_t _pksByPath, - quint64 _pageIndex, - quint16 _pageSize, - TAPI::Cols_t _cols, - TAPI::Filter_t _filters, - TAPI::OrderBy_t _orderBy -// TAPI::GroupBy_t _groupBy, -// bool _reportCount, -// bool _translate -)) { - TAPI::PKsByPath_t _pksByPath = {}; - TAPI::GroupBy_t _groupBy = {}; - bool _reportCount = true; - bool _translate = true; - - APITokenServices::instance().prepareFiltersList(); - - if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false) - this->setSelfFilters({{ tblAPITokens::Fields::apt_usrID, APICALLBOOM_PARAM.getActorID() }}, _filters); - - if (_services.isEmpty()) - throw exHTTPExpectationFailed("Services not provided"); - - if ((_services.count() == 1) && (_services.at(0).indexOf(',') >= 0)) - _services = _services.at(0).split(',', QString::SkipEmptyParts); - - auto fnTouchQuery = [&APICALLBOOM_PARAM, _translate, &_services](ORMSelectQuery &_query) { - _query.nestedInnerJoin(APITokenServices::instance().makeSelectQuery(APICALLBOOM_PARAM, "", _translate, false) - .addCol(tblAPITokenServices::Fields::aptsvc_aptID, tblAPITokenServices::Fields::aptsvc_aptID) - .innerJoinWith(tblAPITokenServices::Relation::Service) - .where({ tblService::Fields::svcName, enuConditionOperator::In, "'" + _services.join("','") + "'" }) - .groupBy(tblAPITokenServices::Fields::aptsvc_aptID) - , "tmpSearchAPIServices" - , { "tmpSearchAPIServices", tblAPITokenServices::Fields::aptsvc_aptID, - enuConditionOperator::Equal, - tblAPITokens::Name, tblAPITokens::Fields::aptID } - ); - }; - - return this->Select(GET_METHOD_ARGS_CALL_VALUES, {}, 0, fnTouchQuery); -} - stuRequestTokenResult APITokens::create( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, -// APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM, quint64 _userID, const QString &_name, const QStringList &_services @@ -242,7 +175,7 @@ stuRequestTokenResult APITokens::create( Payload, enuTokenActorType::API, QJsonObject({ { "svc", _services.join(",") } }), - APITokens::TTL.value() * 24 * 3600 + TokenHelper::APITokenTTL.value() * 24 * 3600 // _activeAccount.Privs["ssnKey"].toString() ); @@ -275,20 +208,74 @@ stuRequestTokenResult APITokens::create( return stuRequestTokenResult(APITokenID, JWT); } +QVariant IMPL_ORMGET_USER(APITokens) { + APITokenServices::instance().prepareFiltersList(); + + if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false) + this->setSelfFilters({{ tblAPITokens::Fields::apt_usrID, APICALLBOOM_PARAM.getActorID() }}, _filters); + + return this->Select(GET_METHOD_ARGS_CALL_VALUES); +} + +QVariant IMPL_REST_GET(APITokens, byService, ( + APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM, + QStringList _services, +// TAPI::PKsByPath_t _pksByPath, + quint64 _pageIndex, + quint16 _pageSize, + TAPI::Cols_t _cols, + TAPI::Filter_t _filters, + TAPI::OrderBy_t _orderBy +// TAPI::GroupBy_t _groupBy, +// bool _reportCount, +// bool _translate +)) { + TAPI::PKsByPath_t _pksByPath = {}; + TAPI::GroupBy_t _groupBy = {}; + bool _reportCount = true; + bool _translate = true; + + APITokenServices::instance().prepareFiltersList(); + + if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false) + this->setSelfFilters({{ tblAPITokens::Fields::apt_usrID, APICALLBOOM_PARAM.getActorID() }}, _filters); + + if (_services.isEmpty()) + throw exHTTPExpectationFailed("Services not provided"); + + if ((_services.count() == 1) && (_services.at(0).indexOf(',') >= 0)) + _services = _services.at(0).split(',', QString::SkipEmptyParts); + + auto fnTouchQuery = [&APICALLBOOM_PARAM, _translate, &_services](ORMSelectQuery &_query) { + _query.nestedInnerJoin(APITokenServices::instance().makeSelectQuery(APICALLBOOM_PARAM, "", _translate, false) + .addCol(tblAPITokenServices::Fields::aptsvc_aptID, tblAPITokenServices::Fields::aptsvc_aptID) + .innerJoinWith(tblAPITokenServices::Relation::Service) + .where({ tblService::Fields::svcName, enuConditionOperator::In, "'" + _services.join("','") + "'" }) + .groupBy(tblAPITokenServices::Fields::aptsvc_aptID) + , "tmpSearchAPIServices" + , { "tmpSearchAPIServices", tblAPITokenServices::Fields::aptsvc_aptID, + enuConditionOperator::Equal, + tblAPITokens::Name, tblAPITokens::Fields::aptID } + ); + }; + + return this->Select(GET_METHOD_ARGS_CALL_VALUES, {}, 0, fnTouchQuery); +} + Targoman::API::AccountModule::stuRequestTokenResult IMPL_REST_POST(APITokens, request, ( APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM, const QString &_name, - const QStringList &_services + Q_DECL_UNUSED const QStringList &_services )) { return this->create( APICALLBOOM_PARAM, APICALLBOOM_PARAM.getActorID(), - _name, - _services + _name/*, + _services*/ ); } -QString IMPL_REST_POST(APITokens, revoke, ( +/*TAPI::EncodedJWT_t*/QVariantMap IMPL_REST_POST(APITokens, revoke, ( APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM, const QString &_token, TAPI::MD5_t _pass, @@ -321,7 +308,8 @@ QString IMPL_REST_POST(APITokens, revoke, ( //---------------------------------------- makeAAADAC(DAC); - clsDACResult Result = DAC.callSP({}, + + /*clsDACResult DACResult = */DAC.callSP({}, "spToken_Revoke", { { "iUserID", APICALLBOOM_PARAM.getActorID() }, { "iPass", _pass }, @@ -336,7 +324,13 @@ QString IMPL_REST_POST(APITokens, revoke, ( NewToken ); - return NewToken; + QVariantMap Result({ + { "counter", RevokeCounter }, + }); + + Result.insert("token", NewToken); + + return Result; } bool IMPL_REST_POST(APITokens, pause, ( diff --git a/Modules/Account/moduleSrc/ORM/APITokens.h b/Modules/Account/moduleSrc/ORM/APITokens.h index df17f411..4ca814ee 100644 --- a/Modules/Account/moduleSrc/ORM/APITokens.h +++ b/Modules/Account/moduleSrc/ORM/APITokens.h @@ -285,24 +285,21 @@ class APITokens : public intfSQLBasedModule TARGOMAN_API_SUBMODULE_DEFINE(Account, APITokens); public: - static inline QString makeConfig(const QString& _name) { return "/Account/APITokens/" + _name; } - static Targoman::Common::Configuration::tmplConfigurable TTL; +// virtual void initializeModule(); + virtual ORMSelectQuery makeSelectQuery(INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, const QString &_alias = {}, bool _translate = true, bool _isRoot = true); -public: stuRequestTokenResult create( INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, -// APICALLBOOM_TYPE_JWT_USER_DECL &APICALLBOOM_PARAM, quint64 _userID, const QString &_name, const QStringList &_services = {} ); -public: -// virtual void initializeModule(); - virtual ORMSelectQuery makeSelectQuery(INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, const QString &_alias = {}, bool _translate = true, bool _isRoot = true); - private slots: QVariant ORMGET_USER("Get APITokens information") +// quint64 ORMCREATE_USER("Create a new APIToken") +// bool ORMUPDATE_USER("Update an APIToken") +// bool ORMDELETE_USER("Delete an APIToken") QVariant REST_GET( byService, @@ -332,7 +329,7 @@ private slots: "create new empty api token" ); - QString REST_POST( + /*TAPI::EncodedJWT_t*/QVariantMap REST_POST( revoke, ( APICALLBOOM_TYPE_JWT_USER_DECL &APICALLBOOM_PARAM, diff --git a/Modules/Account/moduleSrc/Payment/PaymentLogic.cpp b/Modules/Account/moduleSrc/Payment/PaymentLogic.cpp index 8f072701..4b7079c3 100644 --- a/Modules/Account/moduleSrc/Payment/PaymentLogic.cpp +++ b/Modules/Account/moduleSrc/Payment/PaymentLogic.cpp @@ -58,7 +58,7 @@ void PaymentLogic::registerGateway(const QString& _gatewayName, intfPaymentGatew if (PaymentLogic::RegisteredGateways.contains(_gatewayName)) throw Targoman::Common::exTargomanBase(QString("The class for driver name `%1` has been already registered").arg(_gatewayName)); - TargomanDebug(0) << "registering payment gateway:" << _gatewayName; + TargomanDebug(5) << "registering payment gateway:" << _gatewayName; PaymentLogic::RegisteredGateways.insert(_gatewayName, _gateway); } diff --git a/Modules/Advert/moduleSrc/Advert.cpp b/Modules/Advert/moduleSrc/Advert.cpp index 726b0e83..e18f24bf 100644 --- a/Modules/Advert/moduleSrc/Advert.cpp +++ b/Modules/Advert/moduleSrc/Advert.cpp @@ -71,9 +71,18 @@ Advert::Advert() : AdvertSchema, false, { - // day week month total - { "show", { "slbShowPerDay", {}, {}, "slbShowTotal" } }, - { "click", { "slbClicksPerDay", {}, "slbClicksPerMonth", "slbClicksTotal" } }, + { "show", { + /* day */ tblAccountSaleables::ExtraFields::slbShowPerDay, + /* week */ {}, + /* month */ {}, + /* total */ tblAccountSaleables::ExtraFields::slbShowTotal + }}, + { "click", { + /* day */ tblAccountSaleables::ExtraFields::slbClicksPerDay, + /* week */ {}, + /* month */ tblAccountSaleables::ExtraFields::slbClicksPerMonth, + /* total */ tblAccountSaleables::ExtraFields::slbClicksTotal + }}, }, &AccountUnits::instance(), // &AccountUnitsI18N::instance(), diff --git a/Modules/MT/functionalTest/testMT.hpp b/Modules/MT/functionalTest/testMT.hpp index 71628341..9a15d95e 100644 --- a/Modules/MT/functionalTest/testMT.hpp +++ b/Modules/MT/functionalTest/testMT.hpp @@ -42,6 +42,9 @@ using namespace Targoman::API::AAA; #include "Interfaces/Helpers/SecurityHelper.h" using namespace Targoman::API::Helpers; +#include "ModuleHelpers/MT/Interfaces/intfMTAccounting.h" +using namespace Targoman::API::ModuleHelpers::MT::Interfaces; + class testMT : public clsBaseTest { Q_OBJECT @@ -196,6 +199,34 @@ private slots: } } + void createSaleable_mt_ERROR_ON_no_validities() { + this->MTSaleableCode = QString("%1-s%2").arg(this->MTProductCode).arg(QRandomGenerator::global()->generate()); + + QT_TRY { + QVariant Result = callAdminAPI( + RESTClientHelper::PUT, + "MT/AccountSaleables", + {}, + { + { tblAccountSaleablesBase::Fields::slbCode, this->MTSaleableCode }, + { tblAccountSaleablesBase::Fields::slbName, "test mt Saleable 456 name" }, + { tblAccountSaleablesBase::Fields::slbDesc, "test mt Saleable 456 desc" }, + { tblAccountSaleablesBase::Fields::slb_prdID, this->MTProductID }, + { tblAccountSaleablesBase::Fields::slbType, TAPI::enuSaleableType::toStr(TAPI::enuSaleableType::Special) }, + { tblAccountSaleablesBase::Fields::slbBasePrice, 12'000 }, + { tblAccountSaleablesBase::Fields::slbInStockQty, 150 }, + { tblAccountSaleablesBase::Fields::slbVoucherTemplate, "test mt Saleable 456 vt" }, +// { tblAccountSaleablesMTBase::ExtraFields::slbValidityDurationInDays, 60 }, +// { tblAccountSaleablesMTBase::ExtraFields::slbValidityWords, 1000 }, + } + ); + } QT_CATCH (exTargomanBase &exp) { + qDebug() << "OK" << exp.what(); + } QT_CATCH (const std::exception &exp) { + QTest::qFail(exp.what(), __FILE__, __LINE__); + } + } + void createSaleable_mt() { this->MTSaleableCode = QString("%1-s%2").arg(this->MTProductCode).arg(QRandomGenerator::global()->generate()); @@ -213,6 +244,8 @@ private slots: { tblAccountSaleablesBase::Fields::slbBasePrice, 12'000 }, { tblAccountSaleablesBase::Fields::slbInStockQty, 150 }, { tblAccountSaleablesBase::Fields::slbVoucherTemplate, "test mt Saleable 456 vt" }, + { tblAccountSaleablesMTBase::ExtraFields::slbValidityDurationInDays, 60 }, + { tblAccountSaleablesMTBase::ExtraFields::slbValidityWords, 1000 }, } ); @@ -242,10 +275,10 @@ private slots: {}, { { "name", "test mt" }, - { "services", QStringList({ - "MT", - "blablabla", - }) }, +// { "services", QStringList({ +// "MT", +// "blablabla", +// }) }, }); QVERIFY(Result.isValid()); diff --git a/Modules/MT/moduleSrc/MT.cpp b/Modules/MT/moduleSrc/MT.cpp index 3295224b..405c0d4d 100644 --- a/Modules/MT/moduleSrc/MT.cpp +++ b/Modules/MT/moduleSrc/MT.cpp @@ -62,9 +62,12 @@ MT::MT() : MTSchema, true, { - // day week month total -// { "show", { "slbShowPerDay", {}, {}, "slbShowTotal" } }, -// { "click", { "slbClicksPerDay", {}, "slbClicksPerMonth", "slbClicksTotal" } }, + { "words", { + /* day */ {}, //tblAccountSaleables::ExtraFields::slbWordsPerDay, + /* week */ {}, //tblAccountSaleables::ExtraFields::slbWordsPerWeek, + /* month */ {}, //tblAccountSaleables::ExtraFields::slbWordsPerMonth, + /* total */ tblAccountSaleablesMTBase::ExtraFields::slbValidityWords + }}, }, &AccountUnits::instance(), &AccountProducts::instance(), @@ -380,19 +383,6 @@ QVariantMap IMPL_REST_GET_OR_POST(MT, Translate, ( } } -/* -QVariantMap IMPL_REST_GET_OR_POST(MT, Test, ( - const TAPI::RemoteIP_t& _REMOTE_IP, - const QString& _token, - const QString& _arg -)) { - return { - {"inputArg", _arg}, - {"info", Authorization::retrieveTokenInfo(_token, _REMOTE_IP)} - }; -} -*/ - /****************************************************************\ |** fixture *****************************************************| \****************************************************************/ diff --git a/Modules/TargomanMT/moduleSrc/TargomanMT.cpp b/Modules/TargomanMT/moduleSrc/TargomanMT.cpp index b55fe72a..a3c5f5e6 100644 --- a/Modules/TargomanMT/moduleSrc/TargomanMT.cpp +++ b/Modules/TargomanMT/moduleSrc/TargomanMT.cpp @@ -62,9 +62,18 @@ TargomanMT::TargomanMT() : TargomanMTSchema, false, { - // day week month total -// { "show", { "slbShowPerDay", {}, {}, "slbShowTotal" } }, -// { "click", { "slbClicksPerDay", {}, "slbClicksPerMonth", "slbClicksTotal" } }, +// { "show", { +// /* day */ tblAccountSaleables::ExtraFields::slbShowPerDay, +// /* week */ {}, +// /* month */ {}, +// /* total */ tblAccountSaleables::ExtraFields::slbShowTotal +// }}, +// { "click", { +// /* day */ tblAccountSaleables::ExtraFields::slbClicksPerDay, +// /* week */ {}, +// /* month */ tblAccountSaleables::ExtraFields::slbClicksPerMonth, +// /* total */ tblAccountSaleables::ExtraFields::slbClicksTotal +// }}, }, &AccountUnits::instance(), &AccountProducts::instance(), diff --git a/conf/api.conf b/conf/api.conf index c3a40f26..b3a22b03 100644 --- a/conf/api.conf +++ b/conf/api.conf @@ -3,6 +3,22 @@ # Help strings are minimal and all configurations are commented. Uncomment any # configuration that you want to change ################################################################################ +#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +# @@@ APIToken SECTION @@@ +#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +[APIToken] +# Time to live for the api token in days +# Valid values: 0 to 4294967295 +# Default value: 365 +#--------------------------------------- +;APITokenTTL = 365 + +# Token bin refetch cycle time in seconds +# Valid values: 0 to 4294967295 +# Default value: 60 +#--------------------------------------- +;TokenBinRefetchTime = 60 + #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # @@@ Classifier SECTION @@@ #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%