diff --git a/App/Server/RESTAPIRegistry.cpp b/App/Server/RESTAPIRegistry.cpp index a019d76d..aabb3086 100644 --- a/App/Server/RESTAPIRegistry.cpp +++ b/App/Server/RESTAPIRegistry.cpp @@ -222,10 +222,20 @@ void RESTAPIRegistry::registerRESTAPI( if (!FoundDoc) throw exRESTRegistry("Seems that you have not use API macro to define your API: " + MethodName); +#ifdef QT_DEBUG + QString __MethodKey = "/" + _module->moduleBaseName().replace(":", "/") + '/' + _method.name(); + __MethodKey = __MethodKey.replace(QRegularExpression("//+"), "/"); + if (__MethodKey == "/Account/User/apiUPDATEextraInfo") { + int ii; ii = 0; + } +#endif + constexpr char COMMA_SIGN[] = "$_COMMA_$"; MethodSignature = MethodSignature.trimmed().replace("','", QString("'%1'").arg(COMMA_SIGN)); - bool DQuoteStarted = false, BackslashFound = false; + bool DQuoteStarted = false, + BackslashFound = false, + InTemplateParameters = false; QString CommaReplacedMethodSignature; for (int i=0; i< MethodSignature.size(); ++i) { @@ -235,16 +245,29 @@ void RESTAPIRegistry::registerRESTAPI( else if (MethodSignature.at(i).toLatin1() == '\\') { BackslashFound = true; } else if (MethodSignature.at(i).toLatin1() == '"') { - CommaReplacedMethodSignature += '"'; + CommaReplacedMethodSignature += MethodSignature.at(i); if (BackslashFound) BackslashFound = false; else DQuoteStarted = false; } else CommaReplacedMethodSignature += MethodSignature.at(i); + + } else if (InTemplateParameters) { + if (MethodSignature.at(i).toLatin1() == ',') + CommaReplacedMethodSignature += COMMA_SIGN; + else if (MethodSignature.at(i).toLatin1() == '>') { + CommaReplacedMethodSignature += MethodSignature.at(i); + InTemplateParameters = false; + } else + CommaReplacedMethodSignature += MethodSignature.at(i); + } else if (MethodSignature.at(i).toLatin1() == '"') { - CommaReplacedMethodSignature += '"'; + CommaReplacedMethodSignature += MethodSignature.at(i); DQuoteStarted = true; + } else if (MethodSignature.at(i).toLatin1() == '<') { + CommaReplacedMethodSignature += MethodSignature.at(i); + InTemplateParameters = true; } else CommaReplacedMethodSignature += MethodSignature.at(i); } @@ -254,14 +277,6 @@ void RESTAPIRegistry::registerRESTAPI( QList parameterTypes = _method.parameterTypes(); auto ParamsParts = CommaReplacedMethodSignature.split(','); -#ifdef QT_DEBUG - QString MethodKey = "/" + _module->moduleBaseName().replace(":", "/") + '/' + _method.name(); - MethodKey = MethodKey.replace(QRegularExpression("//+"), "/"); - if (MethodKey == "/Account/OfflinePayments/apiGET") { - int ii; ii = 0; - } -#endif - for (quint8 ParamIndex=0; ParamIndexisNullable()) - throw exRESTRegistry("Nullable parameter: <"+_method.parameterNames().value(ParamIndex)+"> on method: <" + MethodName + "> must have default value" ); + throw exRESTRegistry(QString("Nullable parameter: <%1> on method: <%2> must have default value" ) + .arg(*_method.parameterNames().value(ParamIndex)) + .arg(MethodName)); else DefaultValues.append(QVariant()); } @@ -689,7 +706,10 @@ void RESTAPIRegistry::dumpAPIs() QString JWTType = ""; // if (API.APIObject->requiresJWT()) if (API.APIObject->tokenActorType() != enuTokenActorType::ANONYMOUSE) - JWTType = QString(" (JWT:%1)").arg(enuTokenActorType::toStr(API.APIObject->tokenActorType())); + JWTType = QString(" (JWT:%1%2)") + .arg(enuTokenActorType::toStr(API.APIObject->tokenActorType())) + .arg(API.APIObject->tokenIsOptional() ? "/OPTIONAL" : "") + ; TargomanDebug(5).noLabel().noquote().nospace() << (IsLastAPI ? " " : "│") << " " diff --git a/App/Server/StaticModule.cpp b/App/Server/StaticModule.cpp index a5cce9da..b0c86d02 100644 --- a/App/Server/StaticModule.cpp +++ b/App/Server/StaticModule.cpp @@ -35,7 +35,7 @@ StaticModule::StaticModule() : { ; } TAPI::RawData_t IMPL_REST_GET_OR_POST(StaticModule, openAPI_json, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM )) { gServerStats.Success.inc(); @@ -49,7 +49,7 @@ TAPI::RawData_t IMPL_REST_GET_OR_POST(StaticModule, openAPI_json, ( } QVariant IMPL_REST_GET_OR_POST(StaticModule, openAPI_yaml, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM )) { throw exHTTPMethodNotAllowed("Yaml openAPI is not implemented yet"); } @@ -57,7 +57,7 @@ QVariant IMPL_REST_GET_OR_POST(StaticModule, openAPI_yaml, ( //TAPI::ResponseRedirect_t //TAPI::FileData_t QVariant IMPL_REST_GET_OR_POST(StaticModule, swaggerui, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM )) { if (ServerCommonConfigs::SwaggerUI.value().isEmpty()) throw exHTTPNotFound("Swagger is not configured"); @@ -76,7 +76,7 @@ QVariant IMPL_REST_GET_OR_POST(StaticModule, swaggerui, ( } QVariant IMPL_REST_GET_OR_POST(StaticModule, stats_json, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, bool _full )) { gServerStats.Success.inc(); @@ -85,7 +85,7 @@ QVariant IMPL_REST_GET_OR_POST(StaticModule, stats_json, ( } QVariant IMPL_REST_GET_OR_POST(StaticModule, version, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM )) { gServerStats.Success.inc(); @@ -101,7 +101,7 @@ QVariant IMPL_REST_GET_OR_POST(StaticModule, version, ( } QVariant IMPL_REST_GET_OR_POST(StaticModule, ping, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM )) { gServerStats.Success.inc(); diff --git a/App/Server/StaticModule.h b/App/Server/StaticModule.h index b8d1e53c..492af65b 100644 --- a/App/Server/StaticModule.h +++ b/App/Server/StaticModule.h @@ -43,7 +43,7 @@ private slots: TAPI::RawData_t EXREST_GET_OR_POST( openAPI_json, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM ), "", { @@ -55,7 +55,7 @@ private slots: QVariant EXREST_GET_OR_POST( openAPI_yaml, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM ), "", { @@ -69,7 +69,7 @@ private slots: QVariant EXREST_GET_OR_POST( swaggerui, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM ), "", { @@ -80,7 +80,7 @@ private slots: QVariant EXREST_GET_OR_POST( stats_json, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, bool _full = false ), "", @@ -93,7 +93,7 @@ private slots: QVariant EXREST_GET_OR_POST( version, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM ), "", { @@ -104,7 +104,7 @@ private slots: QVariant EXREST_GET_OR_POST( ping, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM ), "", { diff --git a/App/Server/clsAPIObject.cpp b/App/Server/clsAPIObject.cpp index bb173859..bf24b14c 100644 --- a/App/Server/clsAPIObject.cpp +++ b/App/Server/clsAPIObject.cpp @@ -56,7 +56,8 @@ clsAPIObject::clsAPIObject( HasExtraMethodName(_hasExtraMethodName), Parent(_module), // RequiresJWT(false) - TokenActorType(enuTokenActorType::ANONYMOUSE) + TokenActorType(enuTokenActorType::ANONYMOUSE), + TokenIsOptional(true) { QList parameterTypes = _method.parameterTypes(); quint8 i = 0; @@ -69,14 +70,24 @@ clsAPIObject::clsAPIObject( this->ParamTypesName.append(PARAM_JWT); this->ParamTypesID.append(QMetaType::type(PARAM_JWT)); this->BaseMethod.DefaultValues[0] = {}; - } else */if (ParameterTypeName.startsWith(APICALLBOOM_TYPE_BASE_STR)) { //APICALLBOOM_TYPE_NO_JWT_DECL)) { + } else */if (ParameterTypeName.startsWith(APICALLBOOM_TYPE_BASE_STR)) { //APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL)) { --this->RequiredParamsCount; this->BaseMethod.DefaultValues.removeAt(0); -// this->RequiresJWT = true; - if (ParameterTypeName.startsWith(APICALLBOOM_TYPE_JWT_USER_DECL_STR)) + + if (ParameterTypeName.startsWith(APICALLBOOM_TYPE_JWT_USER_DECL_STR)) { + this->TokenActorType = enuTokenActorType::USER; + this->TokenIsOptional = false; + } else if (ParameterTypeName.startsWith(APICALLBOOM_TYPE_JWT_USER_OR_ANONYMOUSE_DECL_STR)) { this->TokenActorType = enuTokenActorType::USER; - else if (ParameterTypeName.startsWith(APICALLBOOM_TYPE_JWT_API_DECL_STR)) + this->TokenIsOptional = true; + } else if (ParameterTypeName.startsWith(APICALLBOOM_TYPE_JWT_API_DECL_STR)) { + this->TokenActorType = enuTokenActorType::API; + this->TokenIsOptional = false; + } else if (ParameterTypeName.startsWith(APICALLBOOM_TYPE_JWT_API_OR_ANONYMOUSE_DECL_STR)) { this->TokenActorType = enuTokenActorType::API; + this->TokenIsOptional = true; + } + } else { QByteArray ParamNameNoUnderScore = (ParamName.startsWith('_') ? ParamName.mid(1) : ParamName); this->ParamNames.append(ParamNameNoUnderScore); diff --git a/App/Server/clsAPIObject.h b/App/Server/clsAPIObject.h index 71bd82fe..a95c9f6e 100644 --- a/App/Server/clsAPIObject.h +++ b/App/Server/clsAPIObject.h @@ -87,6 +87,7 @@ class clsAPIObject : public intfAPIObject, public QObject // return this->Parent->actorType(); // } enuTokenActorType::Type tokenActorType() { return this->TokenActorType; } + bool tokenIsOptional() { return this->TokenIsOptional; } // inline bool requiresCookies() const { // return this->ParamTypesName.contains(PARAM_COOKIES); @@ -165,6 +166,7 @@ class clsAPIObject : public intfAPIObject, public QObject intfPureModule* Parent; // bool RequiresJWT; enuTokenActorType::Type TokenActorType; + bool TokenIsOptional; friend class RESTAPIRegistry; friend class OpenAPIGenerator; diff --git a/App/Server/clsRequestHandler.cpp b/App/Server/clsRequestHandler.cpp index 3f879389..2867521f 100644 --- a/App/Server/clsRequestHandler.cpp +++ b/App/Server/clsRequestHandler.cpp @@ -335,20 +335,25 @@ clsRequestHandler::stuResult clsRequestHandler::run( const QString& _pksByPath, const QString& _api ) { -// QVariantMap ResponseHeaders; - auto fnTiming = [=](const QString &_name, const QString &_desc, quint64 _nanoSecs) { this->addToTimings(_name, _desc, _nanoSecs); }; + enuTokenActorType::Type TokenActorType = _apiObject->tokenActorType(); QScopedPointer APICALLBOOM; -// if (_apiObject->requiresJWT()) - if (_apiObject->tokenActorType() == enuTokenActorType::USER) - APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_USER_DECL(fnTiming)); - else if (_apiObject->tokenActorType() == enuTokenActorType::API) - APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_API_DECL(fnTiming)); - else //enuTokenActorType::ANONYMOUSE - APICALLBOOM.reset(new APICALLBOOM_TYPE_NO_JWT_DECL(fnTiming)); + + if (TokenActorType == enuTokenActorType::USER) { + if (_apiObject->tokenIsOptional()) + APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_USER_OR_ANONYMOUSE_DECL(fnTiming)); + else + APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_USER_DECL(fnTiming)); + } else if (TokenActorType == enuTokenActorType::API) { + if (_apiObject->tokenIsOptional()) + APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_API_OR_ANONYMOUSE_DECL(fnTiming)); + else + APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_API_DECL(fnTiming)); + } else //enuTokenActorType::ANONYMOUSE + APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL(fnTiming)); try { for (auto QueryIter = _queries.begin(); QueryIter != _queries.end(); ++QueryIter) @@ -360,19 +365,30 @@ clsRequestHandler::stuResult clsRequestHandler::run( QString RemoteIP = this->toIPv4(this->Request->remoteAddress()); qhttp::THeaderHash Headers = this->Request->headers(); qhttp::THeaderHash Cookies; - TAPI::JWT_t JWT; -// enuTokenActorType::Type AcceptableActorType = _apiObject->moduleActorType(); - enuTokenActorType::Type TokenActorType = _apiObject->tokenActorType(); -// if (_apiObject->requiresJWT()) { - if (TokenActorType != enuTokenActorType::ANONYMOUSE) { - auto ServerTiming = APICALLBOOM->createScopeTiming("jwt"); + //JWT + TAPI::JWT_t JWT; + { + auto JWTServerTiming = APICALLBOOM->createScopeTiming("jwt"); + QString BearerToken; QString Auth = Headers.value("authorization"); if (Auth.startsWith("Bearer ")) { - QString BearerToken = Auth.mid(sizeof("Bearer")); + BearerToken = Auth.mid(sizeof("Bearer")).trimmed(); Headers.remove("authorization"); + } + + if (BearerToken.isEmpty()) { + if ((TokenActorType != enuTokenActorType::ANONYMOUSE) + && (_apiObject->tokenIsOptional() == false)) + throw exHTTPForbidden("No authentication header is present"); + + } else if (TokenActorType == enuTokenActorType::ANONYMOUSE) { +// throw exHTTPForbidden("The authentication header should not be sent for anonymouse apis"); + APICALLBOOM->addResponseHeader("x-tapi-jwt-warning", "no jwt needed"); + APICALLBOOM->addResponseHeaderNameToExpose("x-tapi-jwt-warning"); + } else { try { QJWT::verifyJWT( BearerToken, @@ -398,10 +414,8 @@ clsRequestHandler::stuResult clsRequestHandler::run( if (JWT.contains("typ")) TokenType = enuTokenActorType::toEnum(JWT["typ"].toString()); - /*if (TokenType == enuTokenActorType::System) { - //do nothing - } else*/ if (TokenType == enuTokenActorType::USER) { - auto ServerTiming = APICALLBOOM->createScopeTiming("jwt", "renew"); + if (TokenType == enuTokenActorType::USER) { + auto RenewJWTServerTiming = APICALLBOOM->createScopeTiming("jwt", "renew"); bool IsRenewed = false; QString NewToken = Authentication::renewExpiredJWT( @@ -423,15 +437,13 @@ clsRequestHandler::stuResult clsRequestHandler::run( throw exHTTPForbidden("API token is expired"); else throw exHTTPForbidden(QString("Unknown token type `%1`").arg(TokenType)); - } + } //catch (exJWTExpired &exp) JWT["encodedJWT"] = BearerToken; - } else - throw exHTTPForbidden("No valid authentication header is present"); - -// APICALLBOOM->setJWT(JWT); - } // if (_apiObject->requiresJWT()) + } // if (BearerToken.isEmpty() == false) { + } //jwt scope + //-- if (/*_apiObject->requiresCookies() && */Headers.value("cookie").size()) { foreach (auto Cookie, Headers.value("cookie").split(';')) { auto CookieParts = Cookie.split('='); diff --git a/Interfaces/AAA/Accounting_Interfaces.cpp b/Interfaces/AAA/Accounting_Interfaces.cpp index 5eba053b..b7104679 100644 --- a/Interfaces/AAA/Accounting_Interfaces.cpp +++ b/Interfaces/AAA/Accounting_Interfaces.cpp @@ -100,7 +100,7 @@ namespace Targoman::API::AAA { QMap intfAccountUnitsI18N::myInstance; intfAccountUnitsI18N::intfAccountUnitsI18N( - bool _isTokenBase, + // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -112,15 +112,15 @@ intfAccountUnitsI18N::intfAccountUnitsI18N( tblAccountUnitsI18NBase::Private::ORMFields + _exclusiveCols, tblAccountUnitsI18NBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountUnitsI18NBase::Private::Indexes + _exclusiveIndexes - ), - intfAccountORMBase(_isTokenBase) + ) + // intfAccountORMBase(_isTokenBase) { intfAccountUnitsI18N::myInstance[_schema] = this; } /******************************************************************/ intfAccountUnits::intfAccountUnits( - bool _isTokenBase, + // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -132,8 +132,8 @@ intfAccountUnits::intfAccountUnits( tblAccountUnitsBase::Private::ORMFields + _exclusiveCols, tblAccountUnitsBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountUnitsBase::Private::Indexes + _exclusiveIndexes - ), - intfAccountORMBase(_isTokenBase) + ) + // intfAccountORMBase(_isTokenBase) { ; } ORMSelectQuery intfAccountUnits::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const QString &_alias, Q_DECL_UNUSED bool _translate, Q_DECL_UNUSED bool _isRoot) { @@ -215,7 +215,7 @@ bool IMPL_ORMDELETE_USER(intfAccountUnits) { QMap intfAccountProductsI18N::myInstance; intfAccountProductsI18N::intfAccountProductsI18N( - bool _isTokenBase, + // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -227,15 +227,15 @@ intfAccountProductsI18N::intfAccountProductsI18N( tblAccountProductsI18NBase::Private::ORMFields + _exclusiveCols, tblAccountProductsI18NBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountProductsI18NBase::Private::Indexes + _exclusiveIndexes - ), - intfAccountORMBase(_isTokenBase) + ) + // intfAccountORMBase(_isTokenBase) { intfAccountProductsI18N::myInstance[_schema] = this; } /******************************************************************/ intfAccountProducts::intfAccountProducts( - bool _isTokenBase, + // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -247,8 +247,8 @@ intfAccountProducts::intfAccountProducts( tblAccountProductsBase::Private::ORMFields + _exclusiveCols, tblAccountProductsBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountProductsBase::Private::Indexes + _exclusiveIndexes - ), - intfAccountORMBase(_isTokenBase) + ) + // intfAccountORMBase(_isTokenBase) { ; } ORMSelectQuery intfAccountProducts::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const QString &_alias, Q_DECL_UNUSED bool _translate, Q_DECL_UNUSED bool _isRoot) { @@ -352,7 +352,7 @@ bool IMPL_ORMDELETE_USER(intfAccountProducts) { QMap intfAccountSaleablesI18N::myInstance; intfAccountSaleablesI18N::intfAccountSaleablesI18N( - bool _isTokenBase, + // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -364,15 +364,15 @@ intfAccountSaleablesI18N::intfAccountSaleablesI18N( tblAccountSaleablesI18NBase::Private::ORMFields + _exclusiveCols, tblAccountSaleablesI18NBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountSaleablesI18NBase::Private::Indexes + _exclusiveIndexes - ), - intfAccountORMBase(_isTokenBase) + ) + // intfAccountORMBase(_isTokenBase) { intfAccountSaleablesI18N::myInstance[_schema] = this; } /******************************************************************/ intfAccountSaleables::intfAccountSaleables( - bool _isTokenBase, + // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -384,8 +384,8 @@ intfAccountSaleables::intfAccountSaleables( tblAccountSaleablesBase::Private::ORMFields + _exclusiveCols, tblAccountSaleablesBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountSaleablesBase::Private::Indexes + _exclusiveIndexes - ), - intfAccountORMBase(_isTokenBase) + ) + // intfAccountORMBase(_isTokenBase) { ; } ORMSelectQuery intfAccountSaleables::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const QString &_alias, Q_DECL_UNUSED bool _translate, Q_DECL_UNUSED bool _isRoot) { @@ -511,7 +511,7 @@ bool IMPL_ORMDELETE_USER(intfAccountSaleables) { QMap intfAccountSaleablesFiles::myInstance; intfAccountSaleablesFiles::intfAccountSaleablesFiles( - bool _isTokenBase, + // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -523,8 +523,8 @@ intfAccountSaleablesFiles::intfAccountSaleablesFiles( tblAccountSaleablesFilesBase::Private::ORMFields + _exclusiveCols, tblAccountSaleablesFilesBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountSaleablesFilesBase::Private::Indexes + _exclusiveIndexes - ), - intfAccountORMBase(_isTokenBase) + ) + // intfAccountORMBase(_isTokenBase) { intfAccountSaleablesFiles::myInstance[_schema] = this; } @@ -556,7 +556,7 @@ bool IMPL_ORMDELETE_USER(intfAccountSaleablesFiles) { /******************************************************************/ /******************************************************************/ intfAccountUserAssets::intfAccountUserAssets( - bool _isTokenBase, + // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -568,8 +568,8 @@ intfAccountUserAssets::intfAccountUserAssets( tblAccountUserAssetsBase::Private::ORMFields + _exclusiveCols, tblAccountUserAssetsBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountUserAssetsBase::Private::Indexes + _exclusiveIndexes - ), - intfAccountORMBase(_isTokenBase) + ) + // intfAccountORMBase(_isTokenBase) { ; } /* @@ -741,7 +741,7 @@ bool IMPL_REST_UPDATE(intfAccountUserAssets, disablePackage, ( QMap intfAccountUserAssetsFiles::myInstance; intfAccountUserAssetsFiles::intfAccountUserAssetsFiles( - bool _isTokenBase, + // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -753,8 +753,8 @@ intfAccountUserAssetsFiles::intfAccountUserAssetsFiles( tblAccountUserAssetsFilesBase::Private::ORMFields + _exclusiveCols, tblAccountUserAssetsFilesBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountUserAssetsFilesBase::Private::Indexes + _exclusiveIndexes - ), - intfAccountORMBase(_isTokenBase) + ) + // intfAccountORMBase(_isTokenBase) { intfAccountUserAssetsFiles::myInstance[_schema] = this; } @@ -769,7 +769,7 @@ QVariant IMPL_ORMGET_USER(intfAccountUserAssetsFiles) { /******************************************************************/ /******************************************************************/ intfAccountAssetUsage::intfAccountAssetUsage( - bool _isTokenBase, + // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -781,8 +781,8 @@ intfAccountAssetUsage::intfAccountAssetUsage( tblAccountAssetUsageBase::Private::ORMFields + _exclusiveCols, tblAccountAssetUsageBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountAssetUsageBase::Private::Indexes + _exclusiveIndexes - ), - intfAccountORMBase(_isTokenBase) + ) + // intfAccountORMBase(_isTokenBase) { ; } QVariant IMPL_ORMGET_USER(intfAccountAssetUsage) { @@ -796,7 +796,7 @@ QVariant IMPL_ORMGET_USER(intfAccountAssetUsage) { /******************************************************************/ /******************************************************************/ intfAccountCoupons::intfAccountCoupons( - bool _isTokenBase, + // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -808,8 +808,8 @@ intfAccountCoupons::intfAccountCoupons( tblAccountCouponsBase::Private::ORMFields + _exclusiveCols, tblAccountCouponsBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountCouponsBase::Private::Indexes + _exclusiveIndexes - ), - intfAccountORMBase(_isTokenBase) + ) + // intfAccountORMBase(_isTokenBase) { ; } QVariant IMPL_ORMGET_USER(intfAccountCoupons) { @@ -844,7 +844,7 @@ bool IMPL_ORMDELETE_USER(intfAccountCoupons) { /******************************************************************/ /******************************************************************/ intfAccountPrizes::intfAccountPrizes( - bool _isTokenBase, + // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -856,8 +856,8 @@ intfAccountPrizes::intfAccountPrizes( tblAccountPrizesBase::Private::ORMFields + _exclusiveCols, tblAccountPrizesBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountPrizesBase::Private::Indexes + _exclusiveIndexes - ), - intfAccountORMBase(_isTokenBase) + ) + // intfAccountORMBase(_isTokenBase) { ; } QVariant IMPL_ORMGET_USER(intfAccountPrizes) { diff --git a/Interfaces/AAA/Accounting_Interfaces.h b/Interfaces/AAA/Accounting_Interfaces.h index ce839fb1..b2b68b21 100644 --- a/Interfaces/AAA/Accounting_Interfaces.h +++ b/Interfaces/AAA/Accounting_Interfaces.h @@ -32,6 +32,7 @@ using namespace Targoman::API::API; namespace Targoman::API::AAA { /******************************************************/ +/* class intfAccountORMBase { public: @@ -42,16 +43,16 @@ class intfAccountORMBase public: bool IsTokenBase; }; - +*/ /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountUnitsI18N : public intfSQLBasedModule, public intfAccountORMBase +class intfAccountUnitsI18N : public intfSQLBasedModule//, public intfAccountORMBase { Q_OBJECT public: - intfAccountUnitsI18N(bool _isTokenBase, + intfAccountUnitsI18N(//bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, @@ -64,12 +65,12 @@ class intfAccountUnitsI18N : public intfSQLBasedModule, public intfAccountORMBas }; /******************************************************/ -class intfAccountUnits : public intfSQLBasedModule, public intfAccountORMBase +class intfAccountUnits : public intfSQLBasedModule//, public intfAccountORMBase { Q_OBJECT public: - intfAccountUnits(bool _isTokenBase, + intfAccountUnits(//bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, @@ -88,12 +89,12 @@ private slots: /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountProductsI18N : public intfSQLBasedModule, public intfAccountORMBase +class intfAccountProductsI18N : public intfSQLBasedModule//, public intfAccountORMBase { Q_OBJECT public: - intfAccountProductsI18N(bool _isTokenBase, + intfAccountProductsI18N(//bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, @@ -106,12 +107,12 @@ class intfAccountProductsI18N : public intfSQLBasedModule, public intfAccountORM }; /******************************************************/ -class intfAccountProducts : public intfSQLBasedModule, public intfAccountORMBase +class intfAccountProducts : public intfSQLBasedModule//, public intfAccountORMBase { Q_OBJECT public: - intfAccountProducts(bool _isTokenBase, + intfAccountProducts(//bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, @@ -130,12 +131,12 @@ private slots: /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountSaleablesI18N : public intfSQLBasedModule, public intfAccountORMBase +class intfAccountSaleablesI18N : public intfSQLBasedModule//, public intfAccountORMBase { Q_OBJECT public: - intfAccountSaleablesI18N(bool _isTokenBase, + intfAccountSaleablesI18N(//bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, @@ -148,12 +149,12 @@ class intfAccountSaleablesI18N : public intfSQLBasedModule, public intfAccountOR }; /******************************************************/ -class intfAccountSaleables : public intfSQLBasedModule, public intfAccountORMBase +class intfAccountSaleables : public intfSQLBasedModule//, public intfAccountORMBase { Q_OBJECT public: - intfAccountSaleables(bool _isTokenBase, + intfAccountSaleables(//bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, @@ -170,12 +171,12 @@ private slots: }; /******************************************************/ -class intfAccountSaleablesFiles : public intfSQLBasedModule, public intfAccountORMBase +class intfAccountSaleablesFiles : public intfSQLBasedModule//, public intfAccountORMBase { Q_OBJECT public: - intfAccountSaleablesFiles(bool _isTokenBase, + intfAccountSaleablesFiles(//bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, @@ -199,12 +200,12 @@ private slots: /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountUserAssets : public intfSQLBasedModule, public intfAccountORMBase +class intfAccountUserAssets : public intfSQLBasedModule//, public intfAccountORMBase { Q_OBJECT public: - intfAccountUserAssets(bool _isTokenBase, + intfAccountUserAssets(//bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, @@ -236,12 +237,12 @@ private slots: }; /******************************************************/ -class intfAccountUserAssetsFiles : public intfSQLBasedModule, public intfAccountORMBase +class intfAccountUserAssetsFiles : public intfSQLBasedModule//, public intfAccountORMBase { Q_OBJECT public: - intfAccountUserAssetsFiles(bool _isTokenBase, + intfAccountUserAssetsFiles(//bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, @@ -261,12 +262,12 @@ private slots: /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountAssetUsage : public intfSQLBasedModule, public intfAccountORMBase +class intfAccountAssetUsage : public intfSQLBasedModule//, public intfAccountORMBase { Q_OBJECT public: - intfAccountAssetUsage(bool _isTokenBase, + intfAccountAssetUsage(//bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, @@ -278,12 +279,12 @@ private slots: /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountCoupons : public intfSQLBasedModule, public intfAccountORMBase +class intfAccountCoupons : public intfSQLBasedModule//, public intfAccountORMBase { Q_OBJECT public: - intfAccountCoupons(bool _isTokenBase, + intfAccountCoupons(//bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, @@ -299,12 +300,12 @@ private slots: /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountPrizes : public intfSQLBasedModule, public intfAccountORMBase +class intfAccountPrizes : public intfSQLBasedModule//, public intfAccountORMBase { Q_OBJECT public: - intfAccountPrizes(bool _isTokenBase, + intfAccountPrizes(//bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, diff --git a/Interfaces/AAA/intfAccountingBasedModule.cpp b/Interfaces/AAA/intfAccountingBasedModule.cpp index 8b4c48d2..bda51479 100644 --- a/Interfaces/AAA/intfAccountingBasedModule.cpp +++ b/Interfaces/AAA/intfAccountingBasedModule.cpp @@ -1559,7 +1559,7 @@ void checkVoucherItemForTrustedActionSanity(stuVoucherItemForTrustedAction &_dat } bool IMPL_REST_POST(intfAccountingBasedModule, processVoucherItem, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, Targoman::API::AAA::stuVoucherItemForTrustedAction _data )) { checkVoucherItemForTrustedActionSanity(_data); @@ -1568,7 +1568,7 @@ bool IMPL_REST_POST(intfAccountingBasedModule, processVoucherItem, ( } bool IMPL_REST_POST(intfAccountingBasedModule, cancelVoucherItem, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, Targoman::API::AAA::stuVoucherItemForTrustedAction _data )) { checkVoucherItemForTrustedActionSanity(_data); diff --git a/Interfaces/AAA/intfAccountingBasedModule.h b/Interfaces/AAA/intfAccountingBasedModule.h index a2432bc8..1c0adcbd 100644 --- a/Interfaces/AAA/intfAccountingBasedModule.h +++ b/Interfaces/AAA/intfAccountingBasedModule.h @@ -61,9 +61,6 @@ class intfAccountingBasedModule : public intfSQLBasedModule //intfSQLBasedWithAc ); // virtual ~intfAccountingBasedModule(); -// TAPI::enuTokenActorType::Type tokenActorType() { return _tokenActorType; } -// bool IsTokenBase() { return _tokenActorType == TAPI::enuTokenActorType::API; } - public: virtual stuActiveCredit activeAccountObject(quint64 _usrID); @@ -244,7 +241,7 @@ protected slots: bool REST_POST( processVoucherItem, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, Targoman::API::AAA::stuVoucherItemForTrustedAction _data ), "Process voucher item" @@ -253,7 +250,7 @@ protected slots: bool REST_POST( cancelVoucherItem, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, Targoman::API::AAA::stuVoucherItemForTrustedAction _data ), "Cancel voucher item" diff --git a/Interfaces/API/intfPureModule.h b/Interfaces/API/intfPureModule.h index d84fc3f1..3dded32d 100644 --- a/Interfaces/API/intfPureModule.h +++ b/Interfaces/API/intfPureModule.h @@ -77,10 +77,10 @@ using namespace TAPI; bool _reportCount, \ bool _translate -#define ANONYMOUSE_GET_METHOD_ARGS_DECL_APICALL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(APICALLBOOM_TYPE_NO_JWT_DECL) +#define ANONYMOUSE_GET_METHOD_ARGS_DECL_APICALL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL) #define USER_GET_METHOD_ARGS_DECL_APICALL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(APICALLBOOM_TYPE_JWT_USER_DECL) #define API_GET_METHOD_ARGS_DECL_APICALL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(APICALLBOOM_TYPE_JWT_API_DECL) -#define ANONYMOUSE_GET_METHOD_ARGS_IMPL_APICALL INTERNAL_GET_METHOD_ARGS_IMPL_APICALL(APICALLBOOM_TYPE_NO_JWT_IMPL) +#define ANONYMOUSE_GET_METHOD_ARGS_IMPL_APICALL INTERNAL_GET_METHOD_ARGS_IMPL_APICALL(APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL) #define USER_GET_METHOD_ARGS_IMPL_APICALL INTERNAL_GET_METHOD_ARGS_IMPL_APICALL(APICALLBOOM_TYPE_JWT_USER_IMPL) #define API_GET_METHOD_ARGS_IMPL_APICALL INTERNAL_GET_METHOD_ARGS_IMPL_APICALL(APICALLBOOM_TYPE_JWT_API_IMPL) diff --git a/Interfaces/ObjectStorage/ObjectStorageManager.cpp b/Interfaces/ObjectStorage/ObjectStorageManager.cpp index e8888a6e..5536d31c 100644 --- a/Interfaces/ObjectStorage/ObjectStorageManager.cpp +++ b/Interfaces/ObjectStorage/ObjectStorageManager.cpp @@ -186,7 +186,6 @@ quint64 ObjectStorageManager::saveFile( if (QueueRowsCount > 0) { TargomanLogDebug(5, "before queue ObjectStorageManager::processQueue(fileID: " << UploadedFileID << ")"); -#if 0 QFuture ret = QtConcurrent::run( ObjectStorageManager::processQueue, stuProcessQueueParams( @@ -198,19 +197,7 @@ quint64 ObjectStorageManager::saveFile( UploadedFileID, QueueRowsCount )); -#else - ObjectStorageManager::processQueue( - stuProcessQueueParams( - APICALLBOOM_PARAM, - APICALLBOOM_PARAM.getActorID(), - _uploadFiles, - _uploadQueue, - _uploadGateways, - UploadedFileID, - QueueRowsCount - )); -#endif TargomanLogDebug(5, "after queue ObjectStorageManager::processQueue(fileID: " << UploadedFileID << ")"); #ifdef QT_DEBUG diff --git a/Interfaces/Server/APICallBoom.cpp b/Interfaces/Server/APICallBoom.cpp index b50b752f..a3f449b2 100644 --- a/Interfaces/Server/APICallBoom.cpp +++ b/Interfaces/Server/APICallBoom.cpp @@ -129,9 +129,15 @@ void intfAPICallBoom::initialize( void intfAPICallBoom::setJWT(/*TAPI::JWT_t*/QJsonObject &_JWT) { this->Data->JWT = _JWT; } + /*TAPI::JWT_t*/QJsonObject &intfAPICallBoom::getJWT() { return this->Data->JWT; } + +bool intfAPICallBoom::isAnonymouse() { + return this->Data->JWT.isEmpty(); +} + quint64 intfAPICallBoom::getActorID(quint64 _default) { quint64 ActorID = Targoman::API::AAA::clsJWT(this->Data->JWT).actorID(); if (ActorID == 0) @@ -250,7 +256,7 @@ void intfAPICallBoom::addToTimings(const QString &_name, const QString &_desc, q this->Data->FNTiming(_name, _desc, _nanoSecs); } -template class APICALLBOOM_TYPE_NO_JWT_DECL; +template class APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL; template class APICALLBOOM_TYPE_JWT_USER_DECL; template class APICALLBOOM_TYPE_JWT_API_DECL; diff --git a/Interfaces/Server/APICallBoom.h b/Interfaces/Server/APICallBoom.h index 8d01d811..0fcb30a0 100644 --- a/Interfaces/Server/APICallBoom.h +++ b/Interfaces/Server/APICallBoom.h @@ -49,42 +49,54 @@ TARGOMAN_DEFINE_ENUM(enuTokenActorType, //TAPI_DECLARE_METATYPE_ENUM(TAPI, enuTokenActorType::Type); -#define APICALLBOOM_TYPE_BASE_STR "APICallBoom<" +#define APICALLBOOM_TYPE_BASE_STR "APICallBoom<" //-- NO JWT //just for use in api methods (.h) -#define APICALLBOOM_TYPE_NO_JWT_DECL APICallBoom //false> -#define APICALLBOOM_TYPE_NO_JWT_DECL_STR TARGOMAN_M2STR(APICALLBOOM_TYPE_NO_JWT_DECL) +#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL APICallBoom +#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL_STR TARGOMAN_M2STR(APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL) //just for use in api methods (.cpp) -#define APICALLBOOM_TYPE_NO_JWT_IMPL Q_DECL_UNUSED APICALLBOOM_TYPE_NO_JWT_DECL +#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL Q_DECL_UNUSED APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL //-- JWT : USER //just for use in api methods (.h) -#define APICALLBOOM_TYPE_JWT_USER_DECL APICallBoom //true> -#define APICALLBOOM_TYPE_JWT_USER_DECL_STR TARGOMAN_M2STR(APICALLBOOM_TYPE_JWT_USER_DECL) +#define APICALLBOOM_TYPE_JWT_USER_DECL APICallBoom +#define APICALLBOOM_TYPE_JWT_USER_DECL_STR "APICallBoom" //TARGOMAN_M2STR(APICALLBOOM_TYPE_JWT_USER_DECL) +//just for use in api methods (.cpp) +#define APICALLBOOM_TYPE_JWT_USER_IMPL Q_DECL_UNUSED APICALLBOOM_TYPE_JWT_USER_DECL +//-- JWT : USER or ANONYMOUSE +//just for use in api methods (.h) +#define APICALLBOOM_TYPE_JWT_USER_OR_ANONYMOUSE_DECL APICallBoom +#define APICALLBOOM_TYPE_JWT_USER_OR_ANONYMOUSE_DECL_STR "APICallBoom" //TARGOMAN_M2STR(APICALLBOOM_TYPE_JWT_USER_OR_ANONYMOUSE_DECL) //just for use in api methods (.cpp) -#define APICALLBOOM_TYPE_JWT_USER_IMPL Q_DECL_UNUSED APICALLBOOM_TYPE_JWT_USER_DECL +#define APICALLBOOM_TYPE_JWT_USER_OR_ANONYMOUSE_IMPL Q_DECL_UNUSED APICALLBOOM_TYPE_JWT_USER_OR_ANONYMOUSE_DECL //-- JWT : API //just for use in api methods (.h) -#define APICALLBOOM_TYPE_JWT_API_DECL APICallBoom //true> -#define APICALLBOOM_TYPE_JWT_API_DECL_STR TARGOMAN_M2STR(APICALLBOOM_TYPE_JWT_API_DECL) +#define APICALLBOOM_TYPE_JWT_API_DECL APICallBoom +#define APICALLBOOM_TYPE_JWT_API_DECL_STR "APICallBoom" //TARGOMAN_M2STR(APICALLBOOM_TYPE_JWT_API_DECL) +//just for use in api methods (.cpp) +#define APICALLBOOM_TYPE_JWT_API_IMPL Q_DECL_UNUSED APICALLBOOM_TYPE_JWT_API_DECL +//-- JWT : API or ANONYMOUSE +//just for use in api methods (.h) +#define APICALLBOOM_TYPE_JWT_API_OR_ANONYMOUSE_DECL APICallBoom +#define APICALLBOOM_TYPE_JWT_API_OR_ANONYMOUSE_DECL_STR "APICallBoom" //TARGOMAN_M2STR(APICALLBOOM_TYPE_JWT_API_OR_ANONYMOUSE_DECL) //just for use in api methods (.cpp) -#define APICALLBOOM_TYPE_JWT_API_IMPL Q_DECL_UNUSED APICALLBOOM_TYPE_JWT_API_DECL +#define APICALLBOOM_TYPE_JWT_API_OR_ANONYMOUSE_IMPL Q_DECL_UNUSED APICALLBOOM_TYPE_JWT_API_OR_ANONYMOUSE_DECL //-- -#define INTFAPICALLBOOM intfAPICallBoom +#define INTFAPICALLBOOM intfAPICallBoom //just for use in NON-api methods (.h) -#define INTFAPICALLBOOM_DECL intfAPICallBoom +#define INTFAPICALLBOOM_DECL intfAPICallBoom //just for use in NON-api methods (.cpp) -#define INTFAPICALLBOOM_IMPL Q_DECL_UNUSED intfAPICallBoom +#define INTFAPICALLBOOM_IMPL Q_DECL_UNUSED intfAPICallBoom -//#define APICALLBOOM_PARAM _APICALLBOOM -//#define APICALLBOOM_PARAM_STR TARGOMAN_M2STR(APICALLBOOM_PARAM) -#define APICALLBOOM_PARAM_STR "APICALLBOOM_PARAM" +//#define APICALLBOOM_PARAM _APICALLBOOM +//#define APICALLBOOM_PARAM_STR TARGOMAN_M2STR(APICALLBOOM_PARAM) +#define APICALLBOOM_PARAM_STR "APICALLBOOM_PARAM" namespace Targoman::API::Server { @@ -110,9 +122,11 @@ class intfAPICallBoom // virtual bool needJWT() = 0; virtual TAPI::enuTokenActorType::Type tokenActorType() = 0; + virtual bool tokenIsOptional() = 0; void setJWT(/*TAPI::JWT_t*/QJsonObject &_JWT); /*TAPI::JWT_t*/QJsonObject &getJWT(); + bool isAnonymouse(); quint64 getActorID(quint64 _default=0); QJsonObject getJWTPrivsObject(); @@ -186,7 +200,7 @@ class intfAPICallBoom QExplicitlySharedDataPointer Data; }; -template //bool _needJWT> +template class APICallBoom : public intfAPICallBoom { public: @@ -194,8 +208,8 @@ class APICallBoom : public intfAPICallBoom intfAPICallBoom(_fnTiming) { ; } -// virtual bool needJWT() { return _needJWT; } virtual TAPI::enuTokenActorType::Type tokenActorType() final { return _tokenActorType; } + virtual bool tokenIsOptional() { return _tokenIsOptional; } }; } //namespace Targoman::API::Server diff --git a/ModuleHelpers/MT/Interfaces/intfMTHelpers.h b/ModuleHelpers/MT/Interfaces/intfMTHelpers.h index cfc6022e..3f5406f3 100644 --- a/ModuleHelpers/MT/Interfaces/intfMTHelpers.h +++ b/ModuleHelpers/MT/Interfaces/intfMTHelpers.h @@ -420,12 +420,12 @@ class intfHelperORMBase typedef typename std::conditional<_tokenActorType == TAPI::enuTokenActorType::USER, APICALLBOOM_TYPE_JWT_USER_DECL, APICALLBOOM_TYPE_JWT_API_DECL>::type - ACCOUNTING_JWT_TYPE_DECL; + MT_JWT_TYPE_DECL; typedef Q_DECL_UNUSED typename std::conditional<_tokenActorType == TAPI::enuTokenActorType::USER, APICALLBOOM_TYPE_JWT_USER_DECL, APICALLBOOM_TYPE_JWT_API_DECL>::type - ACCOUNTING_JWT_TYPE_IMPL; + MT_JWT_TYPE_IMPL; public: TAPI::enuTokenActorType::Type tokenActorType() { return _tokenActorType; } diff --git a/Modules/Account/functionalTest/testAccount.hpp b/Modules/Account/functionalTest/testAccount.hpp index 01cdbc64..a20c6acc 100644 --- a/Modules/Account/functionalTest/testAccount.hpp +++ b/Modules/Account/functionalTest/testAccount.hpp @@ -334,44 +334,25 @@ private slots: } void ApproveMobile_And_Login_0999_888_1010() { - clsDAC DAC; - QJsonObject AprInfo = DAC.execQuery("", - "SELECT aprID" - " , apr_usrID" - " , aprApprovalCode" - " FROM tblApprovalRequest" - " WHERE aprApprovalKey = '+989998881010'" - " ORDER BY aprID DESC" - ) - .toJson(true) - .object() - ; - - quint64 AprID = AprInfo - .value("aprID") - .toDouble(); - QVERIFY(AprID > 0); + QVariant Result = callGuestAPI( + RESTClientHelper::POST, + "Account/fixtureGetLastApprovalRequestCodeAndMakeAsSent", + {}, + { + { "emailOrMobile", "0999-888-1010" }, + }) + ; - quint64 UserID = AprInfo - .value("apr_usrID") - .toDouble(); - QVERIFY(AprID > 0); + QVERIFY(Result.isValid()); - QString Code = AprInfo - .value("aprApprovalCode") - .toString(); + QString Code = Result.toMap().value("aprApprovalCode").toString(); QVERIFY(Code.isEmpty() == false); - DAC.execQuery("", - "UPDATE tblApprovalRequest" - " SET aprStatus = 'S'" - " , aprSentDate = NOW()" - " WHERE aprID=?", - { - AprID - }); + quint64 UserID = Result.toMap().value("apr_usrID").toULongLong(); + QVERIFY(UserID > 0); - QVariant Result = callUserAPI( + //------------------ + Result = callUserAPI( RESTClientHelper::POST, "Account/approveMobile", {}, @@ -421,7 +402,7 @@ private slots: //------------------------------------------------------- void Signup() { //df6d2338b2b8fce1ec2f6dda0a630eb0 # 987 - QVERIFY((gUserID = callUserAPI(RESTClientHelper::PUT, + QVERIFY((gUserID = callGuestAPI(RESTClientHelper::PUT, "Account/signup", {}, { { "emailOrMobile", UT_UserEmail }, { "name", "unit" }, @@ -437,7 +418,7 @@ private slots: ; //df6d2338b2b8fce1ec2f6dda0a630eb0 # 987 - QVERIFY((gAdminUserID = callUserAPI(RESTClientHelper::PUT, + QVERIFY((gAdminUserID = callGuestAPI(RESTClientHelper::PUT, "Account/signup", {}, { { "emailOrMobile", UT_AdminUserEmail }, { "name", "admin unit" }, @@ -453,7 +434,7 @@ private slots: ; clsDAC DAC; - DAC.execQuery("", "UPDATE tblUser SET tblUser.usr_rolID=? WHERE tblUser.usrID=?", {UT_AdminRoleID, gAdminUserID}); + DAC.execQuery("", "UPDATE tblUser SET tblUser.usr_rolID=? WHERE tblUser.usrID=?", { UT_AdminRoleID, gAdminUserID }); } void ResendEmailApproveCode() { @@ -507,24 +488,42 @@ private slots: } void ApproveEmail() { - clsDAC DAC; - QString Code = DAC.execQuery("", - "SELECT aprApprovalCode" - " FROM tblApprovalRequest" - " WHERE apr_usrID=?", - { - gUserID - }) - .toJson(true) - .object() - .value("aprApprovalCode") - .toString() - ; - - DAC.execQuery("", "UPDATE tblApprovalRequest SET aprStatus = 'S', aprSentDate = NOW() WHERE apr_usrID=?", - {gUserID}); +// clsDAC DAC; +// QString Code = DAC.execQuery("", +// "SELECT aprApprovalCode" +// " FROM tblApprovalRequest" +// " WHERE apr_usrID=?", +// { +// gUserID +// }) +// .toJson(true) +// .object() +// .value("aprApprovalCode") +// .toString() +// ; + +// DAC.execQuery("", "UPDATE tblApprovalRequest SET aprStatus = 'S', aprSentDate = NOW() WHERE apr_usrID=?", +// {gUserID}); + + QVariant Result = callGuestAPI( + RESTClientHelper::POST, + "Account/fixtureGetLastApprovalRequestCodeAndMakeAsSent", + {}, + { + { "emailOrMobile", UT_UserEmail }, + }) + ; - QVariant Result = callUserAPI(RESTClientHelper::POST, + QVERIFY(Result.isValid()); + + QString Code = Result.toMap().value("aprApprovalCode").toString(); + QVERIFY(Code.isEmpty() == false); + + quint64 UserID = Result.toMap().value("apr_usrID").toULongLong(); + QVERIFY(UserID > 0); + + //------------------ + Result = callUserAPI(RESTClientHelper::POST, "Account/approveEmail", {}, { @@ -537,14 +536,32 @@ private slots: } void ApproveAdminEmail() { - clsDAC DAC; - QString Code = DAC.execQuery("", "SELECT aprApprovalCode FROM tblApprovalRequest WHERE apr_usrID=?", - {gAdminUserID}).toJson(true).object().value("aprApprovalCode").toString(); +// clsDAC DAC; +// QString Code = DAC.execQuery("", "SELECT aprApprovalCode FROM tblApprovalRequest WHERE apr_usrID=?", +// {gAdminUserID}).toJson(true).object().value("aprApprovalCode").toString(); - DAC.execQuery("", "UPDATE tblApprovalRequest SET aprStatus = 'S', aprSentDate = NOW() WHERE apr_usrID=?", - {gAdminUserID}); +// DAC.execQuery("", "UPDATE tblApprovalRequest SET aprStatus = 'S', aprSentDate = NOW() WHERE apr_usrID=?", +// {gAdminUserID}); - QVariant Result = callUserAPI(RESTClientHelper::POST, + QVariant Result = callGuestAPI( + RESTClientHelper::POST, + "Account/fixtureGetLastApprovalRequestCodeAndMakeAsSent", + {}, + { + { "emailOrMobile", UT_AdminUserEmail }, + }) + ; + + QVERIFY(Result.isValid()); + + QString Code = Result.toMap().value("aprApprovalCode").toString(); + QVERIFY(Code.isEmpty() == false); + + quint64 UserID = Result.toMap().value("apr_usrID").toULongLong(); + QVERIFY(UserID > 0); + + //------------------ + Result = callUserAPI(RESTClientHelper::POST, "Account/approveEmail", {}, { @@ -552,16 +569,19 @@ private slots: { "code", Code }, { "autoLogin", false }, }); + QVERIFY(Result.isValid()); } void Login() { //5d12d36cd5f66fe3e72f7b03cbb75333 = MD5(1234 + df6d2338b2b8fce1ec2f6dda0a630eb0 # 987) QVariant Result = callUserAPI(RESTClientHelper::POST, - "Account/login",{}, { - {"emailOrMobile", UT_UserEmail}, - {"pass", "5d12d36cd5f66fe3e72f7b03cbb75333"}, - {"salt", 1234}, + "Account/login", + {}, + { + { "emailOrMobile", UT_UserEmail }, + { "pass", "5d12d36cd5f66fe3e72f7b03cbb75333" }, + { "salt", 1234} , }); QVERIFY(Result.isValid()); @@ -589,11 +609,13 @@ private slots: void LoginAgain() { //5d12d36cd5f66fe3e72f7b03cbb75333 = MD5(1234 + df6d2338b2b8fce1ec2f6dda0a630eb0 # 987) - QVariant Result = callUserAPI(RESTClientHelper::POST, - "Account/login",{}, { - {"emailOrMobile", UT_UserEmail}, - {"pass", "5d12d36cd5f66fe3e72f7b03cbb75333"}, - {"salt", 1234}, + QVariant Result = callGuestAPI(RESTClientHelper::POST, + "Account/login", + {}, + { + { "emailOrMobile", UT_UserEmail }, + { "pass", "5d12d36cd5f66fe3e72f7b03cbb75333" }, + { "salt", 1234 }, }); QVERIFY(Result.isValid()); @@ -601,7 +623,7 @@ private slots: gJWT = QJsonDocument::fromJson(QByteArray::fromBase64(gEncodedJWT.split('.').at(1).toLatin1())).object(); //5d12d36cd5f66fe3e72f7b03cbb75333 = MD5(1234 + df6d2338b2b8fce1ec2f6dda0a630eb0 # 987) - Result = callUserAPI(RESTClientHelper::POST, + Result = callGuestAPI(RESTClientHelper::POST, "Account/login",{}, { {"emailOrMobile", UT_AdminUserEmail}, {"pass", "5d12d36cd5f66fe3e72f7b03cbb75333"}, @@ -621,20 +643,38 @@ private slots: // } void CreateForgotPasswordLink() { - QVERIFY(callUserAPI(RESTClientHelper::POST, + QVERIFY(callGuestAPI(RESTClientHelper::POST, "Account/createForgotPasswordLink", {}, { { "emailOrMobile", UT_UserEmail }, }).toBool()); } void ChangePassByUUID() { - clsDAC DAC; - QString Code = DAC.execQuery("", "SELECT fprCode FROM tblForgotPassRequest WHERE fpr_usrID=?", - {gUserID}).toJson(true).object().value("fprCode").toString(); +// clsDAC DAC; +// QString Code = DAC.execQuery("", "SELECT fprCode FROM tblForgotPassRequest WHERE fpr_usrID=?", +// {gUserID}).toJson(true).object().value("fprCode").toString(); + +// DAC.execQuery("", "UPDATE tblForgotPassRequest SET fprStatus = 'S' WHERE fprCode=?", +// {Code}); + + QVariant Result = callUserAPI( + RESTClientHelper::POST, + "Account/fixtureGetLastForgotPasswordUUIDAndMakeAsSent", + {}, + { + { "emailOrMobile", UT_UserEmail }, + }) + ; + + QVERIFY(Result.isValid()); + + QString Code = Result.toMap().value("fprCode").toString(); + QVERIFY(Code.isEmpty() == false); - DAC.execQuery("", "UPDATE tblForgotPassRequest SET fprStatus = 'S' WHERE fprCode=?", - {Code}); + quint64 UserID = Result.toMap().value("fpr_usrID").toULongLong(); + QVERIFY(UserID > 0); + //------------------ //827ccb0eea8a706c4c34a16891f84e7b # 12345 QVERIFY(callUserAPI(RESTClientHelper::POST, "Account/changePassByUUID", {}, { diff --git a/Modules/Account/migrations/db/m20220907_174430_AAA_raise_400_error_in_spApprovalAccept_if_duplicates.sql b/Modules/Account/migrations/db/m20220907_174430_AAA_raise_400_error_in_spApprovalAccept_if_duplicates.sql index dc297cb0..7582cb18 100644 --- a/Modules/Account/migrations/db/m20220907_174430_AAA_raise_400_error_in_spApprovalAccept_if_duplicates.sql +++ b/Modules/Account/migrations/db/m20220907_174430_AAA_raise_400_error_in_spApprovalAccept_if_duplicates.sql @@ -109,13 +109,14 @@ BEGIN IF vByType = 'E' THEN IF (EXISTS(SELECT * FROM tblUser WHERE usrEmail = vNewKey - AND _InvalidatedAt = 0)) THEN - + AND _InvalidatedAt = 0 + AND usrID != vUserID + )) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = '400:The email address is already assigned'; END IF; - UPDATE tblUser + UPDATE tblUser SET usrEmail = vNewKey, usrApprovalState = IF(usrApprovalState IN ('N','E'), 'E', 'A'), usrStatus = IF(usrStatus IN('A','V'), 'A', usrStatus), @@ -125,8 +126,9 @@ BEGIN ELSE IF (EXISTS(SELECT * FROM tblUser WHERE usrMobile = vNewKey - AND _InvalidatedAt = 0)) THEN - + AND _InvalidatedAt = 0 + AND usrID != vUserID + )) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = '400:The mobile is already assigned'; END IF; @@ -141,7 +143,7 @@ BEGIN END IF; IF iLogin = 1 THEN - SET vSessionGUID = SUBSTRING({{dbprefix}}CommonFuncs.guid(NULL), 1, 32); + SET vSessionGUID = SUBSTRING(dev_CommonFuncs.guid(NULL), 1, 32); INSERT INTO tblActiveSessions diff --git a/Modules/Account/moduleSrc/Account.cpp b/Modules/Account/moduleSrc/Account.cpp index 3380da64..6c463517 100644 --- a/Modules/Account/moduleSrc/Account.cpp +++ b/Modules/Account/moduleSrc/Account.cpp @@ -251,7 +251,7 @@ TAPI::EncodedJWT_t Account::createJWTAndSaveToActiveSession( |* User **********************************************************| \*****************************************************************/ QString IMPL_REST_GET_OR_POST(Account, normalizePhoneNumber, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _phone, QString _country )) { @@ -259,7 +259,7 @@ QString IMPL_REST_GET_OR_POST(Account, normalizePhoneNumber, ( } QVariantMap IMPL_REST_PUT(Account, signup, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _emailOrMobile, TAPI::MD5_t _pass, QString _role, @@ -311,7 +311,7 @@ QVariantMap IMPL_REST_PUT(Account, signup, ( } TAPI::EncodedJWT_t IMPL_REST_POST(Account, approveEmail, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _email, TAPI::MD5_t _code, bool _autoLogin, @@ -355,7 +355,7 @@ TAPI::EncodedJWT_t IMPL_REST_POST(Account, approveEmail, ( } TAPI::EncodedJWT_t IMPL_REST_POST(Account, approveMobile, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, TAPI::Mobile_t _mobile, quint32 _code, bool _autoLogin, @@ -399,7 +399,7 @@ TAPI::EncodedJWT_t IMPL_REST_POST(Account, approveMobile, ( } TAPI::EncodedJWT_t IMPL_REST_GET_OR_POST(Account, login, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _emailOrMobile, TAPI::MD5_t _pass, QString _salt, @@ -431,7 +431,7 @@ TAPI::EncodedJWT_t IMPL_REST_GET_OR_POST(Account, login, ( } bool IMPL_REST_GET_OR_POST(Account, loginByMobileOnly, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, TAPI::Mobile_t _mobile, bool _signupIfNotExists, QString _signupRole, @@ -466,7 +466,7 @@ bool IMPL_REST_GET_OR_POST(Account, loginByMobileOnly, ( } bool IMPL_REST_GET_OR_POST(Account, resendApprovalCode, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _emailOrMobile )) { Authorization::validateIPAddress(APICALLBOOM_PARAM, APICALLBOOM_PARAM.getIP()); @@ -500,7 +500,7 @@ bool IMPL_REST_GET_OR_POST(Account, resendApprovalCode, ( ///@TODO: update cache for each module ///@TODO: JWT lifetime dynamic based on current hour TAPI::EncodedJWT_t IMPL_REST_GET_OR_POST(Account, loginByOAuth, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, TAPI::enuOAuthType::Type _type, QString _oAuthToken, TAPI::CommaSeparatedStringList_t _services, @@ -588,7 +588,7 @@ bool IMPL_REST_GET_OR_POST(Account, logout, ( } QString IMPL_REST_GET_OR_POST(Account, createForgotPasswordLink, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _emailOrMobile )) { Authorization::validateIPAddress(APICALLBOOM_PARAM, APICALLBOOM_PARAM.getIP()); @@ -604,45 +604,6 @@ QString IMPL_REST_GET_OR_POST(Account, createForgotPasswordLink, ( return (Type == "E" ? "email" : "mobile"); } -#ifdef QT_DEBUG -QString IMPL_REST_POST(Account, fixtureGetLastForgotPasswordUUIDAndMakeAsSent, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, - QString _emailOrMobile -)) { - QString Type = PhoneHelper::ValidateAndNormalizeEmailOrPhoneNumber(_emailOrMobile); - - QVariantMap Data = ForgotPassRequest::instance().makeSelectQuery(APICALLBOOM_PARAM) - .addCols({ - tblForgotPassRequest::Fields::fprCode, - tblForgotPassRequest::Fields::fprStatus, - }) - .innerJoinWith(tblForgotPassRequest::Relation::User) - .where({ Type == "E" ? tblUser::Fields::usrEmail : tblUser::Fields::usrMobile, enuConditionOperator::Equal, _emailOrMobile }) - .andWhere({ tblForgotPassRequest::Fields::fprRequestedVia, enuConditionOperator::Equal, Type.at(0) }) - .orderBy(tblForgotPassRequest::Fields::fprRequestDate, enuOrderDir::Descending) - .one() - ; - - QString Code = Data.value(tblForgotPassRequest::Fields::fprCode).toString(); - - if (Code.isEmpty()) - throw exHTTPNotFound("No Code could be found"); - - QString fprStatus = Data.value(tblForgotPassRequest::Fields::fprStatus).toString(); - if (fprStatus != "Sent") { - quint64 RowsCount = ForgotPassRequest::instance().makeUpdateQuery(APICALLBOOM_PARAM) - .set(tblForgotPassRequest::Fields::fprStatus, enuFPRStatus::Sent) - .where({ tblForgotPassRequest::Fields::fprCode, enuConditionOperator::Equal, Code }) - .execute(1) - ; - if (RowsCount == 0) - throw exHTTPNotFound("error in set as sent"); - } - - return Code; -} -#endif - bool IMPL_REST_GET_OR_POST(Account, changePass, ( APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM, TAPI::MD5_t _newPass, @@ -667,7 +628,7 @@ bool IMPL_REST_GET_OR_POST(Account, changePass, ( } bool IMPL_REST_GET_OR_POST(Account, changePassByUUID, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _emailOrMobile, QString _uuid, TAPI::MD5_t _newPass @@ -732,7 +693,7 @@ void Account::internalCheckBasketVoucherExpirity( } bool IMPL_REST_GET(Account, checkBasketVoucherExpirity, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM )) { ///@TODO: must be implemented @@ -1282,7 +1243,7 @@ Targoman::API::AAA::stuVoucher Account::payAndProcessBasket( * @return */ Targoman::API::AAA::stuVoucher IMPL_REST_POST(Account, approveOnlinePayment, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _paymentKey, // QString _domain, TAPI::JSON_t _pgResponse @@ -2288,8 +2249,70 @@ bool IMPL_REST_POST(Account, checkVoucherTTL, ( |** fixture *****************************************************| \****************************************************************/ #ifdef QT_DEBUG +QVariant IMPL_REST_POST(Account, fixtureGetLastForgotPasswordUUIDAndMakeAsSent, ( + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, + QString _emailOrMobile +)) { + QString Type = PhoneHelper::ValidateAndNormalizeEmailOrPhoneNumber(_emailOrMobile); + + QVariant Data = ForgotPassRequest::instance().makeSelectQuery(APICALLBOOM_PARAM) + .innerJoinWith(tblForgotPassRequest::Relation::User) + .where({ Type == "E" ? tblUser::Fields::usrEmail : tblUser::Fields::usrMobile, enuConditionOperator::Equal, _emailOrMobile }) + .andWhere({ tblForgotPassRequest::Fields::fprRequestedVia, enuConditionOperator::Equal, Type.at(0) }) + .orderBy(tblForgotPassRequest::Fields::fprRequestDate, enuOrderDir::Descending) + .one() + ; + + tblForgotPassRequest::DTO ForgotPassRequestDTO; + ForgotPassRequestDTO.fromJson(QJsonObject::fromVariantMap(Data.toMap())); + + if (ForgotPassRequestDTO.fprCode.isEmpty()) + throw exHTTPNotFound("No Code could be found"); + + if (ForgotPassRequestDTO.fprStatus != enuFPRStatus::Sent) { + quint64 RowsCount = ForgotPassRequest::instance().makeUpdateQuery(APICALLBOOM_PARAM) + .set(tblForgotPassRequest::Fields::fprStatus, enuFPRStatus::Sent) + .where({ tblForgotPassRequest::Fields::fprID, enuConditionOperator::Equal, ForgotPassRequestDTO.fprID }) + .execute(1) + ; + if (RowsCount == 0) + throw exHTTPNotFound("error in set as sent"); + } + + return ForgotPassRequestDTO.toJson(); +} + +QVariant IMPL_REST_POST(Account, fixtureGetLastApprovalRequestCodeAndMakeAsSent, ( + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, + QString _emailOrMobile +)) { + QString Type = PhoneHelper::ValidateAndNormalizeEmailOrPhoneNumber(_emailOrMobile); + + tblApprovalRequest::DTO ApprovalRequestDTO = ApprovalRequest::instance().makeSelectQuery(APICALLBOOM_PARAM) + .where({ tblApprovalRequest::Fields::aprApprovalKey, enuConditionOperator::Equal, _emailOrMobile }) + .orderBy(tblApprovalRequest::Fields::aprID, enuOrderDir::Descending) + .one() + ; + + if (ApprovalRequestDTO.aprApprovalCode.isEmpty()) + throw exHTTPNotFound("No Code could be found"); + + if (ApprovalRequestDTO.aprStatus != enuAPRStatus::Sent) { + quint64 RowsCount = ApprovalRequest::instance().makeUpdateQuery(APICALLBOOM_PARAM) + .set(tblApprovalRequest::Fields::aprStatus, enuAPRStatus::Sent) + .set(tblApprovalRequest::Fields::aprSentDate, DBExpression::NOW()) + .where({ tblApprovalRequest::Fields::aprID, enuConditionOperator::Equal, ApprovalRequestDTO.aprID }) + .execute(1) + ; + if (RowsCount == 0) + throw exHTTPNotFound("error in set as sent"); + } + + return ApprovalRequestDTO.toJson(); +} + QVariant IMPL_REST_POST(Account, fixtureSetup, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _random )) { QVariantMap Result; @@ -2539,7 +2562,7 @@ QVariant IMPL_REST_POST(Account, fixtureSetup, ( } QVariant IMPL_REST_POST(Account, fixtureCleanup, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _random )) { QVariantMap Result; @@ -2754,7 +2777,7 @@ QVariant IMPL_REST_POST(Account, fixtureCleanup, ( ///@TODO: not tested bool IMPL_REST_POST(Account, fixtureApproveEmail, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _email )) { clsDAC DAC; @@ -2794,7 +2817,7 @@ bool IMPL_REST_POST(Account, fixtureApproveEmail, ( ///@TODO: not tested bool IMPL_REST_POST(Account, fixtureApproveMobile, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, TAPI::Mobile_t _mobile )) { clsDAC DAC; diff --git a/Modules/Account/moduleSrc/Account.h b/Modules/Account/moduleSrc/Account.h index c0ae922d..88a1e842 100644 --- a/Modules/Account/moduleSrc/Account.h +++ b/Modules/Account/moduleSrc/Account.h @@ -85,7 +85,7 @@ private slots: QString REST_GET_OR_POST( normalizePhoneNumber, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _phone, QString _country ), @@ -95,7 +95,7 @@ private slots: QVariantMap REST_PUT( signup, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _emailOrMobile, TAPI::MD5_t _pass, QString _role = "BaseUser", @@ -112,7 +112,7 @@ private slots: TAPI::EncodedJWT_t REST_POST( approveEmail, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _email, TAPI::MD5_t _code, bool _autoLogin = false, @@ -127,7 +127,7 @@ private slots: TAPI::EncodedJWT_t REST_POST( approveMobile, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, TAPI::Mobile_t _mobile, quint32 _code, bool _autoLogin = false, @@ -142,7 +142,7 @@ private slots: TAPI::EncodedJWT_t REST_GET_OR_POST( login, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _emailOrMobile, TAPI::MD5_t _pass, QString _salt, @@ -158,7 +158,7 @@ private slots: bool REST_GET_OR_POST( loginByMobileOnly, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, TAPI::Mobile_t _mobile, bool _signupIfNotExists = false, QString _signupRole = "BaseUser", @@ -181,7 +181,7 @@ private slots: bool REST_GET_OR_POST( resendApprovalCode, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _emailOrMobile ), "Recreate (if expired) approval code and resend last valid code to the email or mobile." @@ -190,7 +190,7 @@ private slots: // bool REST_PUT( // requestMobileVerifyCode, // ( -// APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, +// APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, // TAPI::Mobile_t _mobile // ), // "Send verification code for provided mobile." @@ -199,7 +199,7 @@ private slots: // TAPI::EncodedJWT_t REST_PUT( // verifyLoginByMobileCode, // ( -// APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, +// APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, // TAPI::Mobile_t _mobile, // quint32 _code, // TAPI::CommaSeparatedStringList_t _services = {}, @@ -213,7 +213,7 @@ private slots: TAPI::EncodedJWT_t REST_GET_OR_POST( loginByOAuth, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, TAPI::enuOAuthType::Type _type, QString _oAuthToken, TAPI::CommaSeparatedStringList_t _services = {}, @@ -226,7 +226,7 @@ private slots: // Targoman::API::AccountModule::stuMultiJWT REST_GET_OR_POST( // refreshJWT, // ( -// APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, +// APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, // TAPI::JWT_t _loginJWT, // QString _services = {} // ), @@ -244,23 +244,12 @@ private slots: QString REST_GET_OR_POST( createForgotPasswordLink, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _emailOrMobile ), "Create a forgot password request returning a UUID for the requiest" ) -#ifdef QT_DEBUG - QString REST_POST( - fixtureGetLastForgotPasswordUUIDAndMakeAsSent, - ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, - QString _emailOrMobile - ), - "fixture: Get Last Forgot Password UUID And Make As Sent" - ) -#endif - bool REST_GET_OR_POST( changePass, ( @@ -276,7 +265,7 @@ private slots: bool REST_GET_OR_POST( changePassByUUID, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _emailOrMobile, QString _uuid, TAPI::MD5_t _newPass @@ -345,7 +334,7 @@ private slots: bool REST_GET( checkBasketVoucherExpirity, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM ), "Check Vouchers for expirity. called by garbage collector" ) @@ -398,7 +387,7 @@ private slots: Targoman::API::AAA::stuVoucher REST_POST( approveOnlinePayment, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _paymentKey, // QString _domain, TAPI::JSON_t _pgResponse @@ -494,10 +483,28 @@ private slots: ) #ifdef QT_DEBUG + QVariant REST_POST( + fixtureGetLastForgotPasswordUUIDAndMakeAsSent, + ( + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, + QString _emailOrMobile + ), + "fixture: Get Last Forgot Password UUID And Make As Sent" + ) + + QVariant REST_POST( + fixtureGetLastApprovalRequestCodeAndMakeAsSent, + ( + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, + QString _emailOrMobile + ), + "fixture: Get Last Approval Request Code And Make As Sent" + ) + QVariant REST_POST( fixtureSetup, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _random = {} ), "Create sample data. give random=1 to auto generate random number" @@ -506,7 +513,7 @@ private slots: QVariant REST_POST( fixtureCleanup, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _random = {} ), "Cleanup sample data" @@ -514,7 +521,7 @@ private slots: bool REST_POST( fixtureApproveEmail, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _email ), "Approve Email Address directly" @@ -522,7 +529,7 @@ private slots: bool REST_POST( fixtureApproveMobile, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, TAPI::Mobile_t _mobile ), "Approve Mobile directly" diff --git a/Modules/Account/moduleSrc/ORM/ApprovalRequest.cpp b/Modules/Account/moduleSrc/ORM/ApprovalRequest.cpp index 449a5bd5..cd5baa5b 100644 --- a/Modules/Account/moduleSrc/ORM/ApprovalRequest.cpp +++ b/Modules/Account/moduleSrc/ORM/ApprovalRequest.cpp @@ -85,7 +85,7 @@ bool IMPL_ORMDELETE_USER(ApprovalRequest) { } QVariant IMPL_REST_GET_OR_POST(ApprovalRequest, timerInfo, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _emailOrMobile )) { Authorization::validateIPAddress(APICALLBOOM_PARAM, APICALLBOOM_PARAM.getIP()); diff --git a/Modules/Account/moduleSrc/ORM/ApprovalRequest.h b/Modules/Account/moduleSrc/ORM/ApprovalRequest.h index efba0318..89feb744 100644 --- a/Modules/Account/moduleSrc/ORM/ApprovalRequest.h +++ b/Modules/Account/moduleSrc/ORM/ApprovalRequest.h @@ -83,7 +83,7 @@ namespace tblApprovalRequest { { Fields::apr_usrID, S(NULLABLE_TYPE(quint64)), QFV.integer().minValue(1), QInvalid, UPNone }, { Fields::aprRequestedFor, S(Targoman::API::AccountModule::enuApprovalType::Type), QFV, Targoman::API::AccountModule::enuApprovalType::Email, UPNone }, { Fields::aprApprovalKey, S(QString), QFV.allwaysInvalid(), QRequired, UPNone, false, false }, - { Fields::aprApprovalCode, S(QString), QFV.asciiAlNum().maxLenght(32), QRequired, UPNone, false, false, false, false, false, false }, + { Fields::aprApprovalCode, S(QString), QFV.asciiAlNum().maxLenght(32), QRequired, UPNone, false, false }, //, false, false, false, false }, { Fields::aprSentDate, S(NULLABLE_TYPE(TAPI::DateTime_t)), QFV, QNull, UPAdmin }, { Fields::aprApplyDate, S(NULLABLE_TYPE(TAPI::DateTime_t)), QFV, QNull, UPNone }, { Fields::aprStatus, ORM_STATUS_FIELD(Targoman::API::AccountModule::enuAPRStatus, Targoman::API::AccountModule::enuAPRStatus::New) }, @@ -136,7 +136,7 @@ private slots: QVariant REST_GET_OR_POST( timerInfo, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _emailOrMobile ), "Returns TTL remained for Approval Request based on email or mobile" diff --git a/Modules/Account/moduleSrc/ORM/Payments.cpp b/Modules/Account/moduleSrc/ORM/Payments.cpp index 3f1f4a7b..887c5895 100644 --- a/Modules/Account/moduleSrc/ORM/Payments.cpp +++ b/Modules/Account/moduleSrc/ORM/Payments.cpp @@ -78,7 +78,7 @@ QVariant IMPL_ORMGET_USER(OnlinePayments) { * this proxy received GET and POST and make GET call to the clients callback */ QVariant IMPL_REST_GET_OR_POST(OnlinePayments, paymentCallback, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _paymentKey )) { //curl -X POST 'http://localhost:10000/rest/v1/Account/OnlinePayments/paymentCallback?paymentKey=11&q1=qv1' -H 'content-type:application/json' -d '{"d1":"dv1"}' @@ -121,7 +121,7 @@ QVariant IMPL_REST_GET_OR_POST(OnlinePayments, paymentCallback, ( #ifdef QT_DEBUG QVariant IMPL_REST_GET_OR_POST(OnlinePayments, devTestPayPage, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _paymentKey, Q_DECL_UNUSED QString _trackID, QString _callback @@ -220,7 +220,7 @@ curl -v -H 'accept: application/json' -X 'GET' 'http://127.0.0.1:10000/rest/v1/A } QVariant IMPL_REST_GET_OR_POST(OnlinePayments, devTestCallbackPage, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _paymentKey, QString _result )) { diff --git a/Modules/Account/moduleSrc/ORM/Payments.h b/Modules/Account/moduleSrc/ORM/Payments.h index 6a4388ee..832e7634 100644 --- a/Modules/Account/moduleSrc/ORM/Payments.h +++ b/Modules/Account/moduleSrc/ORM/Payments.h @@ -138,7 +138,7 @@ private slots: QVariant EXREST_GET_OR_POST( paymentCallback, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _paymentKey ), "Payment callback proxy", @@ -151,7 +151,7 @@ private slots: QVariant REST_GET_OR_POST( devTestPayPage, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _paymentKey, QString _trackID, QString _callback = {} @@ -162,7 +162,7 @@ private slots: QVariant REST_GET_OR_POST( devTestCallbackPage, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _paymentKey, QString _result ), diff --git a/Modules/Advert/moduleSrc/Advert.cpp b/Modules/Advert/moduleSrc/Advert.cpp index 6e688dcc..77020855 100644 --- a/Modules/Advert/moduleSrc/Advert.cpp +++ b/Modules/Advert/moduleSrc/Advert.cpp @@ -258,14 +258,14 @@ QVariantMap Advert::getCustomUserAssetFieldsForQuery( //} Targoman::API::AdvertModule::stuAdvert IMPL_REST_GET(Advert, newBanner, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _location, Targoman::API::AdvertModule::enuAdvertOrder::Type _order )) { } Targoman::API::AdvertModule::stuAdvert IMPL_REST_GET(Advert, newText, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, QString _location, Targoman::API::AdvertModule::enuAdvertOrder::Type _order, const QString _keywords @@ -273,7 +273,7 @@ Targoman::API::AdvertModule::stuAdvert IMPL_REST_GET(Advert, newText, ( } QString IMPL_REST_GET(Advert, retrieveURL, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, quint64 _id, TAPI::IPv4_t _clientIP, QString _agent diff --git a/Modules/Advert/moduleSrc/Advert.h b/Modules/Advert/moduleSrc/Advert.h index 2ce96c36..9c02ca96 100644 --- a/Modules/Advert/moduleSrc/Advert.h +++ b/Modules/Advert/moduleSrc/Advert.h @@ -118,7 +118,7 @@ protected slots: Targoman::API::AdvertModule::stuAdvert REST_GET( newBanner, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _location, Targoman::API::AdvertModule::enuAdvertOrder::Type _order ), @@ -128,7 +128,7 @@ protected slots: Targoman::API::AdvertModule::stuAdvert REST_GET( newText, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, QString _location, Targoman::API::AdvertModule::enuAdvertOrder::Type _order, QString _keywords @@ -139,7 +139,7 @@ protected slots: QString REST_GET( retrieveURL, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, quint64 _id, TAPI::IPv4_t _clientIP, QString _agent diff --git a/Modules/Advert/moduleSrc/ORM/Accounting.cpp b/Modules/Advert/moduleSrc/ORM/Accounting.cpp index 8075cad2..47408cf9 100644 --- a/Modules/Advert/moduleSrc/ORM/Accounting.cpp +++ b/Modules/Advert/moduleSrc/ORM/Accounting.cpp @@ -37,7 +37,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountUnits) AccountUnits::AccountUnits() : intfAccountUnits( - false, +// false, AdvertSchema, tblAccountUnits::Private::ExtraORMFields, tblAccountUnits::Private::ExtraRelations, @@ -51,7 +51,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountUnitsI18N) AccountUnitsI18N::AccountUnitsI18N() : intfAccountUnitsI18N( - false, +// false, AdvertSchema, tblAccountUnitsI18N::Private::ExtraORMFields, tblAccountUnitsI18N::Private::ExtraRelations, @@ -65,7 +65,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountProducts) AccountProducts::AccountProducts() : intfAccountProducts( - false, +// false, AdvertSchema, tblAccountProducts::Private::ExtraORMFields, tblAccountProducts::Private::ExtraRelations, @@ -79,7 +79,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountProductsI18N) AccountProductsI18N::AccountProductsI18N() : intfAccountProductsI18N( - false, +// false, AdvertSchema, tblAccountProductsI18N::Private::ExtraORMFields, tblAccountProductsI18N::Private::ExtraRelations, @@ -93,7 +93,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountSaleables) AccountSaleables::AccountSaleables() : intfAccountSaleables( - false, +// false, AdvertSchema, tblAccountSaleables::Private::ExtraORMFields, tblAccountSaleables::Private::ExtraRelations, @@ -107,7 +107,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountSaleablesI18N) AccountSaleablesI18N::AccountSaleablesI18N() : intfAccountSaleablesI18N( - false, +// false, AdvertSchema, tblAccountSaleablesI18N::Private::ExtraORMFields, tblAccountSaleablesI18N::Private::ExtraRelations, @@ -119,7 +119,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountSaleablesFiles) AccountSaleablesFiles::AccountSaleablesFiles() : intfAccountSaleablesFiles( - false, +// false, AdvertSchema, tblAccountSaleablesFiles::Private::ExtraORMFields, tblAccountSaleablesFiles::Private::ExtraRelations, @@ -133,7 +133,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountUserAssets) AccountUserAssets::AccountUserAssets() : intfAccountUserAssets( - false, +// false, AdvertSchema, tblAccountUserAssets::Private::ExtraORMFields, tblAccountUserAssets::Private::ExtraRelations, @@ -145,7 +145,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountUserAssetsFiles) AccountUserAssetsFiles::AccountUserAssetsFiles() : intfAccountUserAssetsFiles( - false, +// false, AdvertSchema, tblAccountUserAssetsFiles::Private::ExtraORMFields, tblAccountUserAssetsFiles::Private::ExtraRelations, @@ -159,7 +159,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountAssetUsage) AccountAssetUsage::AccountAssetUsage() : intfAccountAssetUsage( - false, +// false, AdvertSchema, tblAccountAssetUsage::Private::ExtraORMFields, tblAccountAssetUsage::Private::ExtraRelations, @@ -173,7 +173,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountCoupons) AccountCoupons::AccountCoupons() : intfAccountCoupons( - false, +// false, AdvertSchema, tblAccountCoupons::Private::ExtraORMFields, tblAccountCoupons::Private::ExtraRelations, diff --git a/Modules/FormalityChecker/FormalityChecker.cpp b/Modules/FormalityChecker/FormalityChecker.cpp index 0d72f44c..a00482a3 100644 --- a/Modules/FormalityChecker/FormalityChecker.cpp +++ b/Modules/FormalityChecker/FormalityChecker.cpp @@ -39,7 +39,7 @@ void FormalityChecker::initializeModule() { } QString IMPL_REST_GET_OR_POST(FormalityChecker, check, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, const QString _text, const TAPI::ISO639_2_t& _lang )) { diff --git a/Modules/FormalityChecker/FormalityChecker.h b/Modules/FormalityChecker/FormalityChecker.h index 614c1ee7..ff7a9c4b 100644 --- a/Modules/FormalityChecker/FormalityChecker.h +++ b/Modules/FormalityChecker/FormalityChecker.h @@ -44,7 +44,7 @@ private slots: QString REST_GET_OR_POST( check, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, const QString _text, const TAPI::ISO639_2_t& _lang ), diff --git a/Modules/MT/moduleSrc/ORM/Accounting.cpp b/Modules/MT/moduleSrc/ORM/Accounting.cpp index 3c9861c2..90444572 100644 --- a/Modules/MT/moduleSrc/ORM/Accounting.cpp +++ b/Modules/MT/moduleSrc/ORM/Accounting.cpp @@ -35,7 +35,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(MT, AccountUnits) AccountUnits::AccountUnits() : intfAccountUnits( - true, +// true, MTSchema, tblAccountUnits::Private::ExtraORMFields, tblAccountUnits::Private::ExtraRelations, @@ -49,7 +49,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(MT, AccountUnitsI18N) AccountUnitsI18N::AccountUnitsI18N() : intfAccountUnitsI18N( - true, +// true, MTSchema, tblAccountUnitsI18N::Private::ExtraORMFields, tblAccountUnitsI18N::Private::ExtraRelations, @@ -63,7 +63,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(MT, AccountProducts) AccountProducts::AccountProducts() : intfAccountProducts( - true, +// true, MTSchema, tblAccountProducts::Private::ExtraORMFields, tblAccountProducts::Private::ExtraRelations, @@ -77,7 +77,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(MT, AccountProductsI18N) AccountProductsI18N::AccountProductsI18N() : intfAccountProductsI18N( - true, +// true, MTSchema, tblAccountProductsI18N::Private::ExtraORMFields, tblAccountProductsI18N::Private::ExtraRelations, @@ -91,7 +91,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(MT, AccountSaleables) AccountSaleables::AccountSaleables() : intfAccountSaleables( - true, +// true, MTSchema, tblAccountSaleables::Private::ExtraORMFields, tblAccountSaleables::Private::ExtraRelations, @@ -105,7 +105,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(MT, AccountSaleablesI18N) AccountSaleablesI18N::AccountSaleablesI18N() : intfAccountSaleablesI18N( - true, +// true, MTSchema, tblAccountSaleablesI18N::Private::ExtraORMFields, tblAccountSaleablesI18N::Private::ExtraRelations, @@ -117,7 +117,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(MT, AccountSaleablesFiles) AccountSaleablesFiles::AccountSaleablesFiles() : intfAccountSaleablesFiles( - true, +// true, MTSchema, tblAccountSaleablesFiles::Private::ExtraORMFields, tblAccountSaleablesFiles::Private::ExtraRelations, @@ -131,7 +131,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(MT, AccountUserAssets) AccountUserAssets::AccountUserAssets() : intfAccountUserAssets( - true, +// true, MTSchema, tblAccountUserAssets::Private::ExtraORMFields, tblAccountUserAssets::Private::ExtraRelations, @@ -143,7 +143,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(MT, AccountUserAssetsFiles) AccountUserAssetsFiles::AccountUserAssetsFiles() : intfAccountUserAssetsFiles( - true, +// true, MTSchema, tblAccountUserAssetsFiles::Private::ExtraORMFields, tblAccountUserAssetsFiles::Private::ExtraRelations, @@ -157,7 +157,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(MT, AccountAssetUsage) AccountAssetUsage::AccountAssetUsage() : intfAccountAssetUsage( - true, +// true, MTSchema, tblAccountAssetUsage::Private::ExtraORMFields, tblAccountAssetUsage::Private::ExtraRelations, @@ -171,7 +171,7 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(MT, AccountCoupons) AccountCoupons::AccountCoupons() : intfAccountCoupons( - true, +// true, MTSchema, tblAccountCoupons::Private::ExtraORMFields, tblAccountCoupons::Private::ExtraRelations, diff --git a/Modules/Modules.pro b/Modules/Modules.pro index 6dcd80b8..a5c7dca3 100644 --- a/Modules/Modules.pro +++ b/Modules/Modules.pro @@ -13,6 +13,7 @@ addSubdirs(Account, Dependencies) addSubdirs(Advert, Dependencies) addSubdirs(Ticketing, Dependencies) addSubdirs(MT, Dependencies) +addSubdirs(TargomanMT, Dependencies) #addSubdirs(NGT, Dependencies) addSubdirs(TextProcessor, Dependencies) addSubdirs(FormalityChecker, Dependencies) diff --git a/Modules/TargomanMT/TargomanMT.pro b/Modules/TargomanMT/TargomanMT.pro new file mode 100644 index 00000000..51102168 --- /dev/null +++ b/Modules/TargomanMT/TargomanMT.pro @@ -0,0 +1,19 @@ +################################################################################ +# QBuildSystem +# +# Copyright(c) 2021 by Targoman Intelligent Processing +# +# Redistribution and use in source and binary forms are allowed under the +# terms of BSD License 2.0. +################################################################################ +include($$QBUILD_PATH/templates/projectConfigs.pri) + +addSubdirs(moduleSrc, Dependencies) +addSubdirs(functionalTest, Dependencies) + +OTHER_FILES += \ + migrations/.gitkeep \ + migrations/db/* \ + migrations/db/.dbdiff.dev_.cfg \ + migrations/local/* \ + migrations/local/.migrations diff --git a/Modules/TargomanMT/functionalTest/functionalTest.pro b/Modules/TargomanMT/functionalTest/functionalTest.pro new file mode 100644 index 00000000..df1222eb --- /dev/null +++ b/Modules/TargomanMT/functionalTest/functionalTest.pro @@ -0,0 +1,26 @@ +################################################################################ +# QBuildSystem +# +# Copyright(c) 2021 by Targoman Intelligent Processing +# +# Redistribution and use in source and binary forms are allowed under the +# terms of BSD License 2.0. +################################################################################ +TEST_NAME = targomanFunctionalTest + +HEADERS += \ + testTargomanMT.hpp + +SOURCES += \ + $$BASE_PROJECT_PATH/3rdParty/QtCurl/libsrc/QtCUrl.cpp \ + main.cpp \ + +LIBS += -lcurl + +BASE_TEST_PATH = $$BASE_PROJECT_PATH/Interfaces/Test +INCLUDEPATH += $$BASE_TEST_PATH +include($$BASE_TEST_PATH/Test.pri) + +################################################################################ +include($$QBUILD_PATH/templates/unitTestConfigs.pri) +LIBS -= -lTargomanAPI diff --git a/Modules/TargomanMT/functionalTest/main.cpp b/Modules/TargomanMT/functionalTest/main.cpp new file mode 100644 index 00000000..100ff4ff --- /dev/null +++ b/Modules/TargomanMT/functionalTest/main.cpp @@ -0,0 +1,77 @@ +/****************************************************************************** +# TargomanAPI: REST API for Targoman +# +# Copyright 2014-2020 by Targoman Intelligent Processing +# +# TargomanAPI is free software: you can redistribute it and/or modify +# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# TargomanAPI is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# along with Targoman. If not, see . + ******************************************************************************/ +/** + * @author S. Mehran M. Ziabary + * @author Kambiz Zandi + */ + +#include +#include "testBase.hpp" +#include "testTargomanMT.hpp" + +TAPI_MARSHAL_TEST_VARIABLES + +int main(int _argc, char *_argv[]) { + qDebug() << "--------------------------------------------------"; + qDebug() << "-- test module: TargomanMT -----------------------"; + qDebug() << "--------------------------------------------------"; + + //--------------------- + QString DBPrefix; + int progArgsCount = 0; + char **progArgs = findDBPrefixFromArguments(_argc, _argv, DBPrefix, progArgsCount); + + //--------------------- + QCoreApplication App(progArgsCount, progArgs); + App.setAttribute(Qt::AA_Use96Dpi, true); + + clsDAC::addDBEngine(enuDBEngines::MySQL); + clsDAC::setConnectionString(QString("HOST=%1;PORT=%2;USER=%3;PASSWORD=%4;SCHEMA=%5%6") + .arg(TARGOMAN_M2STR(UNITTEST_DB_HOST)) + .arg(TARGOMAN_M2STR(UNITTEST_DB_PORT)) + .arg(TARGOMAN_M2STR(UNITTEST_DB_USER)) + .arg(TARGOMAN_M2STR(UNITTEST_DB_PASSWORD)) + .arg(DBPrefix) + .arg(TARGOMAN_M2STR(UNITTEST_DB_SCHEMA)) + ); + + bool BreakOnFirstFail = true; + int FailedTests = 0; + + try { + FailedTests += QTest::qExec(new testBase(DBPrefix), progArgsCount, progArgs); + if (BreakOnFirstFail && !FailedTests) FailedTests += QTest::qExec(new testTargomanMT(DBPrefix), progArgsCount, progArgs); + } catch (exTargomanBase &e) { + ++FailedTests; + qDebug() << "*** EXCEPTION ***" << QString("error(%1):%2").arg(e.code()).arg(e.what()); + } catch (std::exception &e) { + ++FailedTests; + qDebug() << "*** EXCEPTION ***" << e.what(); + } + + if (FailedTests > 0) { + qDebug() << "total number of failed tests: " << FailedTests; + } else { + qDebug() << "all tests passed :)"; + } + + clsDAC::shutdown(); + + return FailedTests; +} diff --git a/Modules/TargomanMT/functionalTest/testTargomanMT.hpp b/Modules/TargomanMT/functionalTest/testTargomanMT.hpp new file mode 100644 index 00000000..c79829f7 --- /dev/null +++ b/Modules/TargomanMT/functionalTest/testTargomanMT.hpp @@ -0,0 +1,396 @@ +/****************************************************************************** + * TargomanAAA: Authentication, Authorization, Accounting framework * + * * + * Copyright 2014-2019 by Targoman Intelligent Processing * + * * + * TargomanAAA is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License as published * + * by the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * TargomanAAA is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Lesser General Public License for more details. * + * You should have received a copy of the GNU Lesser General Public License * + * along with Targoman. If not, see . * + * * + ******************************************************************************/ +/** + * @author S. Mehran M. Ziabary + * @author Kambiz Zandi + */ + +#ifndef TEST_TARGOMAN_HPP +#define TEST_TARGOMAN_HPP + +#include +#include "Interfaces/Test/testCommon.hpp" +#include "Interfaces/AAA/clsJWT.hpp" +#include +#include + +using namespace Targoman::API; +using namespace Targoman::API::AAA; + +#include "Interfaces/DBM/QueryBuilders.h" +using namespace Targoman::API::DBM; + +#include "Interfaces/AAA/Accounting_Defs.hpp" +using namespace Targoman::API::AAA; + +#include "Interfaces/Helpers/SecurityHelper.h" +using namespace Targoman::API::Helpers; + +class testTargomanMT : public clsBaseTest +{ + Q_OBJECT + +public: + testTargomanMT(const QString &_dbPrefix) : clsBaseTest(_dbPrefix) { ; } + + QString LastRandomNumber; // = "998877998877"; + QString CreatedUserEmail; + QString CreatedAdminEmail; + + QVariant TargomanProductID; + QVariant TargomanSaleableID; + QString TargomanProductCode; + QString TargomanSaleableCode; + Targoman::API::AAA::stuPreVoucher LastPreVoucher; + Targoman::API::AAA::stuVoucher BasketVoucher; +// Targoman::API::AAA::stuVoucher Voucher; + Targoman::API::AAA::stuVoucher ApproveOnlinePaymentVoucher; + + quint64 TokenID; + QString TokenJWT; + +private slots: + void initTestCase() { + initUnitTestData(false); + } + + void cleanupTestCase() { + gEncodedAdminJWT = ""; + gEncodedJWT = ""; + cleanupUnitTestData(); + } + +private: + /***************************************************************************************/ + /* cleanup *****************************************************************************/ + /***************************************************************************************/ + void cleanupUnitTestData() { +// clsDAC DAC; +// DAC.execQuery("", QString("UPDATE %1AAA.tblUser SET usrStatus='R' WHERE usrEmail IN(?,?)").arg(this->DBPrefix), { UT_UserEmail, UT_AdminUserEmail }); + + if (this->LastRandomNumber.isEmpty() == false) { + try { + QVariant Result = callAdminAPI( + RESTClientHelper::POST, + "Account/fixtureCleanup", + {}, + { + { "random", this->LastRandomNumber }, + }); + + } catch (std::exception &_exp) { + TargomanDebug(5) << _exp.what(); + } + } + } + +private slots: + /***************************************************************************************/ + /* tests *******************************************************************************/ + /***************************************************************************************/ + void setupAccountFixture() { + QT_TRY { + QVariant Result = callAdminAPI( + RESTClientHelper::POST, + "Account/fixtureSetup", + {}, + { + { "random", 1 }, + }); + + QVERIFY(Result.isValid()); + + this->LastRandomNumber = Result.toMap().value("Random").toString(); + + this->CreatedUserEmail = Result.toMap().value("User").toMap().value("email").toString(); + gUserID = Result.toMap().value("User").toMap().value("usrID").toULongLong(); + + this->CreatedAdminEmail = Result.toMap().value("Admin").toMap().value("email").toString(); + gAdminUserID = Result.toMap().value("Admin").toMap().value("usrID").toULongLong(); + + } QT_CATCH (const std::exception &exp) { + QTest::qFail(exp.what(), __FILE__, __LINE__); + } + } + + void login_user() { + //5d12d36cd5f66fe3e72f7b03cbb75333 = MD5(1234 + df6d2338b2b8fce1ec2f6dda0a630eb0 # 987) + QVariant Result = callUserAPI(RESTClientHelper::POST, + "Account/login",{},{ + { "emailOrMobile", this->CreatedUserEmail }, + { "pass", "5d12d36cd5f66fe3e72f7b03cbb75333" }, + { "salt", "1234" }, + }); + QVERIFY(Result.isValid()); + + gEncodedJWT = Result.toString(); + gJWT = QJsonDocument::fromJson(QByteArray::fromBase64(gEncodedJWT.split('.').at(1).toLatin1())).object(); + + QVERIFY(clsJWT(gJWT).actorID() == gUserID); + QVERIFY(clsJWT(gJWT).usrStatus() == TAPI::enuUserStatus::Active); + } + + void login_admin() { + //5d12d36cd5f66fe3e72f7b03cbb75333 = MD5(1234 + df6d2338b2b8fce1ec2f6dda0a630eb0 # 987) + QVariant Result = callUserAPI(RESTClientHelper::POST, + "Account/login",{},{ + { "emailOrMobile", this->CreatedAdminEmail }, + { "pass", "5d12d36cd5f66fe3e72f7b03cbb75333" }, + { "salt", "1234" }, + }); + QVERIFY(Result.isValid()); + + gEncodedAdminJWT = Result.toString(); + gAdminJWT = QJsonDocument::fromJson(QByteArray::fromBase64(gEncodedAdminJWT.split('.').at(1).toLatin1())).object(); + + QVERIFY(clsJWT(gAdminJWT).actorID() == gAdminUserID); + QVERIFY(clsJWT(gAdminJWT).usrStatus() == TAPI::enuUserStatus::Active); + } + + /***************************************************/ + void createProduct_Targoman() { + this->TargomanProductCode = QString("p%1").arg(QRandomGenerator::global()->generate()); + + QT_TRY { + this->TargomanProductID = callAdminAPI( + RESTClientHelper::PUT, + "Targoman/AccountProducts", + {}, + { + { tblAccountProductsBase::Fields::prdCode, this->TargomanProductCode }, + { tblAccountProductsBase::Fields::prdName, "test Targoman product 123" }, + { tblAccountProductsBase::Fields::prdInStockQty, 1'000 }, + { tblAccountProductsBase::Fields::prd_untID, 1 }, + { tblAccountProductsBase::Fields::prdNameI18N, QVariantMap({ + { "fa", "عنوان فارسی ۱۲۳" }, + { "ar", "عنوان عربی ۱۲۳" }, + { "fr", "عنوان فرانسوی ۱۲۳" }, + }) }, + { tblAccountProductsBase::Fields::prdDescI18N, QVariantMap({ + { "fa", "شرح فارسی ۱۲۳" }, + { "ar", "شرح عربی ۱۲۳" }, + }) }, + } + ); + + QVERIFY(this->TargomanProductID > 0); + + } QT_CATCH (const std::exception &exp) { + QTest::qFail(exp.what(), __FILE__, __LINE__); + } + } + + void createSaleable_Targoman() { + this->TargomanSaleableCode = QString("%1-s%2").arg(this->TargomanProductCode).arg(QRandomGenerator::global()->generate()); + + QT_TRY { + this->TargomanSaleableID = callAdminAPI( + RESTClientHelper::PUT, + "Targoman/AccountSaleables", + {}, + { + { tblAccountSaleablesBase::Fields::slbCode, this->TargomanSaleableCode }, + { tblAccountSaleablesBase::Fields::slbName, "test Targoman Saleable 456 name" }, + { tblAccountSaleablesBase::Fields::slbDesc, "test Targoman Saleable 456 desc" }, + { tblAccountSaleablesBase::Fields::slb_prdID, this->TargomanProductID }, + { tblAccountSaleablesBase::Fields::slbType, TAPI::enuSaleableType::toStr(TAPI::enuSaleableType::Special) }, + { tblAccountSaleablesBase::Fields::slbBasePrice, 12'000 }, + { tblAccountSaleablesBase::Fields::slbInStockQty, 150 }, + { tblAccountSaleablesBase::Fields::slbVoucherTemplate, "test Targoman Saleable 456 vt" }, + } + ); + + QVERIFY(this->TargomanSaleableID > 0); + + } QT_CATCH (const std::exception &exp) { + QTest::qFail(exp.what(), __FILE__, __LINE__); + } + } + + void create_api() { + QT_TRY { + QVariant Result = this->callUserAPI( + RESTClientHelper::enuHTTPMethod::POST, + "Account/APITokens/request", + {}, + { + { "name", "test Targoman" }, +// { "services", QStringList({ +// "Targoman", +// "blablabla", +// }) }, + }); + + QVERIFY(Result.isValid()); + + QVariantMap ResultToMap = Result.toMap(); + + this->TokenID = ResultToMap["iD"].toULongLong(); + this->TokenJWT = ResultToMap["token"].toString(); + + QVERIFY(this->TokenID > 0); + QVERIFY(this->TokenJWT.isEmpty() == false); + + } QT_CATCH (const std::exception &exp) { + QTest::qFail(exp.what(), __FILE__, __LINE__); + } + } + + void addToBasket_1() { + QT_TRY { + int ItemsCount = this->LastPreVoucher.Items.length(); + + QVariant Result = callUserAPI( + RESTClientHelper::POST, + "Targoman/addToBasket", + {}, + { + { "saleableCode", this->TargomanSaleableCode }, +// { "orderAdditives", QVariantMap({ { "adtv1", "1 1 1" }, { "adtv2", 111 } }) }, + { "qty", 1 }, + { "apiToken", this->TokenJWT }, + { "lastPreVoucher", this->LastPreVoucher.toJson().toVariantMap() }, + } + ); + + stuBasketActionResult BasketActionResult; + BasketActionResult.fromJson(Result.toJsonObject()); + this->LastPreVoucher = BasketActionResult.PreVoucher; + + auto item = this->LastPreVoucher.Items.last(); + QVERIFY(item.TotalPrice == 12'000); + + QVERIFY(this->LastPreVoucher.Items.length() > ItemsCount); + + } QT_CATCH (const std::exception &exp) { + QTest::qFail(exp.what(), __FILE__, __LINE__); + } + } + + void finalizeBasket_1() { + QT_TRY { + QVariant Result = callUserAPI( + RESTClientHelper::POST, + "Account/finalizeBasket", + {}, + { + { "preVoucher", this->LastPreVoucher.toJson().toVariantMap() }, + { "gatewayType", "_DeveloperTest" }, + { "domain", "dev.test" }, + { "paymentVerifyCallback", "http://127.0.0.1:10000/rest/v1/Account/OnlinePayments/devTestCallbackPage" }, + { "allowChargeWallet", true }, + } + ); + + this->BasketVoucher.fromJson(Result.toJsonObject()); + this->LastPreVoucher = this->BasketVoucher.Info; + + QVERIFY(this->BasketVoucher.ID > 0); + QVERIFY(this->LastPreVoucher.VoucherID > 0); + + } QT_CATCH (const std::exception &exp) { + QTest::qFail(exp.what(), __FILE__, __LINE__); + } + } + + void approveOnlinePayment_1() { + if (this->BasketVoucher.PaymentKey.isEmpty() == false) { + QT_TRY { + QVariant Result = callGuestAPI( + RESTClientHelper::POST, + "Account/approveOnlinePayment", + {}, + { + { "paymentKey", this->BasketVoucher.PaymentKey }, +// { "domain", "dev.test" }, + { "pgResponse", QVariantMap({ + { "result", "ok" }, + }) }, + } + ); + + this->ApproveOnlinePaymentVoucher.fromJson(Result.toJsonObject()); + + QVERIFY(this->ApproveOnlinePaymentVoucher.ID > 0); + QVERIFY(this->ApproveOnlinePaymentVoucher.Payed == 12'000); + QVERIFY(this->ApproveOnlinePaymentVoucher.Remained == 0); + + } QT_CATCH (const std::exception &exp) { + QTest::qFail(exp.what(), __FILE__, __LINE__); + } + } + } + + void get_changed_token() { + QT_TRY { + QVariant Result = callUserAPI( + RESTClientHelper::GET, + "Account/APITokens/" + QString::number(this->TokenID) + ); + + QVERIFY(Result.isValid()); + + this->TokenJWT = Result.toMap()["aptToken"].toString(); + + } QT_CATCH (const std::exception &exp) { + QTest::qFail(exp.what(), __FILE__, __LINE__); + } + } + + void translate_en2fa_1() { + QT_TRY { + QVariant Result = this->callAPI( + this->TokenJWT, + RESTClientHelper::enuHTTPMethod::POST, + "Targoman/translate", + {}, + { + { "text", "This is a sample text for testing." }, + { "dir", "en2fa" }, + }); + + QVERIFY(Result.isValid()); + + } QT_CATCH (const std::exception &exp) { + QTest::qFail(exp.what(), __FILE__, __LINE__); + } + } + + void translate_fa2en_1() { + QT_TRY { + QVariant Result = this->callAPI( + this->TokenJWT, + RESTClientHelper::enuHTTPMethod::POST, + "Targoman/translate", + {}, + { + { "text", "این یک متن نمونه برای آزمایش است." }, + { "dir", "fa2en" }, + }); + + QVERIFY(Result.isValid()); + + } QT_CATCH (const std::exception &exp) { + QTest::qFail(exp.what(), __FILE__, __LINE__); + } + } + +}; + +#endif // TEST_TARGOMAN_HPP diff --git a/Modules/TargomanMT/migrations/.gitkeep b/Modules/TargomanMT/migrations/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Modules/TargomanMT/moduleSrc/ORM/Accounting.cpp b/Modules/TargomanMT/moduleSrc/ORM/Accounting.cpp new file mode 100644 index 00000000..32ef8163 --- /dev/null +++ b/Modules/TargomanMT/moduleSrc/ORM/Accounting.cpp @@ -0,0 +1,181 @@ +/****************************************************************************** +# TargomanAPI: REST API for Targoman +# +# Copyright 2014-2020 by Targoman Intelligent Processing +# +# TargomanAPI is free software: you can redistribute it and/or modify +# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# TargomanAPI is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# along with Targoman. If not, see . + ******************************************************************************/ +/** + * @author S. Mehran M. Ziabary + * @author Kambiz Zandi + */ + +#include "Accounting.h" +#include "../TargomanMT.h" + +using namespace Targoman::API::AAA; + +namespace Targoman::API::TargomanMTModule::ORM { + +/******************************************************/ +/******************************************************/ +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, AccountUnits) + +AccountUnits::AccountUnits() : + intfAccountUnits( +// false, + TargomanMTSchema, + tblAccountUnits::Private::ExtraORMFields, + tblAccountUnits::Private::ExtraRelations, + tblAccountUnits::Private::ExtraIndexes +) { + AccountUnitsI18N::instance(); +} + +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, AccountUnitsI18N) + +AccountUnitsI18N::AccountUnitsI18N() : + intfAccountUnitsI18N( +// false, + TargomanMTSchema, + tblAccountUnitsI18N::Private::ExtraORMFields, + tblAccountUnitsI18N::Private::ExtraRelations, + tblAccountUnitsI18N::Private::ExtraIndexes +) { ; } + +/******************************************************/ +/******************************************************/ +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, AccountProducts) + +AccountProducts::AccountProducts() : + intfAccountProducts( +// false, + TargomanMTSchema, + tblAccountProducts::Private::ExtraORMFields, + tblAccountProducts::Private::ExtraRelations, + tblAccountProducts::Private::ExtraIndexes +) { + AccountProductsI18N::instance(); +} + +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, AccountProductsI18N) + +AccountProductsI18N::AccountProductsI18N() : + intfAccountProductsI18N( +// false, + TargomanMTSchema, + tblAccountProductsI18N::Private::ExtraORMFields, + tblAccountProductsI18N::Private::ExtraRelations, + tblAccountProductsI18N::Private::ExtraIndexes +) { ; } + +/******************************************************/ +/******************************************************/ +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, AccountSaleables) + +AccountSaleables::AccountSaleables() : + intfAccountSaleables( +// false, + TargomanMTSchema, + tblAccountSaleables::Private::ExtraORMFields, + tblAccountSaleables::Private::ExtraRelations, + tblAccountSaleables::Private::ExtraIndexes +) { + AccountSaleablesI18N::instance(); +} + +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, AccountSaleablesI18N) + +AccountSaleablesI18N::AccountSaleablesI18N() : + intfAccountSaleablesI18N( +// false, + TargomanMTSchema, + tblAccountSaleablesI18N::Private::ExtraORMFields, + tblAccountSaleablesI18N::Private::ExtraRelations, + tblAccountSaleablesI18N::Private::ExtraIndexes +) { ; } + +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, AccountSaleablesFiles) + +AccountSaleablesFiles::AccountSaleablesFiles() : + intfAccountSaleablesFiles( +// false, + TargomanMTSchema, + tblAccountSaleablesFiles::Private::ExtraORMFields, + tblAccountSaleablesFiles::Private::ExtraRelations, + tblAccountSaleablesFiles::Private::ExtraIndexes +) { ; } + +/******************************************************/ +/******************************************************/ +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, AccountUserAssets) + +AccountUserAssets::AccountUserAssets() : + intfAccountUserAssets( +// false, + TargomanMTSchema, + tblAccountUserAssets::Private::ExtraORMFields, + tblAccountUserAssets::Private::ExtraRelations, + tblAccountUserAssets::Private::ExtraIndexes +) { ; } + +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, AccountUserAssetsFiles) + +AccountUserAssetsFiles::AccountUserAssetsFiles() : + intfAccountUserAssetsFiles( +// false, + TargomanMTSchema, + tblAccountUserAssetsFiles::Private::ExtraORMFields, + tblAccountUserAssetsFiles::Private::ExtraRelations, + tblAccountUserAssetsFiles::Private::ExtraIndexes +) { ; } + +/******************************************************/ +/******************************************************/ +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, AccountAssetUsage) + +AccountAssetUsage::AccountAssetUsage() : + intfAccountAssetUsage( +// false, + TargomanMTSchema, + tblAccountAssetUsage::Private::ExtraORMFields, + tblAccountAssetUsage::Private::ExtraRelations, + tblAccountAssetUsage::Private::ExtraIndexes +) { ; } + +/******************************************************/ +/******************************************************/ +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, AccountCoupons) + +AccountCoupons::AccountCoupons() : + intfAccountCoupons( +// false, + TargomanMTSchema, + tblAccountCoupons::Private::ExtraORMFields, + tblAccountCoupons::Private::ExtraRelations, + tblAccountCoupons::Private::ExtraIndexes +) { ; } + +} // namespace Targoman::API::TargomanMTModule::ORM diff --git a/Modules/TargomanMT/moduleSrc/ORM/Accounting.h b/Modules/TargomanMT/moduleSrc/ORM/Accounting.h new file mode 100644 index 00000000..de99d0ce --- /dev/null +++ b/Modules/TargomanMT/moduleSrc/ORM/Accounting.h @@ -0,0 +1,475 @@ +/****************************************************************************** +# TargomanAPI: REST API for Targoman +# +# Copyright 2014-2020 by Targoman Intelligent Processing +# +# TargomanAPI is free software: you can redistribute it and/or modify +# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# TargomanAPI is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# along with Targoman. If not, see . + ******************************************************************************/ +/** + * @author S. Mehran M. Ziabary + * @author Kambiz Zandi + */ + +#ifndef TARGOMAN_API_MODULES_TARGOMANMT_ORM_ACCOUNTING_H +#define TARGOMAN_API_MODULES_TARGOMANMT_ORM_ACCOUNTING_H + +#include "Interfaces/AAA/Accounting_Defs.hpp" +#include "Interfaces/AAA/AAA.hpp" +#include "../TargomanMTDefs.hpp" + +namespace Targoman::API::TargomanMTModule { + +//structures and enumes goes here + +} //namespace Targoman::API::TargomanMTModule + +namespace Targoman::API::TargomanMTModule { +namespace ORM { + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" + +namespace tblAccountUnits { + + namespace ExtraFields { + } + + namespace ExtraRelation { +// constexpr char AAA[] = "aaa"; + } + + namespace Private { + const QList ExtraORMFields = { + ///ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + ///Col Reference Table ForeignCol Rename LeftJoin + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblAccountUnitsBase_DTO + ); +} + +namespace tblAccountUnitsI18N { + + namespace ExtraFields { + } + + namespace ExtraRelation { +// constexpr char AAA[] = "aaa"; + } + + namespace Private { + const QList ExtraORMFields = { + ///ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + ///Col Reference Table ForeignCol Rename LeftJoin + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblAccountUnitsI18NBase_DTO + ); +} + +namespace tblAccountProducts { + + namespace ExtraFields { + } + + namespace ExtraRelation { +// constexpr char AAA[] = "aaa"; + } + + namespace Private { + const QList ExtraORMFields = { + ///ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + ///Col Reference Table ForeignCol Rename LeftJoin + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblAccountProductsBase_DTO + ); +} + +namespace tblAccountProductsI18N { + + namespace ExtraFields { + } + + namespace ExtraRelation { +// constexpr char AAA[] = "aaa"; + } + + namespace Private { + const QList ExtraORMFields = { + ///ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + ///Col Reference Table ForeignCol Rename LeftJoin + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblAccountProductsI18NBase_DTO + ); +} + +namespace tblAccountSaleables { + + namespace ExtraFields { + } + + namespace ExtraRelation { +// constexpr char AAA[] = "aaa"; + } + + namespace Private { + const QList ExtraORMFields = { + ///ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblAccountSaleablesBase_DTO + ); +} + +namespace tblAccountSaleablesI18N { + + namespace ExtraFields { + } + + namespace ExtraRelation { +// constexpr char AAA[] = "aaa"; + } + + namespace Private { + const QList ExtraORMFields = { + ///ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + ///Col Reference Table ForeignCol Rename LeftJoin + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblAccountSaleablesI18NBase_DTO + ); +} + +namespace tblAccountSaleablesFiles { + + namespace ExtraFields { + } + + namespace ExtraRelation { + } + + namespace Private { + const QList ExtraORMFields = { + ///ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblAccountSaleablesFilesBase_DTO + ); +} + +namespace tblAccountUserAssets { + + namespace ExtraFields { + } + + namespace ExtraRelation { + // constexpr char AAA[] = "aaa"; + } + + namespace Private { + const QList ExtraORMFields = { + //ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblAccountUserAssetsBase_DTO + ); +} + +namespace tblAccountUserAssetsFiles { + + namespace ExtraFields { + } + + namespace ExtraRelation { + } + + namespace Private { + const QList ExtraORMFields = { + //ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblAccountUserAssetsFilesBase_DTO + ); +} + +namespace tblAccountAssetUsage { + + namespace ExtraFields { + //usgRemainingDays + } + + namespace ExtraRelation { + // constexpr char AAA[] = "aaa"; + } + + namespace Private { + const QList ExtraORMFields = { + //ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblAccountAssetUsageBase_DTO + ); +} + +namespace tblAccountCoupons { + + namespace ExtraFields { + } + + namespace ExtraRelation { + // constexpr char AAA[] = "aaa"; + } + + namespace Private { + const QList ExtraORMFields = { + ///ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblAccountCouponsBase_DTO + ); +} + +#pragma GCC diagnostic pop + +/******************************************************/ +/******************************************************/ +/******************************************************/ +class AccountUnits : public intfAccountUnits +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, AccountUnits) + +protected: + QScopedPointer AccountUnitsI18N; +}; + +/******************************************************/ +class AccountUnitsI18N : public intfAccountUnitsI18N +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, AccountUnitsI18N) + +public: +}; + +/******************************************************/ +/******************************************************/ +/******************************************************/ +class AccountProducts : public intfAccountProducts +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, AccountProducts) + +protected: + QScopedPointer AccountProductsI18N; +}; + +/******************************************************/ +class AccountProductsI18N : public intfAccountProductsI18N +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, AccountProductsI18N) + +public: +}; + +/******************************************************/ +/******************************************************/ +/******************************************************/ +class AccountSaleables : public intfAccountSaleables +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, AccountSaleables) + +protected: + QScopedPointer AccountSaleablesI18N; +}; + +/******************************************************/ +class AccountSaleablesI18N : public intfAccountSaleablesI18N +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, AccountSaleablesI18N) + +//public: +}; + +/******************************************************/ +class AccountSaleablesFiles : public intfAccountSaleablesFiles +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, AccountSaleablesFiles) +}; + +/******************************************************/ +/******************************************************/ +/******************************************************/ +class AccountUserAssets : public intfAccountUserAssets +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, AccountUserAssets) + +//public: +}; + +/******************************************************/ +class AccountUserAssetsFiles : public intfAccountUserAssetsFiles +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, AccountUserAssetsFiles) + +//public: +}; + +/******************************************************/ +/******************************************************/ +/******************************************************/ +class AccountAssetUsage : public intfAccountAssetUsage +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, AccountAssetUsage) + +public: +}; + +/******************************************************/ +/******************************************************/ +/******************************************************/ +class AccountCoupons : public intfAccountCoupons +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, AccountCoupons) + +public: +}; + +/******************************************************/ +/******************************************************/ +/******************************************************/ +//There is no Prize in this module +/*class clsAccountPrizes: public Accounting::intfAccountPrizes +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(Targoman,clsAccountPrizes) + +private slots: +public: +}; +*/ + +} //namespace ORM +} //namespace Targoman::API::TargomanMTModule + +#endif // TARGOMAN_API_MODULES_TARGOMANMT_ORM_ACCOUNTING_H diff --git a/Modules/TargomanMT/moduleSrc/ORM/MTHelpers.cpp b/Modules/TargomanMT/moduleSrc/ORM/MTHelpers.cpp new file mode 100644 index 00000000..cb8936c4 --- /dev/null +++ b/Modules/TargomanMT/moduleSrc/ORM/MTHelpers.cpp @@ -0,0 +1,100 @@ +/****************************************************************************** +# TargomanAPI: REST API for Targoman +# +# Copyright 2014-2020 by Targoman Intelligent Processing +# +# TargomanAPI is free software: you can redistribute it and/or modify +# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# TargomanAPI is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# along with Targoman. If not, see . + ******************************************************************************/ +/** + * @author S. Mehran M. Ziabary + * @author Kambiz Zandi + */ + +#include "MTHelpers.h" +#include "../TargomanMT.h" + +//TAPI_REGISTER_TARGOMAN_ENUM(Targoman::API::TargomanMTModule, enu...); + +//using namespace Targoman::API::AAA; + +namespace Targoman::API::TargomanMTModule::ORM { + +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, CorrectionRules) + +CorrectionRules::CorrectionRules() : + intfCorrectionRules( + TargomanMTSchema, + tblCorrectionRules::Private::ExtraORMFields, + tblCorrectionRules::Private::ExtraRelations, + tblCorrectionRules::Private::ExtraIndexes +) { ; } + +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, DigestedTranslationLogs) + +DigestedTranslationLogs::DigestedTranslationLogs() : + intfDigestedTranslationLogs( + TargomanMTSchema, + tblDigestedTranslationLogs::Private::ExtraORMFields, + tblDigestedTranslationLogs::Private::ExtraRelations, + tblDigestedTranslationLogs::Private::ExtraIndexes +) { ; } + +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, MultiDic) + +MultiDic::MultiDic() : + intfMultiDic( + TargomanMTSchema, + tblMultiDic::Private::ExtraORMFields, + tblMultiDic::Private::ExtraRelations, + tblMultiDic::Private::ExtraIndexes +) { ; } + +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, TokenStats) + +TokenStats::TokenStats() : + intfTokenStats( + TargomanMTSchema, + tblTokenStats::Private::ExtraORMFields, + tblTokenStats::Private::ExtraRelations, + tblTokenStats::Private::ExtraIndexes +) { ; } + +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, TranslatedPhrases) + +TranslatedPhrases::TranslatedPhrases() : + intfTranslatedPhrases( + TargomanMTSchema, + tblTranslatedPhrases::Private::ExtraORMFields, + tblTranslatedPhrases::Private::ExtraRelations, + tblTranslatedPhrases::Private::ExtraIndexes +) { ; } + +/******************************************************/ +TARGOMAN_API_SUBMODULE_IMPLEMENT(TargomanMT, TranslationLogs) + +TranslationLogs::TranslationLogs() : + intfTranslationLogs( + TargomanMTSchema, + tblTranslationLogs::Private::ExtraORMFields, + tblTranslationLogs::Private::ExtraRelations, + tblTranslationLogs::Private::ExtraIndexes +) { ; } + +/******************************************************/ +} // namespace Targoman::API::TargomanMTModule::ORM diff --git a/Modules/TargomanMT/moduleSrc/ORM/MTHelpers.h b/Modules/TargomanMT/moduleSrc/ORM/MTHelpers.h new file mode 100644 index 00000000..13d90ba9 --- /dev/null +++ b/Modules/TargomanMT/moduleSrc/ORM/MTHelpers.h @@ -0,0 +1,253 @@ +/****************************************************************************** +# TargomanAPI: REST API for Targoman +# +# Copyright 2014-2020 by Targoman Intelligent Processing +# +# TargomanAPI is free software: you can redistribute it and/or modify +# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# TargomanAPI is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# along with Targoman. If not, see . + ******************************************************************************/ +/** + * @author S. Mehran M. Ziabary + * @author Kambiz Zandi + */ + +#ifndef TARGOMAN_API_MODULES_TARGOMANMT_ORM_MTHELPERS_H +#define TARGOMAN_API_MODULES_TARGOMANMT_ORM_MTHELPERS_H + +#include "ModuleHelpers/MT/Interfaces/intfMTHelpers.h" +#include "../TargomanMTDefs.hpp" + +using namespace Targoman::API::ModuleHelpers::MT::Interfaces; + +namespace Targoman::API::TargomanMTModule { + +//structures and enumes goes here + +//TARGOMAN_DEFINE_ENUM (enu..., + +} //namespace Targoman::API::TargomanMTModule + +//TAPI_DECLARE_METATYPE_ENUM(Targoman::API::TargomanMTModule, enu...); + +namespace Targoman::API::TargomanMTModule::ORM { + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" + +namespace tblCorrectionRules { + + namespace ExtraFields { + } + + namespace ExtraRelation { + } + + namespace Private { + const QList ExtraORMFields = { + ///ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + ///Col Reference Table ForeignCol Rename LeftJoin + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblCorrectionRulesBase_DTO + ); +} + +namespace tblDigestedTranslationLogs { + + namespace ExtraFields { + } + + namespace ExtraRelation { + } + + namespace Private { + const QList ExtraORMFields = { + ///ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + ///Col Reference Table ForeignCol Rename LeftJoin + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblDigestedTranslationLogsBase_DTO + ); +} + +namespace tblMultiDic { + + namespace ExtraFields { + } + + namespace ExtraRelation { + } + + namespace Private { + const QList ExtraORMFields = { + ///ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblMultiDicBase_DTO + ); +} + +namespace tblTokenStats { + + namespace ExtraFields { + } + + namespace ExtraRelation { + } + + namespace Private { + const QList ExtraORMFields = { + //ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblTokenStatsBase_DTO + ); +} + +namespace tblTranslatedPhrases { + + namespace ExtraFields { + //usgRemainingDays + } + + namespace ExtraRelation { + } + + namespace Private { + const QList ExtraORMFields = { + //ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblTranslatedPhrasesBase_DTO + ); +} + +namespace tblTranslationLogs { + + namespace ExtraFields { + } + + namespace ExtraRelation { + } + + namespace Private { + const QList ExtraORMFields = { + ///ColName Type Validation Default UpBy Sort Filter Self Virt PK + }; + + const QList ExtraRelations = { + }; + + const QList ExtraIndexes = { + }; + + } //namespace Private + + TAPI_DEFINE_STRUCT(DTO, + SF_tblTranslationLogsBase_DTO + ); +} + +#pragma GCC diagnostic pop + +/******************************************************/ +class CorrectionRules : public intfCorrectionRules +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, CorrectionRules) +}; + +/******************************************************/ +class DigestedTranslationLogs : public intfDigestedTranslationLogs +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, DigestedTranslationLogs) +}; + +/******************************************************/ +class MultiDic : public intfMultiDic +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, MultiDic) +}; + +/******************************************************/ +class TokenStats : public intfTokenStats +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, TokenStats) +}; + +/******************************************************/ +class TranslatedPhrases : public intfTranslatedPhrases +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, TranslatedPhrases) +}; + +/******************************************************/ +class TranslationLogs : public intfTranslationLogs +{ + Q_OBJECT + TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, TranslationLogs) +}; + +/******************************************************/ +} //namespace Targoman::API::TargomanMTModule::ORM + +#endif // TARGOMAN_API_MODULES_TARGOMANMT_ORM_MTHELPERS_H diff --git a/Modules/TargomanMT/moduleSrc/TargomanMT.cpp b/Modules/TargomanMT/moduleSrc/TargomanMT.cpp new file mode 100644 index 00000000..b55fe72a --- /dev/null +++ b/Modules/TargomanMT/moduleSrc/TargomanMT.cpp @@ -0,0 +1,390 @@ +/****************************************************************************** +# TargomanAPI: REST API for Targoman +# +# Copyright 2014-2019 by Targoman Intelligent Processing +# +# TargomanAPI is free software: you can redistribute it and/or modify +# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# TargomanAPI is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# along with Targoman. If not, see . + ******************************************************************************/ +/** + * @author S. Mehran M. Ziabary + * @author Kambiz Zandi + */ + +#include "TargomanMT.h" + +#include "libQFieldValidator/QFieldValidator.h" +#include "Interfaces/AAA/PrivHelpers.h" +#include "Interfaces/Common/GenericEnums.hpp" +#include "Interfaces/Common/HTTPExceptions.hpp" +#include "Interfaces/Helpers/SecurityHelper.h" +using namespace Targoman::API::Helpers; + +#include "ModuleHelpers/MT/MTHelper.h" +using namespace Targoman::API::ModuleHelpers::MT; + +#include "TargomanMTDefs.hpp" +#include "ORM/MTHelpers.h" +#include "ORM/Accounting.h" + +#include "Interfaces/Helpers/RESTClientHelper.h" +#include "Interfaces/Helpers/FixtureHelper.h" +using namespace Targoman::API::Helpers; + +using namespace Targoman::API::AAA; + +namespace Targoman::API::TargomanMTModule { + +using namespace ORM; + +TARGOMAN_API_MODULE_IMPLEMENT(TargomanMT) +//--------------------------------------------------------- +TARGOMAN_API_MODULE_IMPLEMENT_DB_CONFIG(TargomanMT, TargomanMTSchema) +//--------------------------------------------------------- +TARGOMAN_API_MODULE_IMPLEMENT_MIGRATIONS(TargomanMT, TargomanMTSchema); +TARGOMAN_API_MODULE_IMPLEMENT_ACTIONLOG(TargomanMT, TargomanMTSchema); +TARGOMAN_API_MODULE_IMPLEMENT_OBJECTSTORAGE(TargomanMT, TargomanMTSchema) +TARGOMAN_API_MODULE_IMPLEMENT_FAQ(TargomanMT, TargomanMTSchema); + +TargomanMT::TargomanMT() : + intfAccountingBasedModule( + TargomanMTDomain, + TargomanMTSchema, + false, + { + // day week month total +// { "show", { "slbShowPerDay", {}, {}, "slbShowTotal" } }, +// { "click", { "slbClicksPerDay", {}, "slbClicksPerMonth", "slbClicksTotal" } }, + }, + &AccountUnits::instance(), + &AccountProducts::instance(), + &AccountSaleables::instance(), + &AccountSaleablesFiles::instance(), + &AccountUserAssets::instance(), + &AccountUserAssetsFiles::instance(), + &AccountAssetUsage::instance(), + &AccountCoupons::instance() + ), + DerivedHelperSubmodules( + &CorrectionRules::instance(), + &DigestedTranslationLogs::instance(), + &MultiDic::instance(), + &TokenStats::instance(), + &TranslatedPhrases::instance(), + &TranslationLogs::instance() +) { + TARGOMAN_API_MODULE_IMPLEMENT_CTOR_MIGRATIONS(Targoman, TargomanMTSchema); + TARGOMAN_API_MODULE_IMPLEMENT_CTOR_ACTIONLOG(Targoman, TargomanMTSchema); + TARGOMAN_API_MODULE_IMPLEMENT_CTOR_OBJECTSTORAGE(Targoman, TargomanMTSchema) + TARGOMAN_API_MODULE_IMPLEMENT_CTOR_FAQ(Targoman, TargomanMTSchema); + + this->addSubModule(&CorrectionRules::instance()); + this->addSubModule(&DigestedTranslationLogs::instance()); + this->addSubModule(&MultiDic::instance()); + this->addSubModule(&TokenStats::instance()); + this->addSubModule(&TranslatedPhrases::instance()); + this->addSubModule(&TranslationLogs::instance()); + + this->addSubModule(AccountUnits.data()); + this->addSubModule(AccountProducts.data()); + this->addSubModule(AccountSaleables.data()); + this->addSubModule(AccountSaleablesFiles.data()); + this->addSubModule(AccountUserAssets.data()); + this->addSubModule(AccountUserAssetsFiles.data()); + this->addSubModule(AccountAssetUsages.data()); + this->addSubModule(AccountCoupons.data()); + //this->addSubModule(AccountPrizes); // There is no prize in Targoman module +} + +QMap TargomanMT::requiredDBs() const { + QMap RequiredDBs = intfSQLBasedModule::requiredDBs(); + +// RequiredDBs.insert("MTHelper", MTHelper::instance().requiredDB()); + + return RequiredDBs; +} + +void TargomanMT::initializeModule() { + MTHelper::instance().initialize(); +} + +stuServiceCreditsInfo TargomanMT::retrieveServiceCreditsInfo(quint64 _usrID) { + ///@TODO: complete this + return stuServiceCreditsInfo( + {}, + NULLABLE_NULL_VALUE, + NULLABLE_NULL_VALUE, + {}, + {} + ); +} + +void TargomanMT::breakCredit(quint64 _slbID) { +} + +bool TargomanMT::isUnlimited(const UsageLimits_t& _limits) const { +} + +bool TargomanMT::isEmpty(const UsageLimits_t& _limits) const { +} + +void TargomanMT::computeAdditives( + INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, + INOUT stuAssetItem &_assetItem, + const stuVoucherItem *_oldVoucherItem /*= nullptr*/ +) { + ///@TODO: [very important] complete this +// qDebug() << "----------" << "_orderAdditives:" << _orderAdditives; +// AssetItem.UnitPrice *= 1.1; +}; + +void TargomanMT::computeReferrer( + INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, + INOUT stuAssetItem &_assetItem, + const stuVoucherItem *_oldVoucherItem /*= nullptr*/ +) { + ///@TODO: [very important] complete this + +#if 0 //def QT_DEBUG + ///::: SAMPLE CODE ::: + + //1: add, modify or remove credit voucher for fp.com + if (_oldVoucherItem != nullptr) { + if (_oldVoucherItem->Qty != _assetItem.Qty) { + //remove old + QList::iterator it = _assetItem.Private.PendingVouchers.begin(); + while (it != _assetItem.Private.PendingVouchers.end()) { + if ((it->Name == PENDING_VOUCHER_NAME_REFERRER_PRIZE) + && (it->Info.contains("referrer")) + ) { + it = _assetItem.Private.PendingVouchers.erase(it); + continue; + } + + ++it; + } + } + } + + if (_assetItem.Qty > 0) { + _assetItem.Private.PendingVouchers.append({ + /* Name */ PENDING_VOUCHER_NAME_REFERRER_PRIZE, + /* Type */ enuVoucherType::Prize, //Credit, + /* Amount */ 2000 * _assetItem.Qty, + /* Info */ { + { "referrer", _assetItem.Referrer }, + }, + }); + } + + //2: add, modify or remove system discount + this->computeSystemDiscount(APICALLBOOM_PARAM, _assetItem, { + QString("referrer_%1").arg("fp.com"), + "5% off by fp.com", + 5, + enuDiscountType::Percent, + 10'000 + }, _oldVoucherItem); + + //3: inc translate words max limit (30'000 -> 35'000) +// int IncAmount = 5'000; +// if (_assetItem.AdditionalInfo.contains("plus-max-words")) +// _assetItem.AdditionalInfo["plus-max-words"] = IncAmount + _assetItem.AdditionalInfo["plus-max-words"].toInt(); +// else +// _assetItem.AdditionalInfo.insert("plus-max-words", IncAmount); + + //4: inc days (30 -> 40) + int IncDays = 10; + if (_assetItem.AdditionalInfo.contains(ASSET_ITEM_ADDITIONAL_INTO_KEY_PLUS_MAX_DAYS)) + _assetItem.AdditionalInfo[ASSET_ITEM_ADDITIONAL_INTO_KEY_PLUS_MAX_DAYS] = IncDays + _assetItem.AdditionalInfo[ASSET_ITEM_ADDITIONAL_INTO_KEY_PLUS_MAX_DAYS].toInt(); + else + _assetItem.AdditionalInfo.insert(ASSET_ITEM_ADDITIONAL_INTO_KEY_PLUS_MAX_DAYS, IncDays); +#endif +}; + +QVariantMap TargomanMT::getCustomUserAssetFieldsForQuery( + INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, + INOUT stuAssetItem &_assetItem, + const stuVoucherItem *_oldVoucherItem /*= nullptr*/ +) { + ///@TODO: [very important] complete this + + QVariantMap Result; + +// if (_assetItem.AdditionalInfo.contains(ASSET_ITEM_ADDITIONAL_INTO_KEY_PLUS_MAX_DAYS)) +// Result.insert(tblAccountUserAssets::ExtraFields::uasDays, _assetItem.AdditionalInfo[ASSET_ITEM_ADDITIONAL_INTO_KEY_PLUS_MAX_DAYS].toInt()); + + return Result; +} + +/****************************************************************\ +|** API Methods *************************************************| +\****************************************************************/ +QVariantMap IMPL_REST_GET_OR_POST(TargomanMT, Translate, ( + APICALLBOOM_TYPE_JWT_USER_OR_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, + QString _text, + QString _dir, + bool _detailed, + bool _detok, + bool _dic, + bool _dicFull +)) { + QString _engine = "NMT"; + + if (APICALLBOOM_PARAM.isAnonymouse()) { + + } else { + + } + + QTime Timer, OverallTime; + Timer.start(); + OverallTime.start(); + + int PreprocessTime = 0; + + _text = _text.trimmed(); + if (_text.isEmpty()) + throw exHTTPBadRequest("Input text must not be empty"); + + _dir = _dir.replace('_', '2'); + + TranslationDir_t Dir = MTHelper::dirLangs(_dir); + if (Dir.first.isNull()) + throw exHTTPBadRequest("Invalid translation direction format"); + + if (!MTHelper::instance().isValidEngine(_engine, Dir) == false) + throw exHTTPBadRequest("Invalid engine/direction combination"); + +// QJsonObject TokenInfo = Authorization::retrieveTokenInfo(_token, +// _REMOTE_IP, { +// TARGOMAN_PRIV_PREFIX + _engine, +// TARGOMAN_PRIV_PREFIX + _dir, +// _dic ? (TARGOMAN_PRIV_PREFIX + "Dic") : QString(), +// _dicFull ? (TARGOMAN_PRIV_PREFIX + "DicFull") : QString() +// }); + + +// QJsonObject Stats = this->execQuery( +// "SELECT * FROM tblTokenStats " +// "WHERE tks_tokID = ? " +// " AND tksEngine=? " +// " AND tksDir=? ", +// { +// {TokenInfo[TOKENItems::tokID]}, +// {_engine}, +// {_dir}, +// } +// ).toJson(true).object (); + +// if (Stats.isEmpty()) +// this->execQuery("INSERT IGNORE INTO tblTokenStats (tks_tokID,tksEngine,tksDir) VALUES(?, ?, ?)", { +// {TokenInfo[TOKENItems::tokID]}, +// {_engine}, +// {_dir}, +// }); + + _text = MTHelper::instance().tokenize(_text, Dir.first); + quint64 SourceWordCount = static_cast(_text.split(' ').size()); + +// QJsonObject Privs = Authorization::privObjectFromInfo(TokenInfo); + + //@TODO: fix +// Accounting::checkCredit(Privs, TARGOMAN_QUOTA_PREFIX+_engine+"MaxPerDay", Stats["tksTodayWords"].toDouble()+ SourceWordCount); +// Accounting::checkCredit(Privs, TARGOMAN_QUOTA_PREFIX+_engine+"MaxPerMonth", Stats["tksThisMonthWords"].toDouble()+ SourceWordCount); +// Accounting::checkCredit(Privs, TARGOMAN_QUOTA_PREFIX+_engine+"MaxTotal", Stats["tksTotalWords"].toDouble()+ SourceWordCount); +// Accounting::checkCredit(Privs, TARGOMAN_QUOTA_PREFIX+_dir+"MaxPerDay", Stats["tksTodayWords"].toDouble()+ SourceWordCount); +// Accounting::checkCredit(Privs, TARGOMAN_QUOTA_PREFIX+_dir+"MaxPerMonth", Stats["tksThisMonthWords"].toDouble()+ SourceWordCount); +// Accounting::checkCredit(Privs, TARGOMAN_QUOTA_PREFIX+_dir+"MaxTotal", Stats["tksTotalWords"].toDouble()+ SourceWordCount); +// Accounting::checkCredit(Privs, TARGOMAN_QUOTA_PREFIX+"MaxPerDay", Stats["tksTodayWords"].toDouble()+ SourceWordCount); +// Accounting::checkCredit(Privs, TARGOMAN_QUOTA_PREFIX+"MaxPerMonth", Stats["tksThisMonthWords"].toDouble()+ SourceWordCount); +// Accounting::checkCredit(Privs, TARGOMAN_QUOTA_PREFIX+"MaxTotal", Stats["tksTotalWords"].toDouble()+ SourceWordCount); + + if (_dic) { + if (Authorization::hasPriv(APICALLBOOM_PARAM, { TARGOMAN_PRIV_PREFIX + "Dic" })) { + if (_dicFull && Authorization::hasPriv(APICALLBOOM_PARAM, { TARGOMAN_PRIV_PREFIX + "DicFull" })) + throw exAuthorization("Not enought privileges to retrieve dictionary full response."); + + PreprocessTime = Timer.elapsed(); + Timer.restart(); + + QVariantMap DicResponse = MTHelper::instance().retrieveDicResponse(_text, Dir.first); + if (DicResponse.size()) { + if (_detailed) { + DicResponse[RESULTItems::TIMES] = QVariantMap({ + { RESULTItems::TIMESItems::PRE, PreprocessTime }, + { RESULTItems::TIMESItems::TR, Timer.elapsed() }, + { RESULTItems::TIMESItems::POST, 0} , + { RESULTItems::TIMESItems::ALL, PreprocessTime+Timer.elapsed() }, + }); + } + + MTHelper::instance().addDicLog(Dir.first, SourceWordCount, _text); + return DicResponse; + } + } else + throw exAuthorization("Not enought privileges to retrieve dictionary response."); + } + + PreprocessTime += Timer.elapsed(); + + try { + int InternalPreprocessTime = 0, InternalTranslationTime = 0, InternalPostprocessTime = 0; + + QVariantMap Translation = MTHelper::instance().doTranslation( + APICALLBOOM_PARAM, +// Privs, + this->DerivedHelperSubmodules, + _text, + Dir, + _engine, + true, + _detailed, + _detok, + InternalPreprocessTime, + InternalTranslationTime + ); + Timer.restart(); + + if (_detailed) { + Translation[RESULTItems::TIMES] = QVariantMap({ + { RESULTItems::TIMESItems::PRE, InternalPreprocessTime + PreprocessTime }, + { RESULTItems::TIMESItems::TR, InternalTranslationTime }, + { RESULTItems::TIMESItems::POST, InternalPostprocessTime + Timer.elapsed() }, + { RESULTItems::TIMESItems::ALL, OverallTime.elapsed() }, + }); + } else + Translation[RESULTItems::TIME] = OverallTime.elapsed(); + +// MTHelper::instance().addTranslationLog(static_cast(TokenInfo[TOKENItems::tokID].toInt()), _engine, _dir, SourceWordCount, _text, OverallTime.elapsed()); + + if (Authorization::hasPriv(APICALLBOOM_PARAM, { TARGOMAN_PRIV_PREFIX + "ReportServer" }) == false) + Translation.remove(RESULTItems::SERVERID); + + return Translation; + + } catch (exTargomanBase &_exp) { + MTHelper::instance().addErrorLog( + //static_cast(TokenInfo[TOKENItems::tokID].toInt()), + APICALLBOOM_PARAM.getActorID(), + _engine, + _dir, + SourceWordCount, + _text, + _exp.code()); + + throw; + } +} + +} //namespace Targoman::API::TargomanMTModule diff --git a/Modules/TargomanMT/moduleSrc/TargomanMT.h b/Modules/TargomanMT/moduleSrc/TargomanMT.h new file mode 100644 index 00000000..81e042ef --- /dev/null +++ b/Modules/TargomanMT/moduleSrc/TargomanMT.h @@ -0,0 +1,121 @@ +/****************************************************************************** +# TargomanAPI: REST API for Targoman +# +# Copyright 2014-2019 by Targoman Intelligent Processing +# +# TargomanAPI is free software: you can redistribute it and/or modify +# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# TargomanAPI is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# along with Targoman. If not, see . + ******************************************************************************/ +/** + * @author S. Mehran M. Ziabary + * @author Kambiz Zandi + */ + +#ifndef TARGOMAN_API_MODULES_TARGOMANMT_TARGOMAN_H +#define TARGOMAN_API_MODULES_TARGOMANMT_TARGOMAN_H + +#include "Interfaces/ORM/intfActionLogs.h" +#include "Interfaces/ORM/intfMigrations.h" +#include "Interfaces/ObjectStorage/ORM/ObjectStorage.h" +#include "libTargomanCommon/Configuration/tmplConfigurable.h" +#include "Interfaces/AAA/intfAccountingBasedModule.h" +#include "Interfaces/AAA/AAA.hpp" +#include "Interfaces/AAA/Accounting_Defs.hpp" +#include "Interfaces/ORM/intfFAQ.h" +using namespace Targoman::API::AAA; +using namespace Targoman::API::ORM; +#include "TargomanMTDefs.hpp" +#include "ModuleHelpers/MT/Classes/clsDerivedHelperSubmodules.h" + +using namespace Targoman::API::ModuleHelpers::MT::Classes; + +namespace Targoman::API::TargomanMTModule { + +constexpr char ASSET_ITEM_ADDITIONAL_INTO_KEY_PLUS_MAX_DAYS[] = "plus-max-days"; + +TARGOMAN_MIGRATIONS_PREPARENT; +TARGOMAN_ACTIONLOG_PREPARENT; +TARGOMAN_OBJECTSTORAGE_PREPARENT; +TARGOMAN_FAQ_PREPARENT; + +class TargomanMT : public intfAccountingBasedModule +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID INTFPUREMODULE_IID) + Q_INTERFACES(Targoman::API::API::intfPureModule) + //--------------------------------------------------------- + TARGOMAN_API_MODULE_DEFINE(TargomanMT); //, enuTokenActorType::API); + //--------------------------------------------------------- + TARGOMAN_API_MODULE_DEFINE_DB_CONFIGS(TargomanMT); + //--------------------------------------------------------- + TARGOMAN_API_MODULE_DEFINE_MIGRATIONS(TargomanMT, TargomanMTSchema); + TARGOMAN_API_MODULE_DEFINE_ACTIONLOG(TargomanMT, TargomanMTSchema); + TARGOMAN_API_MODULE_DEFINE_OBJECTSTORAGE(TargomanMT, TargomanMTSchema); + TARGOMAN_API_MODULE_DEFINE_FAQ(TargomanMT, TargomanMTSchema); + +public: + virtual QMap requiredDBs() const; + virtual void initializeModule(); + +protected: + virtual stuServiceCreditsInfo retrieveServiceCreditsInfo(quint64 _usrID); + + virtual void breakCredit(quint64 _slbID); + virtual bool isUnlimited(const UsageLimits_t& _limits) const; + virtual bool isEmpty(const UsageLimits_t& _limits) const; + + virtual void computeAdditives( + INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, + INOUT stuAssetItem &_assetItem, + const stuVoucherItem *_oldVoucherItem = nullptr + ); + + virtual void computeReferrer( + INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, + INOUT stuAssetItem &_assetItem, + const stuVoucherItem *_oldVoucherItem = nullptr + ); + + virtual QVariantMap getCustomUserAssetFieldsForQuery( + INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, + INOUT stuAssetItem &_assetItem, + const stuVoucherItem *_oldVoucherItem = nullptr + ); + +private slots: + QVariantMap REST_GET_OR_POST( + Translate, + ( + APICALLBOOM_TYPE_JWT_USER_OR_ANONYMOUSE_DECL &APICALLBOOM_PARAM, + QString _text, + QString _dir, + bool _detailed = false, + bool _detok = true, + bool _dic = false, + bool _dicFull = false + ), + "Translates input text" + ) + +private: + clsDerivedHelperSubmodules DerivedHelperSubmodules; +}; + +TARGOMAN_MIGRATIONS_POSTPARENT(TargomanMT, TargomanMTSchema); +TARGOMAN_ACTIONLOG_POSTPARENT(TargomanMT, TargomanMTSchema); +TARGOMAN_OBJECTSTORAGE_POSTPARENT(TargomanMT, TargomanMTSchema); +TARGOMAN_FAQ_POSTPARENT(TargomanMT, TargomanMTSchema); + +} //namespace Targoman::API::TargomanMTModule + +#endif // TARGOMAN_API_MODULES_TARGOMANMT_TARGOMAN_H diff --git a/Modules/TargomanMT/moduleSrc/TargomanMTDefs.hpp b/Modules/TargomanMT/moduleSrc/TargomanMTDefs.hpp new file mode 100644 index 00000000..649b19ac --- /dev/null +++ b/Modules/TargomanMT/moduleSrc/TargomanMTDefs.hpp @@ -0,0 +1,38 @@ +/****************************************************************************** +# TargomanAPI: REST API for Targoman +# +# Copyright 2014-2019 by Targoman Intelligent Processing +# +# TargomanAPI is free software: you can redistribute it and/or modify +# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# TargomanAPI is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# along with Targoman. If not, see . + ******************************************************************************/ +/** + * @author S. Mehran M. Ziabary + * @author Kambiz Zandi + */ + +#ifndef TARGOMAN_API_MODULES_TARGOMANMT_DEFS_HPP +#define TARGOMAN_API_MODULES_TARGOMANMT_DEFS_HPP + +#include "ModuleHelpers/MT/MTDefs.hpp" +#include "libTargomanCommon/Macros.h" +#include "Interfaces/Common/intfAPIArgManipulator.h" + +constexpr char TargomanMTDomain[] = "TargomanMT"; +constexpr char TargomanMTSchema[] = "TargomanMT"; + +namespace Targoman::API::TargomanMTModule { + +} //namespace Targoman::API::TargomanMTModule + +#endif // TARGOMAN_API_MODULES_TARGOMANMT_DEFS_HPP diff --git a/Modules/TargomanMT/moduleSrc/moduleSrc.pro b/Modules/TargomanMT/moduleSrc/moduleSrc.pro new file mode 100644 index 00000000..78c40924 --- /dev/null +++ b/Modules/TargomanMT/moduleSrc/moduleSrc.pro @@ -0,0 +1,28 @@ +################################################################################ +# QBuildSystem +# +# Copyright(c) 2021 by Targoman Intelligent Processing +# +# Redistribution and use in source and binary forms are allowed under the +# terms of BSD License 2.0. +################################################################################ +ModuleName=TargomanMT + +HEADERS += \ + TargomanMTDefs.hpp \ + ORM/MTHelpers.h \ + ORM/Accounting.h \ + TargomanMT.h + +SOURCES += \ + ORM/MTHelpers.cpp \ + ORM/Accounting.cpp \ + TargomanMT.cpp + +OTHER_FILES += \ + +LIBS += -lNLPHelper \ + -lMTHelper \ + +################################################################################ +include($$QBUILD_PATH/templates/moduleConfigs.pri) diff --git a/Modules/TextProcessor/TextProcessor.cpp b/Modules/TextProcessor/TextProcessor.cpp index ae1e8806..5b99ffdb 100644 --- a/Modules/TextProcessor/TextProcessor.cpp +++ b/Modules/TextProcessor/TextProcessor.cpp @@ -44,7 +44,7 @@ void TextProcessor::initializeModule() { } QString IMPL_REST_GET_OR_POST(TextProcessor, normalize, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, const QString _text, const TAPI::ISO639_2_t& _lang, bool _useSpellCorrector @@ -53,7 +53,7 @@ QString IMPL_REST_GET_OR_POST(TextProcessor, normalize, ( } QString IMPL_REST_GET_OR_POST(TextProcessor, text2IXML, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, const QString& _text, const TAPI::ISO639_2_t& _lang, bool _useSpellCorrector @@ -76,7 +76,7 @@ QString IMPL_REST_GET_OR_POST(TextProcessor, text2IXML, ( } QString IMPL_REST_GET_OR_POST(TextProcessor, ixml2Text, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, const QString& _ixml, bool _detokenize, bool _hinidiDigits, @@ -87,7 +87,7 @@ QString IMPL_REST_GET_OR_POST(TextProcessor, ixml2Text, ( } QString IMPL_REST_GET_OR_POST(TextProcessor, tokenize, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, const QString& _text, const TAPI::ISO639_2_t& _lang, bool _useSpellCorrector, diff --git a/Modules/TextProcessor/TextProcessor.h b/Modules/TextProcessor/TextProcessor.h index cb48ba1f..89564073 100644 --- a/Modules/TextProcessor/TextProcessor.h +++ b/Modules/TextProcessor/TextProcessor.h @@ -44,7 +44,7 @@ private slots: QString REST_GET_OR_POST( normalize, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, const QString _text, const TAPI::ISO639_2_t& _lang, bool _useSpellCorrector = true @@ -55,7 +55,7 @@ private slots: QString REST_GET_OR_POST( text2IXML, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, const QString& _text, const TAPI::ISO639_2_t& _lang, bool _useSpellCorrector = true @@ -66,7 +66,7 @@ private slots: QString REST_GET_OR_POST( ixml2Text, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, const QString& _ixml, bool _detokenize = true, bool _hinidiDigits = false, @@ -79,7 +79,7 @@ private slots: QString REST_GET_OR_POST( tokenize, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, const QString& _text, const TAPI::ISO639_2_t& _lang, bool _useSpellCorrector = true, diff --git a/Modules/URLProcessor/URLProcessor.cpp b/Modules/URLProcessor/URLProcessor.cpp index 3cf85413..e6ec5fa1 100644 --- a/Modules/URLProcessor/URLProcessor.cpp +++ b/Modules/URLProcessor/URLProcessor.cpp @@ -34,7 +34,7 @@ URLProcessor::URLProcessor() : intfPureModule("URLProcessor") { ; } QString IMPL_REST_GET(URLProcessor, canonicalize, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, const QString _url, bool _removeWWW )) { @@ -44,7 +44,7 @@ QString IMPL_REST_GET(URLProcessor, canonicalize, ( } QString IMPL_REST_GET(URLProcessor, convertHexCodes, ( - APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, const QString _url, bool _convertAll )) { diff --git a/Modules/URLProcessor/URLProcessor.h b/Modules/URLProcessor/URLProcessor.h index f2a42252..d5a821c9 100644 --- a/Modules/URLProcessor/URLProcessor.h +++ b/Modules/URLProcessor/URLProcessor.h @@ -41,7 +41,7 @@ private slots: QString REST_GET( canonicalize, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, const QString _url, bool _removeWWW = true ), @@ -51,7 +51,7 @@ private slots: QString REST_GET( convertHexCodes, ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM, const QString _url, bool _convertAll = false ), diff --git a/conf/api.conf b/conf/api.conf index ee6cf10d..4999f461 100644 --- a/conf/api.conf +++ b/conf/api.conf @@ -511,6 +511,40 @@ DB/Schema = MT ;ObjectStorage/TempLocalStoragePath = /targoman/data/MT/objectstorage +#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +# @@@ Module_TargomanMT SECTION @@@ +#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +[Module_TargomanMT] +# Database Host address +# Valid values: +# Default value: 127.0.0.1 +#--------------------------------------- +DB/Host = 127.0.0.1 + +# Database port +# Valid values: 10 to 65000 +# Default value: 3306 +#--------------------------------------- +DB/Port = 3306 + +# Database username for connection +# Valid values: +# Default value: root +#--------------------------------------- +DB/User = root + +# Database password +# Valid values: +# Default value: targoman123 +#--------------------------------------- +DB/Pass = targoman123 + +# Database schema +# Valid values: +# Default value: TargomanMT +#--------------------------------------- +DB/Schema = TargomanMT + #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # @@@ Module_NGTv1 SECTION @@@ #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/conf/migration.conf b/conf/migration.conf index a696afbb..f4bd4562 100644 --- a/conf/migration.conf +++ b/conf/migration.conf @@ -286,36 +286,42 @@ Projects/9/AllowDB = true Projects/9/AllowLocal = true Projects/9/DBDestinations = devdb1,proddb1 -Projects/10/Name = NGT -Projects/10/Tags = ActionLogs,FAQ +Projects/10/Name = TargomanMT +Projects/10/Tags = Accounting,ObjectStorage,ActionLogs,FAQ,MT Projects/10/AllowDB = true Projects/10/AllowLocal = true Projects/10/DBDestinations = devdb1,proddb1 -Projects/11/Name = MigrationTool +Projects/11/Name = NGT +Projects/11/Tags = ActionLogs,FAQ Projects/11/AllowDB = true Projects/11/AllowLocal = true -Projects/11/ApplyToTags = * +Projects/11/DBDestinations = devdb1,proddb1 -Projects/12/Name = Interfaces_Accounting +Projects/12/Name = MigrationTool Projects/12/AllowDB = true Projects/12/AllowLocal = true -Projects/12/ApplyToTags = Accounting +Projects/12/ApplyToTags = * -Projects/13/Name = Interfaces_ObjectStorage +Projects/13/Name = Interfaces_Accounting Projects/13/AllowDB = true Projects/13/AllowLocal = true -Projects/13/ApplyToTags = ObjectStorage +Projects/13/ApplyToTags = Accounting -Projects/14/Name = Interfaces_ActionLogs +Projects/14/Name = Interfaces_ObjectStorage Projects/14/AllowDB = true Projects/14/AllowLocal = true -Projects/14/ApplyToTags = ActionLogs +Projects/14/ApplyToTags = ObjectStorage -Projects/15/Name = Interfaces_FAQ +Projects/15/Name = Interfaces_ActionLogs Projects/15/AllowDB = true Projects/15/AllowLocal = true -Projects/15/ApplyToTags = FAQ +Projects/15/ApplyToTags = ActionLogs + +Projects/16/Name = Interfaces_FAQ +Projects/16/AllowDB = true +Projects/16/AllowLocal = true +Projects/16/ApplyToTags = FAQ RunningModes/0/Name = dev RunningModes/0/DBServers = devdb1 diff --git a/migrations/TargomanMT b/migrations/TargomanMT new file mode 120000 index 00000000..14f9b343 --- /dev/null +++ b/migrations/TargomanMT @@ -0,0 +1 @@ +../Modules/TargomanMT/migrations \ No newline at end of file