From 5506a8b1b71dec05585c0032eff9d38ba4f57092 Mon Sep 17 00:00:00 2001 From: kambizzandi Date: Sat, 1 Oct 2022 22:14:41 +0330 Subject: [PATCH 1/2] make api methods accept multi jwt actor type --- App/Server/OpenAPIGenerator.cpp | 6 +- App/Server/RESTAPIRegistry.cpp | 19 +- App/Server/clsAPIObject.cpp | 48 ++- App/Server/clsAPIObject.h | 35 ++- App/Server/clsRequestHandler.cpp | 80 +++-- Interfaces/AAA/Accounting_Interfaces.cpp | 17 +- Interfaces/AAA/Accounting_Interfaces.h | 88 +++++- Interfaces/AAA/clsJWT.hpp | 6 +- Interfaces/API/intfPureModule.h | 42 +-- Interfaces/Server/APICallBoom.cpp | 10 + Interfaces/Server/APICallBoom.h | 92 ++++-- Interfaces/Server/QJWT.cpp | 30 +- Interfaces/Server/QJWT.h | 5 +- .../MT/Classes/clsDerivedHelperSubmodules.cpp | 16 +- .../MT/Classes/clsDerivedHelperSubmodules.h | 26 +- ModuleHelpers/MT/Interfaces/intfMTHelpers.cpp | 6 +- ModuleHelpers/MT/Interfaces/intfMTHelpers.h | 34 +-- ModuleHelpers/MT/MTHelper.cpp | 273 ++++++------------ ModuleHelpers/MT/MTHelper.h | 12 +- Modules/MT/functionalTest/testMT.hpp | 19 ++ Modules/TargomanMT/moduleSrc/TargomanMT.cpp | 2 +- Modules/TargomanMT/moduleSrc/TargomanMT.h | 2 +- 22 files changed, 518 insertions(+), 350 deletions(-) diff --git a/App/Server/OpenAPIGenerator.cpp b/App/Server/OpenAPIGenerator.cpp index c38fffbd..7c2eb086 100644 --- a/App/Server/OpenAPIGenerator.cpp +++ b/App/Server/OpenAPIGenerator.cpp @@ -509,16 +509,14 @@ QJsonObject OpenAPIGenerator::retrieveJson( }); } -// if (APIObject->requiresJWT()) { - if (APIObject->tokenActorType() != enuTokenActorType::ANONYMOUSE) { + if (APIObject->mustProvideJWT()) { ResponseModel["401"] = QJsonObject({{ "description", "Authorization information is missing or invalid" }}); ResponseModel["403"] = QJsonObject({{ "description", "Access forbidden" }}); } PathInfo["responses"] = ResponseModel; -// if (APIObject->requiresJWT()) { - if (APIObject->tokenActorType() != enuTokenActorType::ANONYMOUSE) { + if (APIObject->mustProvideJWT()) { PathInfo["security"] = QJsonArray({ QJsonObject({ { "Bearer", QJsonArray() }, diff --git a/App/Server/RESTAPIRegistry.cpp b/App/Server/RESTAPIRegistry.cpp index aabb3086..b34f5486 100644 --- a/App/Server/RESTAPIRegistry.cpp +++ b/App/Server/RESTAPIRegistry.cpp @@ -397,8 +397,7 @@ QMap RESTAPIRegistry::extractMethods( clsAPIObject* APIObject = _registry.value(Key); QStringList Parameters; -// if (APIObject->requiresJWT()) - if (APIObject->tokenActorType() != enuTokenActorType::ANONYMOUSE) + if (APIObject->mustProvideJWT()) Parameters.append(QString(_showTypes ? "TAPI::JWT_t " : "") + "JWT"); for (quint8 i=0; i/*BaseMethod.parameterCount()*/ParamTypesName.count(); ++i) { @@ -704,12 +703,16 @@ void RESTAPIRegistry::dumpAPIs() bool IsLastMethod = (Method == Methods.last()); QString JWTType = ""; -// if (API.APIObject->requiresJWT()) - if (API.APIObject->tokenActorType() != enuTokenActorType::ANONYMOUSE) - JWTType = QString(" (JWT:%1%2)") - .arg(enuTokenActorType::toStr(API.APIObject->tokenActorType())) - .arg(API.APIObject->tokenIsOptional() ? "/OPTIONAL" : "") - ; + if (API.APIObject->canProvideJWT()) { + QStringList JWTTypesList; + if (API.APIObject->tokenAllowANONYMOUSE()) + JWTTypesList.append("ANONYMOUSE"); + if (API.APIObject->tokenAllowUSER()) + JWTTypesList.append("USER"); + if (API.APIObject->tokenAllowAPI()) + JWTTypesList.append("API"); + JWTType = QString(" (JWT:%1)").arg(JWTTypesList.join(',')); + } TargomanDebug(5).noLabel().noquote().nospace() << (IsLastAPI ? " " : "│") << " " diff --git a/App/Server/clsAPIObject.cpp b/App/Server/clsAPIObject.cpp index 584fa005..78662cd9 100644 --- a/App/Server/clsAPIObject.cpp +++ b/App/Server/clsAPIObject.cpp @@ -56,8 +56,11 @@ clsAPIObject::clsAPIObject( HasExtraMethodName(_hasExtraMethodName), Parent(_module), // RequiresJWT(false) - TokenActorType(enuTokenActorType::ANONYMOUSE), - TokenIsOptional(true) +// TokenActorType(enuTokenActorType::ANONYMOUSE), +// TokenIsOptional(true) + TokenAllowANONYMOUSE(false), + TokenAllowUSER(false), + TokenAllowAPI(false) { QList parameterTypes = _method.parameterTypes(); quint8 i = 0; @@ -74,19 +77,36 @@ clsAPIObject::clsAPIObject( --this->RequiredParamsCount; this->BaseMethod.DefaultValues.removeAt(0); - 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; - this->TokenIsOptional = true; + if (ParameterTypeName.startsWith(APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL_STR)) { + this->TokenAllowANONYMOUSE = true; + this->TokenAllowUSER = false; + this->TokenAllowAPI = false; + } else if (ParameterTypeName.startsWith(APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_DECL_STR)) { + this->TokenAllowANONYMOUSE = true; + this->TokenAllowUSER = true; + this->TokenAllowAPI = false; + } else if (ParameterTypeName.startsWith(APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_API_DECL_STR)) { + this->TokenAllowANONYMOUSE = true; + this->TokenAllowUSER = false; + this->TokenAllowAPI = true; + } else if (ParameterTypeName.startsWith(APICALLBOOM_TYPE_JWT_USER_DECL_STR)) { + this->TokenAllowANONYMOUSE = false; + this->TokenAllowUSER = true; + this->TokenAllowAPI = false; } 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; - } + this->TokenAllowANONYMOUSE = false; + this->TokenAllowUSER = false; + this->TokenAllowAPI = true; + } else if (ParameterTypeName.startsWith(APICALLBOOM_TYPE_JWT_USER_OR_API_DECL_STR)) { + this->TokenAllowANONYMOUSE = false; + this->TokenAllowUSER = true; + this->TokenAllowAPI = true; + } else if (ParameterTypeName.startsWith(APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_OR_API_DECL_STR)) { + this->TokenAllowANONYMOUSE = true; + this->TokenAllowUSER = true; + this->TokenAllowAPI = true; + } else + throw exHTTPInternalServerError(QString("Unknown jwt type: %1").arg(ParameterTypeName)); } else { QByteArray ParamNameNoUnderScore = (ParamName.startsWith('_') ? ParamName.mid(1) : ParamName); diff --git a/App/Server/clsAPIObject.h b/App/Server/clsAPIObject.h index a95c9f6e..fa1983a9 100644 --- a/App/Server/clsAPIObject.h +++ b/App/Server/clsAPIObject.h @@ -79,15 +79,26 @@ class clsAPIObject : public intfAPIObject, public QObject return this->Parent; } -// inline bool requiresJWT() const { -// return this->RequiresJWT; //ParamTypesName.contains(PARAM_JWT); -// } +// enuTokenActorType::Type tokenActorType() { return this->TokenActorType; } +// bool tokenIsOptional() { return this->TokenIsOptional; } -// inline enuTokenActorType::Type moduleActorType() const { -// return this->Parent->actorType(); -// } - enuTokenActorType::Type tokenActorType() { return this->TokenActorType; } - bool tokenIsOptional() { return this->TokenIsOptional; } + bool tokenAllowANONYMOUSE() { return this->TokenAllowANONYMOUSE; } + bool tokenAllowUSER() { return this->TokenAllowUSER; } + bool tokenAllowAPI() { return this->TokenAllowAPI; } + + inline bool mustProvideJWT() { + return ((this->tokenAllowANONYMOUSE() == false) + && (this->tokenAllowUSER() || this->tokenAllowAPI()) + ); + } + inline bool canProvideJWT() { + return (this->tokenAllowANONYMOUSE() + && (this->tokenAllowUSER() || this->tokenAllowAPI()) + ); + } + inline bool noJWTNeeded() { + return ((this->tokenAllowUSER() == false) && (this->tokenAllowAPI() == false)); + } // inline bool requiresCookies() const { // return this->ParamTypesName.contains(PARAM_COOKIES); @@ -164,9 +175,11 @@ class clsAPIObject : public intfAPIObject, public QObject quint8 RequiredParamsCount; bool HasExtraMethodName; intfPureModule* Parent; -// bool RequiresJWT; - enuTokenActorType::Type TokenActorType; - bool TokenIsOptional; +// enuTokenActorType::Type TokenActorType; +// bool TokenIsOptional; + bool TokenAllowANONYMOUSE; + bool TokenAllowUSER; + bool TokenAllowAPI; friend class RESTAPIRegistry; friend class OpenAPIGenerator; diff --git a/App/Server/clsRequestHandler.cpp b/App/Server/clsRequestHandler.cpp index 2867521f..a70c78a4 100644 --- a/App/Server/clsRequestHandler.cpp +++ b/App/Server/clsRequestHandler.cpp @@ -335,25 +335,51 @@ clsRequestHandler::stuResult clsRequestHandler::run( const QString& _pksByPath, const QString& _api ) { - auto fnTiming = [=](const QString &_name, const QString &_desc, quint64 _nanoSecs) { + auto FnTiming = [=](const QString &_name, const QString &_desc, quint64 _nanoSecs) { this->addToTimings(_name, _desc, _nanoSecs); }; - enuTokenActorType::Type TokenActorType = _apiObject->tokenActorType(); QScopedPointer APICALLBOOM; - 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)); + if (_apiObject->tokenAllowANONYMOUSE()) { + if (_apiObject->tokenAllowUSER()) { + if (_apiObject->tokenAllowAPI()) + APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_OR_API_DECL(FnTiming)); + else + APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_DECL(FnTiming)); + } else { + if (_apiObject->tokenAllowAPI()) + APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_API_DECL(FnTiming)); + else + APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL(FnTiming)); + } + } else { + if (_apiObject->tokenAllowUSER()) { + if (_apiObject->tokenAllowAPI()) + APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_USER_OR_API_DECL(FnTiming)); + else + APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_USER_DECL(FnTiming)); + } else { + if (_apiObject->tokenAllowAPI()) + APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_API_DECL(FnTiming)); + else + throw exHTTPInternalServerError("jwt f,f,f"); + } + } + +// enuTokenActorType::Type TokenActorType = _apiObject->tokenActorType(); +// if (TokenActorType == enuTokenActorType::USER) { +// if (_apiObject->tokenIsOptional()) +// APICALLBOOM.reset(new APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_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_ANONYMOUSE_OR_API_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) @@ -379,26 +405,28 @@ clsRequestHandler::stuResult clsRequestHandler::run( } if (BearerToken.isEmpty()) { - if ((TokenActorType != enuTokenActorType::ANONYMOUSE) - && (_apiObject->tokenIsOptional() == false)) - throw exHTTPForbidden("No authentication header is present"); - - } else if (TokenActorType == enuTokenActorType::ANONYMOUSE) { + if (_apiObject->mustProvideJWT()) + throw exHTTPForbidden("No authentication header is present"); + } else if (_apiObject->noJWTNeeded()) { // 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 { + TAPI::enuTokenActorType::Type JWTTokenActorType; + QJWT::verifyJWT( BearerToken, RemoteIP, - TokenActorType, + _apiObject->tokenAllowUSER(), + _apiObject->tokenAllowAPI(), + JWTTokenActorType, JWT ); //check svcs just for API tokens - if ((TokenActorType == enuTokenActorType::API) + if ((JWTTokenActorType == enuTokenActorType::API) && JWT.contains("prv") && JWT["prv"].toObject().contains("svc")) { QString ModuleBaseName = _apiObject->parentModule()->moduleBaseName().split(":").first(); if (ModuleBaseName.isEmpty() == false) { @@ -409,12 +437,12 @@ clsRequestHandler::stuResult clsRequestHandler::run( } } catch (exJWTExpired &exp) { - enuTokenActorType::Type TokenType = enuTokenActorType::USER; + enuTokenActorType::Type JWTTokenActorType = enuTokenActorType::USER; if (JWT.contains("typ")) - TokenType = enuTokenActorType::toEnum(JWT["typ"].toString()); + JWTTokenActorType = enuTokenActorType::toEnum(JWT["typ"].toString()); - if (TokenType == enuTokenActorType::USER) { + if (JWTTokenActorType == enuTokenActorType::USER) { auto RenewJWTServerTiming = APICALLBOOM->createScopeTiming("jwt", "renew"); bool IsRenewed = false; @@ -433,10 +461,10 @@ clsRequestHandler::stuResult clsRequestHandler::run( APICALLBOOM->addResponseHeader("x-auth-warning", "replace token"); APICALLBOOM->addResponseHeaderNameToExpose("x-auth-warning"); } - } else if (TokenType == enuTokenActorType::API) + } else if (JWTTokenActorType == enuTokenActorType::API) throw exHTTPForbidden("API token is expired"); else - throw exHTTPForbidden(QString("Unknown token type `%1`").arg(TokenType)); + throw exHTTPForbidden(QString("Unknown token type `%1`").arg(JWTTokenActorType)); } //catch (exJWTExpired &exp) JWT["encodedJWT"] = BearerToken; diff --git a/Interfaces/AAA/Accounting_Interfaces.cpp b/Interfaces/AAA/Accounting_Interfaces.cpp index e04ab02e..beec8a2a 100644 --- a/Interfaces/AAA/Accounting_Interfaces.cpp +++ b/Interfaces/AAA/Accounting_Interfaces.cpp @@ -698,9 +698,22 @@ ORMSelectQuery intfAccountUserAssets::makeSelectQuery(INTFAPICALLBOOM_IMPL &APIC return Query; } -QVariant IMPL_ORMGET_USER(intfAccountUserAssets) { +QVariant IMPL_ORMGET_USER_OR_API(intfAccountUserAssets) { + + + + + if (APICALLBOOM_PARAM.jwtActorType() == TAPI::enuTokenActorType::USER) { + + } else { //API + + } + + + + if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false) - this->setSelfFilters({{tblAccountUserAssetsBase::Fields::uas_actorID, APICALLBOOM_PARAM.getActorID() }}, _filters); + this->setSelfFilters({{ tblAccountUserAssetsBase::Fields::uas_actorID, APICALLBOOM_PARAM.getActorID() }}, _filters); auto fnTouchQuery = [this, &_cols](ORMSelectQuery &_query) { if (_cols.isEmpty()) diff --git a/Interfaces/AAA/Accounting_Interfaces.h b/Interfaces/AAA/Accounting_Interfaces.h index 4107d410..5bb04a91 100644 --- a/Interfaces/AAA/Accounting_Interfaces.h +++ b/Interfaces/AAA/Accounting_Interfaces.h @@ -31,19 +31,90 @@ using namespace Targoman::API::API; namespace Targoman::API::AAA { +/******************************************************\ + +If!TB: If NOT token base +If=TB: If IS token base + +------------------|-------|-------|-------|--------- +AccountUnits | ANONY | USER | API | +------------------|-------|-------|-------|--------- + C | | x | | + R | x | x | | + U | | x | | + D | | x | | + +------------------|-------|-------|-------|--------- +AccountProducts | ANONY | USER | API | +------------------|-------|-------|-------|--------- + C | | x | | + R | x | x | | + U | | x | | + D | | x | | + +------------------|-------|-------|-------|--------- +AccountSaleables | ANONY | USER | API | +------------------|-------|-------|-------|--------- + C | | x | | + R | x | x | | + U | | x | | + D | | x | | + +------------------|-------|-------|-------|--------- +AccountUserAssets | ANONY | USER | API | +------------------|-------|-------|-------|--------- + C | | x | | + R | | If!TB | If=TB | + U | | | | + D | | | | + +------------------|-------|-------|-------|--------- +AccountAssetUsage | ANONY | USER | API | +------------------|-------|-------|-------|--------- + C | | If!TB | If=TB | + R | | x | If=TB | + U | | x | If=TB | + D | | | | + +------------------|-------|-------|-------|--------- +AccountCoupons | ANONY | USER | API | +------------------|-------|-------|-------|--------- + C | | x | | + R | x | x | | + U | | x | | + D | | x | | + +------------------|-------|-------|-------|--------- +AccountPrizes | ANONY | USER | API | +------------------|-------|-------|-------|--------- + C | | | | + R | | | | + U | | | | + D | | | | +------------------|-------|-------|-------|--------- + +\******************************************************/ + + /******************************************************/ -/* +template class intfAccountORMBase { public: - intfAccountORMBase(bool _isTokenBase) : - IsTokenBase(_isTokenBase) - { ; } + typedef typename std::conditional<_itmplIsTokenBase, + APICALLBOOM_TYPE_JWT_API_DECL, + APICALLBOOM_TYPE_JWT_USER_DECL>::type + ACCORM_JWT_TYPE_DECL; + + typedef Q_DECL_UNUSED typename std::conditional<_itmplIsTokenBase, + APICALLBOOM_TYPE_JWT_API_DECL, + APICALLBOOM_TYPE_JWT_USER_DECL>::type + ACCORM_JWT_TYPE_IMPL; public: - bool IsTokenBase; + bool IsTokenBase() { return _itmplIsTokenBase; } }; -*/ + /******************************************************/ /******************************************************/ /******************************************************/ @@ -219,7 +290,7 @@ class intfAccountUserAssets : public intfSQLBasedModule//, public intfAccountORM virtual ORMSelectQuery makeSelectQuery(INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, const QString &_alias = {}, bool _translate = true, bool _isRoot = true); private slots: - QVariant ORMGET_USER("Get User Assets") + QVariant ORMGET_USER_OR_API("Get User Assets") bool REST_UPDATE( disablePackage, @@ -266,7 +337,8 @@ private slots: /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountAssetUsage : public intfSQLBasedModule//, public intfAccountORMBase +//template +class intfAccountAssetUsage : public intfSQLBasedModule//, public intfAccountORMBase<_itmplIsTokenBase> { Q_OBJECT diff --git a/Interfaces/AAA/clsJWT.hpp b/Interfaces/AAA/clsJWT.hpp index d775452b..38fbb142 100644 --- a/Interfaces/AAA/clsJWT.hpp +++ b/Interfaces/AAA/clsJWT.hpp @@ -63,7 +63,11 @@ class clsJWT { inline quint64 expireAt() const { return static_cast(this->Token.value(JWTItems::exp).toDouble()); } // inline quint64 actorID() const { return static_cast(this->Token.value(JWTItems::uid).toDouble()); } - inline TAPI::enuTokenActorType::Type actorType() const { return TAPI::enuTokenActorType::toEnum(this->Token.value(JWTItems::typ).toString()); } + inline TAPI::enuTokenActorType::Type actorType() const { + if (this->Token.contains(JWTItems::typ) == false) + return TAPI::enuTokenActorType::USER; + return TAPI::enuTokenActorType::toEnum(this->Token.value(JWTItems::typ).toString()); + } // inline QVariantMap privatePart() const { return this->Token.value(JWTItems::priv).toObject().toVariantMap(); } inline QVariantMap privs() const { return this->Token.value(JWTItems::privs).toObject().toVariantMap(); } diff --git a/Interfaces/API/intfPureModule.h b/Interfaces/API/intfPureModule.h index 8de5a5bf..a447f03b 100644 --- a/Interfaces/API/intfPureModule.h +++ b/Interfaces/API/intfPureModule.h @@ -77,33 +77,41 @@ using namespace TAPI; bool _reportCount, \ bool _translate -#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_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) - -#define ORMGET_ANONYMOUSE(_doc, ...) apiGET(ANONYMOUSE_GET_METHOD_ARGS_DECL_APICALL) __VA_ARGS__; \ - QString signOfGET() { return TARGOMAN_M2STR((USER_GET_METHOD_ARGS_DECL_APICALL)); } \ +#define GET_METHOD_ARGS_ANONYMOUSE_DECL_APICALL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL) +#define GET_METHOD_ARGS_USER_DECL_APICALL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(APICALLBOOM_TYPE_JWT_USER_DECL) +#define GET_METHOD_ARGS_API_DECL_APICALL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(APICALLBOOM_TYPE_JWT_API_DECL) +#define GET_METHOD_ARGS_USER_OR_API_DECL_APICALL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(APICALLBOOM_TYPE_JWT_USER_OR_API_DECL) + +#define GET_METHOD_ARGS_ANONYMOUSE_IMPL_APICALL INTERNAL_GET_METHOD_ARGS_IMPL_APICALL(APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL) +#define GET_METHOD_ARGS_USER_IMPL_APICALL INTERNAL_GET_METHOD_ARGS_IMPL_APICALL(APICALLBOOM_TYPE_JWT_USER_IMPL) +#define GET_METHOD_ARGS_API_IMPL_APICALL INTERNAL_GET_METHOD_ARGS_IMPL_APICALL(APICALLBOOM_TYPE_JWT_API_IMPL) +#define GET_METHOD_ARGS_USER_OR_API_IMPL_APICALL INTERNAL_GET_METHOD_ARGS_IMPL_APICALL(APICALLBOOM_TYPE_JWT_USER_OR_API_IMPL) + +#define ORMGET_ANONYMOUSE(_doc, ...) apiGET(GET_METHOD_ARGS_ANONYMOUSE_DECL_APICALL) __VA_ARGS__; \ + QString signOfGET() { return TARGOMAN_M2STR((GET_METHOD_ARGS_USER_DECL_APICALL)); } \ QString docOfGET() { return _doc; } #define ORMGET_ANONYMOUSE_HIDDEN(_doc, ...) ORMGET_ANONYMOUSE(_doc, __VA_ARGS__); ORM_EX_CONFIG(GET, { EXRESTCONFIG_HIDDEN }) -#define ORMGET_USER(_doc, ...) apiGET(USER_GET_METHOD_ARGS_DECL_APICALL) __VA_ARGS__; \ - QString signOfGET() { return TARGOMAN_M2STR((USER_GET_METHOD_ARGS_DECL_APICALL)); } \ +#define ORMGET_USER(_doc, ...) apiGET(GET_METHOD_ARGS_USER_DECL_APICALL) __VA_ARGS__; \ + QString signOfGET() { return TARGOMAN_M2STR((GET_METHOD_ARGS_USER_DECL_APICALL)); } \ QString docOfGET() { return _doc; } -#define IMPL_ORMGET_ANONYMOUSE(_module) _module::apiGET(ANONYMOUSE_GET_METHOD_ARGS_IMPL_APICALL) -#define IMPL_ORMGET_USER(_module) _module::apiGET(USER_GET_METHOD_ARGS_IMPL_APICALL) -#define IMPL_ORMGET_API(_module) _module::apiGET(API_GET_METHOD_ARGS_IMPL_APICALL) - #define ORMGET_USER_HIDDEN(_doc, ...) ORMGET_USER(_doc, __VA_ARGS__); ORM_EX_CONFIG(GET, { EXRESTCONFIG_HIDDEN }) -#define ORMGET_USER_ByName(_name, _doc, ...) apiGET##_name(USER_GET_METHOD_ARGS_DECL_APICALL) __VA_ARGS__; \ - QString signOfGET##_name() { return TARGOMAN_M2STR((USER_GET_METHOD_ARGS_DECL_APICALL)); } \ +#define ORMGET_USER_ByName(_name, _doc, ...) apiGET##_name(GET_METHOD_ARGS_USER_DECL_APICALL) __VA_ARGS__; \ + QString signOfGET##_name() { return TARGOMAN_M2STR((GET_METHOD_ARGS_USER_DECL_APICALL)); } \ QString docOfGET##_name() { return _doc; } +#define ORMGET_USER_OR_API(_doc, ...) apiGET(GET_METHOD_ARGS_USER_OR_API_DECL_APICALL) __VA_ARGS__; \ + QString signOfGET() { return TARGOMAN_M2STR((GET_METHOD_ARGS_USER_OR_API_DECL_APICALL)); } \ + QString docOfGET() { return _doc; } + +#define IMPL_ORMGET_ANONYMOUSE(_module) _module::apiGET(GET_METHOD_ARGS_ANONYMOUSE_IMPL_APICALL) +#define IMPL_ORMGET_USER(_module) _module::apiGET(GET_METHOD_ARGS_USER_IMPL_APICALL) +#define IMPL_ORMGET_API(_module) _module::apiGET(GET_METHOD_ARGS_API_IMPL_APICALL) +#define IMPL_ORMGET_USER_OR_API(_module) _module::apiGET(GET_METHOD_ARGS_USER_OR_API_IMPL_APICALL) + //used by intfSQLBasedModule #define GET_METHOD_ARGS_DECL_INTERNAL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(INTFAPICALLBOOM_DECL) #define GET_METHOD_ARGS_IMPL_INTERNAL INTERNAL_GET_METHOD_ARGS_IMPL_APICALL(INTFAPICALLBOOM_IMPL) diff --git a/Interfaces/Server/APICallBoom.cpp b/Interfaces/Server/APICallBoom.cpp index a3f449b2..2b78acbe 100644 --- a/Interfaces/Server/APICallBoom.cpp +++ b/Interfaces/Server/APICallBoom.cpp @@ -137,6 +137,12 @@ void intfAPICallBoom::setJWT(/*TAPI::JWT_t*/QJsonObject &_JWT) { bool intfAPICallBoom::isAnonymouse() { return this->Data->JWT.isEmpty(); } +TAPI::enuTokenActorType::Type intfAPICallBoom::jwtActorType() { + if (this->isAnonymouse()) + return TAPI::enuTokenActorType::ANONYMOUSE; + + return Targoman::API::AAA::clsJWT(this->Data->JWT).actorType(); +} quint64 intfAPICallBoom::getActorID(quint64 _default) { quint64 ActorID = Targoman::API::AAA::clsJWT(this->Data->JWT).actorID(); @@ -256,8 +262,12 @@ void intfAPICallBoom::addToTimings(const QString &_name, const QString &_desc, q this->Data->FNTiming(_name, _desc, _nanoSecs); } +//-------------------------------------------------------------------- template class APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL; template class APICALLBOOM_TYPE_JWT_USER_DECL; template class APICALLBOOM_TYPE_JWT_API_DECL; +template class APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_DECL; +template class APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_API_DECL; + } //namespace Targoman::API::Server diff --git a/Interfaces/Server/APICallBoom.h b/Interfaces/Server/APICallBoom.h index 30862fd3..48a42437 100644 --- a/Interfaces/Server/APICallBoom.h +++ b/Interfaces/Server/APICallBoom.h @@ -53,39 +53,62 @@ TARGOMAN_DEFINE_ENUM(enuTokenActorType, //-- NO JWT //just for use in api methods (.h) -#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL APICallBoom -#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL_STR TARGOMAN_M2STR(APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL) - +//#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL APICallBoom +//#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL_STR TARGOMAN_M2STR(APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL) +#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL APICallBoom +#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL_STR "APICallBoom" //just for use in api methods (.cpp) #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 -#define APICALLBOOM_TYPE_JWT_USER_DECL_STR "APICallBoom" //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) +#define APICALLBOOM_TYPE_JWT_USER_DECL APICallBoom +#define APICALLBOOM_TYPE_JWT_USER_DECL_STR "APICallBoom" //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 +//-- JWT : ANONYMOUSE or USER //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) +//#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_DECL APICallBoom +//#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_DECL_STR "APICallBoom" //TARGOMAN_M2STR(APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_DECL) +#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_DECL APICallBoom +#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_DECL_STR "APICallBoom" //just for use in api methods (.cpp) -#define APICALLBOOM_TYPE_JWT_USER_OR_ANONYMOUSE_IMPL Q_DECL_UNUSED APICALLBOOM_TYPE_JWT_USER_OR_ANONYMOUSE_DECL +#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_IMPL Q_DECL_UNUSED APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_DECL //-- JWT : API //just for use in api methods (.h) -#define APICALLBOOM_TYPE_JWT_API_DECL APICallBoom -#define APICALLBOOM_TYPE_JWT_API_DECL_STR "APICallBoom" //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) +#define APICALLBOOM_TYPE_JWT_API_DECL APICallBoom +#define APICALLBOOM_TYPE_JWT_API_DECL_STR "APICallBoom" //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 +//-- JWT : ANONYMOUSE or API +//just for use in api methods (.h) +//#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_API_DECL APICallBoom +//#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_API_DECL_STR "APICallBoom" //TARGOMAN_M2STR(APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_API_DECL) +#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_API_DECL APICallBoom +#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_API_DECL_STR "APICallBoom" +//just for use in api methods (.cpp) +#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_API_IMPL Q_DECL_UNUSED APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_API_DECL + +//-- JWT : ANONYMOUSE or USER or API +//just for use in api methods (.h) +#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_OR_API_DECL APICallBoom +#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_OR_API_DECL_STR "APICallBoom" +//just for use in api methods (.cpp) +#define APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_OR_API_IMPL Q_DECL_UNUSED APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_OR_API_DECL + +//-- JWT : USER or API //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) +#define APICALLBOOM_TYPE_JWT_USER_OR_API_DECL APICallBoom +#define APICALLBOOM_TYPE_JWT_USER_OR_API_DECL_STR "APICallBoom" //just for use in api methods (.cpp) -#define APICALLBOOM_TYPE_JWT_API_OR_ANONYMOUSE_IMPL Q_DECL_UNUSED APICALLBOOM_TYPE_JWT_API_OR_ANONYMOUSE_DECL +#define APICALLBOOM_TYPE_JWT_USER_OR_API_IMPL Q_DECL_UNUSED APICALLBOOM_TYPE_JWT_USER_OR_API_DECL //-- #define INTFAPICALLBOOM intfAPICallBoom @@ -121,12 +144,27 @@ class intfAPICallBoom ); // virtual bool needJWT() = 0; - virtual TAPI::enuTokenActorType::Type tokenActorType() = 0; - virtual bool tokenIsOptional() = 0; +// virtual TAPI::enuTokenActorType::Type tokenActorType() = 0; +// virtual bool tokenIsOptional() = 0; + virtual bool tokenAllowANONYMOUSE() = 0; + virtual bool tokenAllowUSER() = 0; + virtual bool tokenAllowAPI() = 0; + + inline bool mustProvideJWT() { + return ((this->tokenAllowANONYMOUSE() == false) + && (this->tokenAllowUSER() || this->tokenAllowAPI()) + ); + } + inline bool canProvideJWT() { + return (this->tokenAllowANONYMOUSE() + && (this->tokenAllowUSER() || this->tokenAllowAPI()) + ); + } void setJWT(/*TAPI::JWT_t*/QJsonObject &_JWT); /*TAPI::JWT_t*/QJsonObject &getJWT(); bool isAnonymouse(); + TAPI::enuTokenActorType::Type jwtActorType(); quint64 getActorID(quint64 _default=0); QJsonObject getJWTPrivsObject(); @@ -201,7 +239,7 @@ class intfAPICallBoom QExplicitlySharedDataPointer Data; }; -template +template class APICallBoom : public intfAPICallBoom { public: @@ -209,10 +247,24 @@ class APICallBoom : public intfAPICallBoom intfAPICallBoom(_fnTiming) { ; } - virtual TAPI::enuTokenActorType::Type tokenActorType() final { return _tokenActorType; } - virtual bool tokenIsOptional() { return _tokenIsOptional; } +// virtual TAPI::enuTokenActorType::Type tokenActorType() final { return _tokenActorType; } + virtual bool tokenAllowANONYMOUSE() { return _itmplAllowANONYMOUSE; } + virtual bool tokenAllowUSER() { return _itmplAllowUSER; } + virtual bool tokenAllowAPI() { return _itmplAllowAPI; } }; +//template +//class APICallBoom : public intfAPICallBoom +//{ +//public: +// APICallBoom(std::function _fnTiming) : +// intfAPICallBoom(_fnTiming) +// { ; } + +// virtual TAPI::enuTokenActorType::Type tokenActorType() final { return _tokenActorType; } +// virtual bool tokenIsOptional() { return _tokenIsOptional; } +//}; + } //namespace Targoman::API::Server #endif // TARGOMAN_API_SERVER_APICALLBOOM_H diff --git a/Interfaces/Server/QJWT.cpp b/Interfaces/Server/QJWT.cpp index c9d05e1c..eda0b16f 100644 --- a/Interfaces/Server/QJWT.cpp +++ b/Interfaces/Server/QJWT.cpp @@ -225,20 +225,32 @@ void QJWT::extractAndDecryptPayload( void QJWT::verifyJWT( const QString &_jwt, Q_DECL_UNUSED const QString &_remoteIP, - const enuTokenActorType::Type &_acceptableActorType, +// const enuTokenActorType::Type &_acceptableActorType, + bool _tokenAllowUSER, + bool _tokenAllowAPI, + TAPI::enuTokenActorType::Type &_jwtTokenActorType, TAPI::JWT_t &_jWTPayload ) { QJWT::extractAndDecryptPayload(_jwt, _jWTPayload); //-- check actor type ----- - enuTokenActorType::Type TokenType = enuTokenActorType::USER; + _jwtTokenActorType = enuTokenActorType::USER; if (_jWTPayload.contains("typ")) - TokenType = enuTokenActorType::toEnum(_jWTPayload["typ"].toString()); - - if (TokenType != _acceptableActorType) - throw exHTTPForbidden(QString("Token type `%1` not acceptable by this module. expected: %2") - .arg(enuTokenActorType::toStr(TokenType)) - .arg(enuTokenActorType::toStr(_acceptableActorType))); + _jwtTokenActorType = enuTokenActorType::toEnum(_jWTPayload["typ"].toString()); + + if ((_jwtTokenActorType == enuTokenActorType::USER) && (_tokenAllowUSER == false)) +// if (TokenType != _acceptableActorType) + throw exHTTPForbidden(QString("Token type `%1` not acceptable by this module. expected: USER") + .arg(enuTokenActorType::toStr(_jwtTokenActorType)) +// .arg(enuTokenActorType::toStr(_acceptableActorType)) + ); + + if ((_jwtTokenActorType == enuTokenActorType::API) && (_tokenAllowAPI == false)) +// if (TokenType != _acceptableActorType) + throw exHTTPForbidden(QString("Token type `%1` not acceptable by this module. expected: API") + .arg(enuTokenActorType::toStr(_jwtTokenActorType)) +// .arg(enuTokenActorType::toStr(_acceptableActorType)) + ); //-- check client ip ----- // if (_jWTPayload.contains("prv")) { @@ -251,7 +263,7 @@ void QJWT::verifyJWT( uint currentDateTime = QDateTime::currentDateTime().toTime_t(); //-- check large expiration ----- - if (TokenType == enuTokenActorType::USER) { + if (_jwtTokenActorType == enuTokenActorType::USER) { if (_jWTPayload.contains("ssnexp") == false) throw exHTTPForbidden("Invalid ssnexp in JWT"); diff --git a/Interfaces/Server/QJWT.h b/Interfaces/Server/QJWT.h index c3fa97af..7d7d42ee 100644 --- a/Interfaces/Server/QJWT.h +++ b/Interfaces/Server/QJWT.h @@ -72,7 +72,10 @@ class QJWT static void verifyJWT( const QString &_jwt, const QString &_remoteIP, - const TAPI::enuTokenActorType::Type &_acceptableActorType, +// const TAPI::enuTokenActorType::Type &_acceptableActorType, + bool _tokenAllowUSER, + bool _tokenAllowAPI, + TAPI::enuTokenActorType::Type &_jwtTokenActorType, TAPI::JWT_t &_jWTPayload ); diff --git a/ModuleHelpers/MT/Classes/clsDerivedHelperSubmodules.cpp b/ModuleHelpers/MT/Classes/clsDerivedHelperSubmodules.cpp index 2a94aa4e..93e46814 100644 --- a/ModuleHelpers/MT/Classes/clsDerivedHelperSubmodules.cpp +++ b/ModuleHelpers/MT/Classes/clsDerivedHelperSubmodules.cpp @@ -25,14 +25,14 @@ namespace Targoman::API::ModuleHelpers::MT::Classes { -template -clsDerivedHelperSubmodules<_tokenActorType>::clsDerivedHelperSubmodules( - intfCorrectionRules<_tokenActorType> *_correctionRules, - intfDigestedTranslationLogs<_tokenActorType> *_digestedTranslationLogs, - intfMultiDic<_tokenActorType> *_multiDic, - intfTokenStats<_tokenActorType> *_tokenStats, - intfTranslatedPhrases<_tokenActorType> *_translatedPhrases, - intfTranslationLogs<_tokenActorType> *_translationLogs +template +clsDerivedHelperSubmodules<_itmplTokenActorType>::clsDerivedHelperSubmodules( + intfCorrectionRules<_itmplTokenActorType> *_correctionRules, + intfDigestedTranslationLogs<_itmplTokenActorType> *_digestedTranslationLogs, + intfMultiDic<_itmplTokenActorType> *_multiDic, + intfTokenStats<_itmplTokenActorType> *_tokenStats, + intfTranslatedPhrases<_itmplTokenActorType> *_translatedPhrases, + intfTranslationLogs<_itmplTokenActorType> *_translationLogs ) : CorrectionRules (_correctionRules), DigestedTranslationLogs (_digestedTranslationLogs), diff --git a/ModuleHelpers/MT/Classes/clsDerivedHelperSubmodules.h b/ModuleHelpers/MT/Classes/clsDerivedHelperSubmodules.h index 984f35b3..b0b6e42e 100644 --- a/ModuleHelpers/MT/Classes/clsDerivedHelperSubmodules.h +++ b/ModuleHelpers/MT/Classes/clsDerivedHelperSubmodules.h @@ -30,26 +30,26 @@ namespace Targoman::API::ModuleHelpers::MT::Classes { using namespace Interfaces; -template +template class clsDerivedHelperSubmodules { public: clsDerivedHelperSubmodules( - intfCorrectionRules<_tokenActorType> *_correctionRules, - intfDigestedTranslationLogs<_tokenActorType> *_digestedTranslationLogs, - intfMultiDic<_tokenActorType> *_multiDic, - intfTokenStats<_tokenActorType> *_tokenStats, - intfTranslatedPhrases<_tokenActorType> *_translatedPhrases, - intfTranslationLogs<_tokenActorType> *_translationLogs + intfCorrectionRules<_itmplTokenActorType> *_correctionRules, + intfDigestedTranslationLogs<_itmplTokenActorType> *_digestedTranslationLogs, + intfMultiDic<_itmplTokenActorType> *_multiDic, + intfTokenStats<_itmplTokenActorType> *_tokenStats, + intfTranslatedPhrases<_itmplTokenActorType> *_translatedPhrases, + intfTranslationLogs<_itmplTokenActorType> *_translationLogs ); public: - QScopedPointer> CorrectionRules; - QScopedPointer> DigestedTranslationLogs; - QScopedPointer> MultiDic; - QScopedPointer> TokenStats; - QScopedPointer> TranslatedPhrases; - QScopedPointer> TranslationLogs; + QScopedPointer> CorrectionRules; + QScopedPointer> DigestedTranslationLogs; + QScopedPointer> MultiDic; + QScopedPointer> TokenStats; + QScopedPointer> TranslatedPhrases; + QScopedPointer> TranslationLogs; }; } //namespace Targoman::API::ModuleHelpers::MT::Classes diff --git a/ModuleHelpers/MT/Interfaces/intfMTHelpers.cpp b/ModuleHelpers/MT/Interfaces/intfMTHelpers.cpp index f8268c59..fb1b327d 100644 --- a/ModuleHelpers/MT/Interfaces/intfMTHelpers.cpp +++ b/ModuleHelpers/MT/Interfaces/intfMTHelpers.cpp @@ -27,8 +27,8 @@ TAPI_REGISTER_TARGOMAN_ENUM(Targoman::API::ModuleHelpers::MT, enuCorrectionRuleT TAPI_REGISTER_TARGOMAN_ENUM(Targoman::API::ModuleHelpers::MT, enuMultiDicStatus); #define TAPI_HELPERORM_SUBMODULE_IMPLEMENT(_className, _tblName) \ - template \ - _className<_tokenActorType>::_className( \ + template \ + _className<_itmplTokenActorType>::_className( \ const QString& _schema, \ const QList& _exclusiveCols, \ const QList& _exclusiveRelations, \ @@ -41,7 +41,7 @@ TAPI_REGISTER_TARGOMAN_ENUM(Targoman::API::ModuleHelpers::MT, enuMultiDicStatus) _tblName::Private::Relations(_schema) + _exclusiveRelations, \ _tblName::Private::Indexes + _exclusiveIndexes \ ), \ - intfHelperORMBase<_tokenActorType>() + intfHelperORMBase<_itmplTokenActorType>() namespace Targoman::API::ModuleHelpers::MT::Interfaces { diff --git a/ModuleHelpers/MT/Interfaces/intfMTHelpers.h b/ModuleHelpers/MT/Interfaces/intfMTHelpers.h index 3f5406f3..608bede2 100644 --- a/ModuleHelpers/MT/Interfaces/intfMTHelpers.h +++ b/ModuleHelpers/MT/Interfaces/intfMTHelpers.h @@ -413,30 +413,30 @@ namespace tblTranslationLogsBase { #pragma GCC diagnostic pop /******************************************************/ -template +template class intfHelperORMBase { public: - typedef typename std::conditional<_tokenActorType == TAPI::enuTokenActorType::USER, + typedef typename std::conditional<_itmplTokenActorType == TAPI::enuTokenActorType::USER, APICALLBOOM_TYPE_JWT_USER_DECL, APICALLBOOM_TYPE_JWT_API_DECL>::type MT_JWT_TYPE_DECL; - typedef Q_DECL_UNUSED typename std::conditional<_tokenActorType == TAPI::enuTokenActorType::USER, + typedef Q_DECL_UNUSED typename std::conditional<_itmplTokenActorType == TAPI::enuTokenActorType::USER, APICALLBOOM_TYPE_JWT_USER_DECL, APICALLBOOM_TYPE_JWT_API_DECL>::type MT_JWT_TYPE_IMPL; public: - TAPI::enuTokenActorType::Type tokenActorType() { return _tokenActorType; } - bool IsTokenBase() { return _tokenActorType == TAPI::enuTokenActorType::API; } + TAPI::enuTokenActorType::Type tokenActorType() { return _itmplTokenActorType; } + bool IsTokenBase() { return _itmplTokenActorType == TAPI::enuTokenActorType::API; } }; /******************************************************/ /* intf classes ***************************************/ /******************************************************/ -template -class intfCorrectionRules : public intfSQLBasedModule, public intfHelperORMBase<_tokenActorType> +template +class intfCorrectionRules : public intfSQLBasedModule, public intfHelperORMBase<_itmplTokenActorType> { // Q_OBJECT @@ -448,8 +448,8 @@ class intfCorrectionRules : public intfSQLBasedModule, public intfHelperORMBase< }; /******************************************************/ -template -class intfDigestedTranslationLogs : public intfSQLBasedModule, public intfHelperORMBase<_tokenActorType> +template +class intfDigestedTranslationLogs : public intfSQLBasedModule, public intfHelperORMBase<_itmplTokenActorType> { // Q_OBJECT @@ -461,8 +461,8 @@ class intfDigestedTranslationLogs : public intfSQLBasedModule, public intfHelper }; /******************************************************/ -template -class intfMultiDic : public intfSQLBasedModule, public intfHelperORMBase<_tokenActorType> +template +class intfMultiDic : public intfSQLBasedModule, public intfHelperORMBase<_itmplTokenActorType> { // Q_OBJECT @@ -474,8 +474,8 @@ class intfMultiDic : public intfSQLBasedModule, public intfHelperORMBase<_tokenA }; /******************************************************/ -template -class intfTokenStats : public intfSQLBasedModule, public intfHelperORMBase<_tokenActorType> +template +class intfTokenStats : public intfSQLBasedModule, public intfHelperORMBase<_itmplTokenActorType> { // Q_OBJECT @@ -487,8 +487,8 @@ class intfTokenStats : public intfSQLBasedModule, public intfHelperORMBase<_toke }; /******************************************************/ -template -class intfTranslatedPhrases : public intfSQLBasedModule, public intfHelperORMBase<_tokenActorType> +template +class intfTranslatedPhrases : public intfSQLBasedModule, public intfHelperORMBase<_itmplTokenActorType> { // Q_OBJECT @@ -500,8 +500,8 @@ class intfTranslatedPhrases : public intfSQLBasedModule, public intfHelperORMBas }; /******************************************************/ -template -class intfTranslationLogs : public intfSQLBasedModule, public intfHelperORMBase<_tokenActorType> +template +class intfTranslationLogs : public intfSQLBasedModule, public intfHelperORMBase<_itmplTokenActorType> { // Q_OBJECT diff --git a/ModuleHelpers/MT/MTHelper.cpp b/ModuleHelpers/MT/MTHelper.cpp index 96d03a66..c45caa0a 100644 --- a/ModuleHelpers/MT/MTHelper.cpp +++ b/ModuleHelpers/MT/MTHelper.cpp @@ -152,11 +152,11 @@ void MTHelper::registerEngines() { } } -template +template QVariantMap MTHelper::doTranslation( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, // const QJsonObject& _privInfo, - clsDerivedHelperSubmodules<_tokenActorType> &DerivedHelperSubmodules, + clsDerivedHelperSubmodules<_itmplTokenActorType> &DerivedHelperSubmodules, QString _text, const TranslationDir_t& _dir, const QString& _engine, @@ -167,8 +167,7 @@ QVariantMap MTHelper::doTranslation( int& _translationTime ) { APICALLBOOM_PARAM.createScopeTiming("translate"); -throw exTargomanBase("not finished yet"); -/* + auto FnFindClassAndEngine = [this]( QString _text, const TranslationDir_t &_dir, @@ -198,8 +197,26 @@ throw exTargomanBase("not finished yet"); return nullptr; }; - //1: find _dir.first class end engine + auto FnGetTranslateResultText = [](const QVariantMap &_translateResult) -> QString { + QVariantMap ResultAsMap = _translateResult[RESULTItems::TRANSLATION].toMap(); + + if (ResultAsMap.contains(RESULTItems::SIMPLE)) + return ResultAsMap[RESULTItems::SIMPLE].toString(); + + if (ResultAsMap.contains(RESULTItems::TRANSLATIONItems::BASE)) { + QStringList ResultList; + foreach (auto OneLine, ResultAsMap[RESULTItems::TRANSLATIONItems::BASE].toList()) + ResultList.append(OneLine.toString()); + + return ResultList.join('\n'); + } + + throw exHTTPInternalServerError("Unable to find pre translate result"); + }; + QString Class; + + //1: find _dir.first class end engine clsEngine* TranslationEngine = FnFindClassAndEngine( _text, _dir, @@ -209,20 +226,22 @@ throw exTargomanBase("not finished yet"); ); if (TranslationEngine != nullptr) { - return this->internalDoTranslation( - APICALLBOOM_PARAM, - DerivedHelperSubmodules, - _text, - _dir, - _engine, - _useSpecialClass, - Class, - TranslationEngine, - _detailed, - _detokenize, - _preprocessTime, - _translationTime - ); + QVariantMap TranslateResult = this->internalDoTranslation( + APICALLBOOM_PARAM, + DerivedHelperSubmodules, + _text, + _dir, + _engine, + _useSpecialClass, + Class, + TranslationEngine, + _detailed, + _detokenize, + _preprocessTime, + _translationTime + ); + + return TranslateResult; } //need more steps @@ -231,168 +250,62 @@ throw exTargomanBase("not finished yet"); //phase 1 Dir = { _dir.first, "en" }; - TranslationEngine = FnFindClassAndEngine( - TextToTranslate, - Dir, - _engine, - _useSpecialClass, - Class - ); + clsEngine* PreTranslationEngine = FnFindClassAndEngine( + TextToTranslate, + Dir, + _engine, + _useSpecialClass, + Class + ); QVariantMap PreTranslateResult = this->internalDoTranslation( - APICALLBOOM_PARAM, - DerivedHelperSubmodules, - TextToTranslate, - Dir, - _engine, - _useSpecialClass, - Class, - TranslationEngine, - _detailed, - _detokenize, - _preprocessTime, - _translationTime - ); - - QVariantMap TranslationResultAsMap = PreTranslateResult[RESULTItems::TRANSLATION].toMap(); - if (TranslationResultAsMap.contains(RESULTItems::SIMPLE)) - TextToTranslate = TranslationResultAsMap[RESULTItems::SIMPLE].toString(); - else if (TranslationResultAsMap.contains(RESULTItems::SIMPLE)) - TextToTranslate = TranslationResultAsMap[RESULTItems::SIMPLE].toString(); -// else + APICALLBOOM_PARAM, + DerivedHelperSubmodules, + TextToTranslate, + Dir, + _engine, + _useSpecialClass, + Class, + PreTranslationEngine, + _detailed, + _detokenize, + _preprocessTime, + _translationTime + ); + + TextToTranslate = FnGetTranslateResultText(PreTranslateResult); //phase 2 Dir = { "en", _dir.second }; - TranslationEngine = FnFindClassAndEngine( - TextToTranslate, - Dir, - _engine, - _useSpecialClass, - Class - ); - - - - - - - - - - - struct stuTranslateStep { - QString FromLang; - QString ToLang; - QString Class; - clsEngine* Engine; - QString TranslatedText; - }; - QList TranslateSteps; - - if (_dir.first == "en" || _dir.second == "en") { - stuTranslateStep Step; - - Step.FromLang = _dir.first; - Step.ToLang = _dir.second; - Step.Engine = MTHelper::findEngine( - APICALLBOOM_PARAM, - _text, - _dir, - _engine, - _useSpecialClass, - Step.Class - ); - - TranslateSteps.append(Step); - } else { - - } - - - //find class and engine - QString Class; - clsEngine* TranslationEngine = MTHelper::findEngine( - APICALLBOOM_PARAM, - _text, - _dir, - _engine, - _useSpecialClass, - Class - ); - - if (TranslationEngine != nullptr) { - return this->internalDoTranslation( - APICALLBOOM_PARAM, - DerivedHelperSubmodules, - _text, - _dir, - _engine, - _useSpecialClass, - Class, - TranslationEngine, - _detailed, - _detokenize, - _preprocessTime, - _translationTime - ); - } - - - //-- pre - TranslationDir_t PreTranslateDir = { _dir.first, "en" }; - QString PreClass; - clsEngine* PreTranslationEngine = MTHelper::findEngine( - APICALLBOOM_PARAM, - _text, - PreTranslateDir, - _engine, - _useSpecialClass, - PreClass - ); - - //-- post - TranslationDir_t PostTranslateDir = { "en", _dir.second }; - QString PostClass; - clsEngine* PostTranslationEngine = MTHelper::findEngine( - APICALLBOOM_PARAM, - _text, - PostTranslateDir, - _engine, - _useSpecialClass, - PostClass - ); - - // - PreTranslateResult = this->internalDoTranslation( - APICALLBOOM_PARAM, - DerivedHelperSubmodules, - _text, - PreTranslateDir, - _engine, - _useSpecialClass, - PreClass, - PreTranslationEngine, - _detailed, - _detokenize, - _preprocessTime, - _translationTime - ); - - auto PostTranslateResult = this->internalDoTranslation( - APICALLBOOM_PARAM, - DerivedHelperSubmodules, - _text, - PostTranslateDir, - _engine, - _useSpecialClass, - PostClass, - PostTranslationEngine, - _detailed, - _detokenize, - _preprocessTime, - _translationTime - ); -*/ + clsEngine* PostTranslationEngine = FnFindClassAndEngine( + TextToTranslate, + Dir, + _engine, + _useSpecialClass, + Class + ); + + QVariantMap PostTranslateResult = this->internalDoTranslation( + APICALLBOOM_PARAM, + DerivedHelperSubmodules, + TextToTranslate, + Dir, + _engine, + _useSpecialClass, + Class, + PostTranslationEngine, + _detailed, + _detokenize, + _preprocessTime, + _translationTime + ); + + TextToTranslate = FnGetTranslateResultText(PostTranslateResult); + + //result + + + return PostTranslateResult; } clsEngine* MTHelper::findEngine( @@ -424,10 +337,10 @@ clsEngine* MTHelper::findEngine( return nullptr; } -template +template QVariantMap MTHelper::internalDoTranslation( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, - clsDerivedHelperSubmodules<_tokenActorType> &DerivedHelperSubmodules, + clsDerivedHelperSubmodules<_itmplTokenActorType> &DerivedHelperSubmodules, QString _text, const TranslationDir_t& _dir, const QString& _engine, @@ -530,10 +443,10 @@ QString MTHelper::detectClass(const QString& _engine, const QString& _text, cons return FormalityChecker::instance().check(_lang, _text); } -template +template QString MTHelper::preprocessText( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, - clsDerivedHelperSubmodules<_tokenActorType> &DerivedHelperSubmodules, + clsDerivedHelperSubmodules<_itmplTokenActorType> &DerivedHelperSubmodules, const QString& _text, const QString& _lang ) { diff --git a/ModuleHelpers/MT/MTHelper.h b/ModuleHelpers/MT/MTHelper.h index 5387520b..f30a9cc0 100644 --- a/ModuleHelpers/MT/MTHelper.h +++ b/ModuleHelpers/MT/MTHelper.h @@ -156,10 +156,10 @@ class MTHelper : public intfModuleHelper return this->RegisteredEngines.contains(stuEngineSpecs::makeFullName(_engine, _dir.first, _dir.second)); } - template + template QVariantMap doTranslation( INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, - clsDerivedHelperSubmodules<_tokenActorType> &DerivedHelperSubmodules, + clsDerivedHelperSubmodules<_itmplTokenActorType> &DerivedHelperSubmodules, QString _text, const TranslationDir_t& _dir, const QString& _engine, @@ -180,10 +180,10 @@ class MTHelper : public intfModuleHelper /*OUT*/ QString &_class ); - template + template QVariantMap internalDoTranslation( INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, - clsDerivedHelperSubmodules<_tokenActorType> &DerivedHelperSubmodules, + clsDerivedHelperSubmodules<_itmplTokenActorType> &DerivedHelperSubmodules, QString _text, const TranslationDir_t& _dir, const QString& _engine, @@ -201,10 +201,10 @@ class MTHelper : public intfModuleHelper QString detokenize(const QString& _text, const QString& _lang); QString detectClass(const QString& _engine, const QString& _text, const QString& _lang); - template + template QString preprocessText( INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, - clsDerivedHelperSubmodules<_tokenActorType> &DerivedHelperSubmodules, + clsDerivedHelperSubmodules<_itmplTokenActorType> &DerivedHelperSubmodules, const QString& _text, const QString& _lang ); diff --git a/Modules/MT/functionalTest/testMT.hpp b/Modules/MT/functionalTest/testMT.hpp index 9a15d95e..8237e237 100644 --- a/Modules/MT/functionalTest/testMT.hpp +++ b/Modules/MT/functionalTest/testMT.hpp @@ -520,6 +520,25 @@ private slots: } } + void translate_fa2ar_1() { + QT_TRY { + QVariant Result = this->callAPI( + this->TokenJWT, + RESTClientHelper::enuHTTPMethod::POST, + "MT/translate", + {}, + { + { "text", "این یک متن نمونه برای آزمایش است." }, + { "dir", "fa2ar" }, + }); + + QVERIFY(Result.isValid()); + + } QT_CATCH (const std::exception &exp) { + QTest::qFail(exp.what(), __FILE__, __LINE__); + } + } + }; #endif // TEST_MT_HPP diff --git a/Modules/TargomanMT/moduleSrc/TargomanMT.cpp b/Modules/TargomanMT/moduleSrc/TargomanMT.cpp index a3c5f5e6..a0a89324 100644 --- a/Modules/TargomanMT/moduleSrc/TargomanMT.cpp +++ b/Modules/TargomanMT/moduleSrc/TargomanMT.cpp @@ -240,7 +240,7 @@ QVariantMap TargomanMT::getCustomUserAssetFieldsForQuery( |** API Methods *************************************************| \****************************************************************/ QVariantMap IMPL_REST_GET_OR_POST(TargomanMT, Translate, ( - APICALLBOOM_TYPE_JWT_USER_OR_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_IMPL &APICALLBOOM_PARAM, QString _text, QString _dir, bool _detailed, diff --git a/Modules/TargomanMT/moduleSrc/TargomanMT.h b/Modules/TargomanMT/moduleSrc/TargomanMT.h index 81e042ef..591af5d5 100644 --- a/Modules/TargomanMT/moduleSrc/TargomanMT.h +++ b/Modules/TargomanMT/moduleSrc/TargomanMT.h @@ -96,7 +96,7 @@ private slots: QVariantMap REST_GET_OR_POST( Translate, ( - APICALLBOOM_TYPE_JWT_USER_OR_ANONYMOUSE_DECL &APICALLBOOM_PARAM, + APICALLBOOM_TYPE_JWT_ANONYMOUSE_OR_USER_DECL &APICALLBOOM_PARAM, QString _text, QString _dir, bool _detailed = false, From a4433d1e2c482aaec60551f40f1fe5eb1910da41 Mon Sep 17 00:00:00 2001 From: kambizzandi Date: Mon, 3 Oct 2022 11:45:20 +0330 Subject: [PATCH 2/2] make some changes in jwt type for accounting --- App/Server/clsAPIObject.h | 4 +- Interfaces/AAA/Accounting_Interfaces.cpp | 420 +++++++++++------- Interfaces/AAA/Accounting_Interfaces.h | 230 +++++++--- Interfaces/AAA/intfAccountingBasedModule.cpp | 101 +++-- Interfaces/AAA/intfAccountingBasedModule.h | 75 +++- Interfaces/API/intfPureModule.h | 17 +- Interfaces/Server/APICallBoom.h | 4 +- .../MT/Interfaces/intfMTAccounting.cpp | 77 +++- .../MT/Interfaces/intfMTAccounting.h | 47 +- ModuleHelpers/MT/Interfaces/intfMTHelpers.h | 6 +- Modules/Account/moduleSrc/ORM/APITokens.cpp | 6 +- Modules/Advert/moduleSrc/Advert.cpp | 2 +- Modules/Advert/moduleSrc/Advert.h | 2 +- Modules/Advert/moduleSrc/ORM/Accounting.cpp | 11 - Modules/Advert/moduleSrc/ORM/Accounting.h | 9 +- Modules/MT/moduleSrc/MT.cpp | 2 +- Modules/MT/moduleSrc/MT.h | 2 +- Modules/MT/moduleSrc/ORM/Accounting.h | 7 +- Modules/TargomanMT/moduleSrc/ORM/Accounting.h | 7 +- Modules/TargomanMT/moduleSrc/TargomanMT.cpp | 2 +- Modules/TargomanMT/moduleSrc/TargomanMT.h | 2 +- 21 files changed, 713 insertions(+), 320 deletions(-) diff --git a/App/Server/clsAPIObject.h b/App/Server/clsAPIObject.h index fa1983a9..b9c56aab 100644 --- a/App/Server/clsAPIObject.h +++ b/App/Server/clsAPIObject.h @@ -92,8 +92,8 @@ class clsAPIObject : public intfAPIObject, public QObject ); } inline bool canProvideJWT() { - return (this->tokenAllowANONYMOUSE() - && (this->tokenAllowUSER() || this->tokenAllowAPI()) + return (/*this->tokenAllowANONYMOUSE() + &&*/ (this->tokenAllowUSER() || this->tokenAllowAPI()) ); } inline bool noJWTNeeded() { diff --git a/Interfaces/AAA/Accounting_Interfaces.cpp b/Interfaces/AAA/Accounting_Interfaces.cpp index beec8a2a..5b1b6386 100644 --- a/Interfaces/AAA/Accounting_Interfaces.cpp +++ b/Interfaces/AAA/Accounting_Interfaces.cpp @@ -100,7 +100,6 @@ namespace Targoman::API::AAA { QMap intfAccountUnitsI18N::MyInstance; intfAccountUnitsI18N::intfAccountUnitsI18N( - // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -113,14 +112,15 @@ intfAccountUnitsI18N::intfAccountUnitsI18N( tblAccountUnitsI18NBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountUnitsI18NBase::Private::Indexes + _exclusiveIndexes ) - // intfAccountORMBase(_isTokenBase) + // , intfAccountORMBase<_itmplIsTokenBase>() { intfAccountUnitsI18N::MyInstance[_schema] = this; } +/******************************************************************/ +/******************************************************************/ /******************************************************************/ intfAccountUnits::intfAccountUnits( - // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -133,7 +133,7 @@ intfAccountUnits::intfAccountUnits( tblAccountUnitsBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountUnitsBase::Private::Indexes + _exclusiveIndexes ) - // intfAccountORMBase(_isTokenBase) + // , intfAccountORMBase<_itmplIsTokenBase>() { ; } ORMSelectQuery intfAccountUnits::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const QString &_alias, Q_DECL_UNUSED bool _translate, Q_DECL_UNUSED bool _isRoot) { @@ -215,7 +215,6 @@ bool IMPL_ORMDELETE_USER(intfAccountUnits) { QMap intfAccountProductsI18N::MyInstance; intfAccountProductsI18N::intfAccountProductsI18N( - // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -228,11 +227,13 @@ intfAccountProductsI18N::intfAccountProductsI18N( tblAccountProductsI18NBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountProductsI18NBase::Private::Indexes + _exclusiveIndexes ) - // intfAccountORMBase(_isTokenBase) + // , intfAccountORMBase<_itmplIsTokenBase>() { intfAccountProductsI18N::MyInstance[_schema] = this; } +/******************************************************************/ +/******************************************************************/ /******************************************************************/ intfAccountProducts::intfAccountProducts( // bool _isTokenBase, @@ -248,7 +249,7 @@ intfAccountProducts::intfAccountProducts( tblAccountProductsBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountProductsBase::Private::Indexes + _exclusiveIndexes ) - // intfAccountORMBase(_isTokenBase) + // , intfAccountORMBase<_itmplIsTokenBase>() { ; } ORMSelectQuery intfAccountProducts::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const QString &_alias, Q_DECL_UNUSED bool _translate, Q_DECL_UNUSED bool _isRoot) { @@ -352,7 +353,6 @@ bool IMPL_ORMDELETE_USER(intfAccountProducts) { QMap intfAccountSaleablesI18N::MyInstance; intfAccountSaleablesI18N::intfAccountSaleablesI18N( - // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -365,7 +365,6 @@ intfAccountSaleablesI18N::intfAccountSaleablesI18N( tblAccountSaleablesI18NBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountSaleablesI18NBase::Private::Indexes + _exclusiveIndexes ) - // intfAccountORMBase(_isTokenBase) { intfAccountSaleablesI18N::MyInstance[_schema] = this; } @@ -375,7 +374,6 @@ intfAccountSaleablesI18N::intfAccountSaleablesI18N( QMap intfAccountSaleables::MyInstance; intfAccountSaleables::intfAccountSaleables( - // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -388,7 +386,6 @@ intfAccountSaleables::intfAccountSaleables( tblAccountSaleablesBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountSaleablesBase::Private::Indexes + _exclusiveIndexes ) - // intfAccountORMBase(_isTokenBase) { intfAccountSaleables::MyInstance[_schema] = this; } @@ -516,7 +513,6 @@ bool IMPL_ORMDELETE_USER(intfAccountSaleables) { QMap intfAccountSaleablesFiles::MyInstance; intfAccountSaleablesFiles::intfAccountSaleablesFiles( - // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -529,7 +525,6 @@ intfAccountSaleablesFiles::intfAccountSaleablesFiles( tblAccountSaleablesFilesBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountSaleablesFilesBase::Private::Indexes + _exclusiveIndexes ) - // intfAccountORMBase(_isTokenBase) { intfAccountSaleablesFiles::MyInstance[_schema] = this; } @@ -552,73 +547,156 @@ bool IMPL_ORMUPDATE_USER(intfAccountSaleablesFiles) { } bool IMPL_ORMDELETE_USER(intfAccountSaleablesFiles) { - Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_DELETE, this->moduleBaseName())); + Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_DELETE, this->moduleBaseName())); - return this->DeleteByPks(DELETE_METHOD_ARGS_CALL_VALUES); + return this->DeleteByPks(DELETE_METHOD_ARGS_CALL_VALUES); } /******************************************************************/ /******************************************************************/ /******************************************************************/ -intfAccountUserAssets::intfAccountUserAssets( - // bool _isTokenBase, +baseintfAccountUserAssets::baseintfAccountUserAssets( const QString& _schema, - const QList& _exclusiveCols, - const QList& _exclusiveRelations, - const QList& _exclusiveIndexes + const QList& _cols, + const QList& _relations, + const QList& _indexes ) : intfSQLBasedModule( _schema, tblAccountUserAssetsBase::Name, - tblAccountUserAssetsBase::Private::ORMFields + _exclusiveCols, - tblAccountUserAssetsBase::Private::Relations(_schema) + _exclusiveRelations, - tblAccountUserAssetsBase::Private::Indexes + _exclusiveIndexes + _cols, + _relations, + _indexes ) - // intfAccountORMBase(_isTokenBase) { ; } -/* -SELECT - tmpNeededFiles.* -, tmpProvidedFiles.* -, uas.* +bool IMPL_REST_UPDATE(baseintfAccountUserAssets, setAsPrefered, ( + APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM, + TAPI::PKsByPath_t _pksByPath +)) { + bool Ok; + quint64 UserPackageID = _pksByPath.toUInt(&Ok); + if (!Ok || !UserPackageID ) + throw exHTTPBadRequest("Invalid UserPackageID provided"); -FROM tblAccountUserAssets uas + this->callSP(APICALLBOOM_PARAM, + "spUserAsset_SetAsPrefered", { + { "iUserID", APICALLBOOM_PARAM.getActorID() }, + { "iUASID", UserPackageID }, + }); + return false; +} -LEFT JOIN ( -SELECT slf_slbID -, SUM(slfMinCount) AS MandatoryFilesCount -FROM tblAccountSaleablesFiles slf -WHERE slfMinCount > 0 -GROUP BY slf_slbID -) tmpNeededFiles -ON tmpNeededFiles.slf_slbID = uas.uas_slbID +bool IMPL_REST_UPDATE(baseintfAccountUserAssets, disablePackage, ( + APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM, + TAPI::PKsByPath_t _pksByPath +)) { + bool Ok; + quint64 UserPackageID = _pksByPath.toUInt(&Ok); + if (!Ok || !UserPackageID ) + throw exHTTPBadRequest("Invalid UserPackageID provided"); -LEFT JOIN ( -SELECT -uasufl_uasID -, SUM(LEAST(slfMinCount, ProvidedFilesCount)) AS ProvidedMandatoryFilesCount + Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_PATCH, this->moduleBaseName())); + /*return this->update(APICALLBOOM_PARAM.getActorID(), { + {tblAccountUserAssets::Fields::uasID, UserPackageID} + }, { + {tblAccountUserAssets::Fields::uasStatus, TAPI::enuAuditableStatus::Banned}, + });*/ + throw Targoman::Common::exTargomanMustBeImplemented(__FUNCTION__); + return Ok; +} -FROM ( -SELECT -uasufl_uasID -, uasufl_slfID -, slfMinCount -, COUNT(*) AS ProvidedFilesCount -FROM tblAccountUserAssets_files uasufl -INNER JOIN tblAccountSaleablesFiles slf -ON slf.slfID = uasufl.uasufl_slfID -WHERE slfMinCount > 0 -GROUP BY uasufl_uasID -, uasufl_slfID -) t1 +/******************************************************************/ +baseintfAccountUserAssets_USER::baseintfAccountUserAssets_USER( + const QString& _schema, + const QList& _cols, + const QList& _relations, + const QList& _indexes +) : + baseintfAccountUserAssets( + _schema, + _cols, + _relations, + _indexes + ) + // , intfAccountORMBase<_itmplIsTokenBase>() +{ ; } -GROUP BY uasufl_uasID -) tmpProvidedFiles -ON tmpProvidedFiles.uasufl_uasID = uas.uasID -*/ +QVariant IMPL_ORMGET_USER(baseintfAccountUserAssets_USER) { + if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false) + this->setSelfFilters({{ tblAccountUserAssetsBase::Fields::uas_actorID, APICALLBOOM_PARAM.getActorID() }}, _filters); -ORMSelectQuery intfAccountUserAssets::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const QString &_alias, Q_DECL_UNUSED bool _translate, Q_DECL_UNUSED bool _isRoot) { + auto fnTouchQuery = [this, &_cols](ORMSelectQuery &_query) { + if (_cols.isEmpty()) + _query.addCols(this->selectableColumnNames()); + else { + _query.addCSVCols(_cols); + _cols = {}; + } + + _query.innerJoinWith(tblAccountUserAssetsBase::Relation::Saleable) + .addCols(intfAccountSaleables::MyInstance[this->Schema]->selectableColumnNames()) + ; + }; + + return this->Select(GET_METHOD_ARGS_CALL_VALUES, {}, 0, fnTouchQuery); +} + +/******************************************************************/ +baseintfAccountUserAssets_API::baseintfAccountUserAssets_API( + const QString& _schema, + const QList& _cols, + const QList& _relations, + const QList& _indexes +) : + baseintfAccountUserAssets( + _schema, + _cols, + _relations, + _indexes + ) + // , intfAccountORMBase<_itmplIsTokenBase>() +{ ; } + +QVariant IMPL_ORMGET_API(baseintfAccountUserAssets_API) { + if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false) + this->setSelfFilters({{ tblAccountUserAssetsBase::Fields::uas_actorID, APICALLBOOM_PARAM.getActorID() }}, _filters); + + auto fnTouchQuery = [this, &_cols](ORMSelectQuery &_query) { + if (_cols.isEmpty()) + _query.addCols(this->selectableColumnNames()); + else { + _query.addCSVCols(_cols); + _cols = {}; + } + + _query.innerJoinWith(tblAccountUserAssetsBase::Relation::Saleable) + .addCols(intfAccountSaleables::MyInstance[this->Schema]->selectableColumnNames()) + ; + }; + + return this->Select(GET_METHOD_ARGS_CALL_VALUES, {}, 0, fnTouchQuery); +} + +/******************************************************************/ +template +intfAccountUserAssets<_itmplIsTokenBase>::intfAccountUserAssets( + const QString& _schema, + const QList& _exclusiveCols, + const QList& _exclusiveRelations, + const QList& _exclusiveIndexes +) : + std::conditional<_itmplIsTokenBase, baseintfAccountUserAssets_API, baseintfAccountUserAssets_USER>::type( + _schema, + tblAccountUserAssetsBase::Private::ORMFields + _exclusiveCols, + tblAccountUserAssetsBase::Private::Relations(_schema) + _exclusiveRelations, + tblAccountUserAssetsBase::Private::Indexes + _exclusiveIndexes + ) + // , intfAccountORMBase<_itmplIsTokenBase>() +{ ; } + +template +ORMSelectQuery intfAccountUserAssets<_itmplIsTokenBase>::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const QString &_alias, Q_DECL_UNUSED bool _translate, Q_DECL_UNUSED bool _isRoot) { ORMSelectQuery Query = intfSQLBasedModule::makeSelectQuery(APICALLBOOM_PARAM, _alias, _translate); @@ -698,81 +776,54 @@ ORMSelectQuery intfAccountUserAssets::makeSelectQuery(INTFAPICALLBOOM_IMPL &APIC return Query; } -QVariant IMPL_ORMGET_USER_OR_API(intfAccountUserAssets) { - - - - - if (APICALLBOOM_PARAM.jwtActorType() == TAPI::enuTokenActorType::USER) { - - } else { //API - - } - - - - - if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false) - this->setSelfFilters({{ tblAccountUserAssetsBase::Fields::uas_actorID, APICALLBOOM_PARAM.getActorID() }}, _filters); - - auto fnTouchQuery = [this, &_cols](ORMSelectQuery &_query) { - if (_cols.isEmpty()) - _query.addCols(this->selectableColumnNames()); - else { - _query.addCSVCols(_cols); - _cols = {}; - } - - _query.innerJoinWith(tblAccountUserAssetsBase::Relation::Saleable) - .addCols(intfAccountSaleables::MyInstance[this->Schema]->selectableColumnNames()) - ; - }; +/* +SELECT + tmpNeededFiles.* +, tmpProvidedFiles.* +, uas.* - return this->Select(GET_METHOD_ARGS_CALL_VALUES, {}, 0, fnTouchQuery); -} +FROM tblAccountUserAssets uas -bool IMPL_REST_UPDATE(intfAccountUserAssets, setAsPrefered, ( - APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM, - TAPI::PKsByPath_t _pksByPath -)) { - bool Ok; - quint64 UserPackageID = _pksByPath.toUInt(&Ok); - if (!Ok || !UserPackageID ) - throw exHTTPBadRequest("Invalid UserPackageID provided"); +LEFT JOIN ( +SELECT slf_slbID +, SUM(slfMinCount) AS MandatoryFilesCount +FROM tblAccountSaleablesFiles slf +WHERE slfMinCount > 0 +GROUP BY slf_slbID +) tmpNeededFiles +ON tmpNeededFiles.slf_slbID = uas.uas_slbID - this->callSP(APICALLBOOM_PARAM, - "spUserAsset_SetAsPrefered", { - { "iUserID", APICALLBOOM_PARAM.getActorID() }, - { "iUASID", UserPackageID }, - }); - return false; -} +LEFT JOIN ( +SELECT +uasufl_uasID +, SUM(LEAST(slfMinCount, ProvidedFilesCount)) AS ProvidedMandatoryFilesCount -bool IMPL_REST_UPDATE(intfAccountUserAssets, disablePackage, ( - APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM, - TAPI::PKsByPath_t _pksByPath -)) { - bool Ok; - quint64 UserPackageID = _pksByPath.toUInt(&Ok); - if (!Ok || !UserPackageID ) - throw exHTTPBadRequest("Invalid UserPackageID provided"); +FROM ( +SELECT +uasufl_uasID +, uasufl_slfID +, slfMinCount +, COUNT(*) AS ProvidedFilesCount +FROM tblAccountUserAssets_files uasufl +INNER JOIN tblAccountSaleablesFiles slf +ON slf.slfID = uasufl.uasufl_slfID +WHERE slfMinCount > 0 +GROUP BY uasufl_uasID +, uasufl_slfID +) t1 - Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_PATCH, this->moduleBaseName())); - /*return this->update(APICALLBOOM_PARAM.getActorID(), { - {tblAccountUserAssets::Fields::uasID, UserPackageID} - }, { - {tblAccountUserAssets::Fields::uasStatus, TAPI::enuAuditableStatus::Banned}, - });*/ - throw Targoman::Common::exTargomanMustBeImplemented(__FUNCTION__); - return Ok; -} +GROUP BY uasufl_uasID +) tmpProvidedFiles +ON tmpProvidedFiles.uasufl_uasID = uas.uasID +*/ +/******************************************************************/ +/******************************************************************/ /******************************************************************/ //key: schema QMap intfAccountUserAssetsFiles::MyInstance; intfAccountUserAssetsFiles::intfAccountUserAssetsFiles( - // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -785,7 +836,6 @@ intfAccountUserAssetsFiles::intfAccountUserAssetsFiles( tblAccountUserAssetsFilesBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountUserAssetsFilesBase::Private::Indexes + _exclusiveIndexes ) - // intfAccountORMBase(_isTokenBase) { intfAccountUserAssetsFiles::MyInstance[_schema] = this; } @@ -799,35 +849,89 @@ QVariant IMPL_ORMGET_USER(intfAccountUserAssetsFiles) { /******************************************************************/ /******************************************************************/ /******************************************************************/ -intfAccountAssetUsage::intfAccountAssetUsage( - // bool _isTokenBase, +baseintfAccountAssetUsage::baseintfAccountAssetUsage( const QString& _schema, - const QList& _exclusiveCols, - const QList& _exclusiveRelations, - const QList& _exclusiveIndexes + const QList& _cols, + const QList& _relations, + const QList& _indexes ) : intfSQLBasedModule( _schema, tblAccountAssetUsageBase::Name, - tblAccountAssetUsageBase::Private::ORMFields + _exclusiveCols, - tblAccountAssetUsageBase::Private::Relations(_schema) + _exclusiveRelations, - tblAccountAssetUsageBase::Private::Indexes + _exclusiveIndexes + _cols, + _relations, + _indexes ) - // intfAccountORMBase(_isTokenBase) + // , intfAccountORMBase<_itmplIsTokenBase>() { ; } -QVariant IMPL_ORMGET_USER(intfAccountAssetUsage) { +/******************************************************************/ +baseintfAccountAssetUsage_USER::baseintfAccountAssetUsage_USER( + const QString& _schema, + const QList& _cols, + const QList& _relations, + const QList& _indexes +) : + baseintfAccountAssetUsage( + _schema, + _cols, + _relations, + _indexes + ) + // , intfAccountORMBase<_itmplIsTokenBase>() +{ ; } + +QVariant IMPL_ORMGET_USER(baseintfAccountAssetUsage_USER) { if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false) this->setSelfFilters({{tblAccountUserAssetsBase::Fields::uas_actorID, APICALLBOOM_PARAM.getActorID()}}, _filters); return this->Select(GET_METHOD_ARGS_CALL_VALUES); } +/******************************************************************/ +baseintfAccountAssetUsage_API::baseintfAccountAssetUsage_API( + const QString& _schema, + const QList& _cols, + const QList& _relations, + const QList& _indexes +) : + baseintfAccountAssetUsage( + _schema, + _cols, + _relations, + _indexes + ) + // , intfAccountORMBase<_itmplIsTokenBase>() +{ ; } + +QVariant IMPL_ORMGET_API(baseintfAccountAssetUsage_API) { + if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false) + this->setSelfFilters({{tblAccountUserAssetsBase::Fields::uas_actorID, APICALLBOOM_PARAM.getActorID()}}, _filters); + + return this->Select(GET_METHOD_ARGS_CALL_VALUES); +} + +/******************************************************************/ +template +intfAccountAssetUsage<_itmplIsTokenBase>::intfAccountAssetUsage( + const QString& _schema, + const QList& _exclusiveCols, + const QList& _exclusiveRelations, + const QList& _exclusiveIndexes +) : + std::conditional<_itmplIsTokenBase, baseintfAccountAssetUsage_API, baseintfAccountAssetUsage_USER>::type( + _schema, + tblAccountAssetUsageBase::Private::ORMFields + _exclusiveCols, + tblAccountAssetUsageBase::Private::Relations(_schema) + _exclusiveRelations, + tblAccountAssetUsageBase::Private::Indexes + _exclusiveIndexes + ) + // , intfAccountORMBase<_itmplIsTokenBase>() +{ ; } + /******************************************************************/ /******************************************************************/ /******************************************************************/ intfAccountCoupons::intfAccountCoupons( - // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -840,17 +944,12 @@ intfAccountCoupons::intfAccountCoupons( tblAccountCouponsBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountCouponsBase::Private::Indexes + _exclusiveIndexes ) - // intfAccountORMBase(_isTokenBase) { ; } QVariant IMPL_ORMGET_USER(intfAccountCoupons) { - Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())); - - return this->Select(GET_METHOD_ARGS_CALL_VALUES); - -// return query.one(); + Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())); -// return this->selectFromTable({}, {}, GET_METHOD_CALL_ARGS_APICALL); + return this->Select(GET_METHOD_ARGS_CALL_VALUES); } quint32 IMPL_ORMCREATE_USER(intfAccountCoupons) { @@ -875,7 +974,6 @@ bool IMPL_ORMDELETE_USER(intfAccountCoupons) { /******************************************************************/ /******************************************************************/ intfAccountPrizes::intfAccountPrizes( - // bool _isTokenBase, const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, @@ -888,17 +986,12 @@ intfAccountPrizes::intfAccountPrizes( tblAccountPrizesBase::Private::Relations(_schema) + _exclusiveRelations, tblAccountPrizesBase::Private::Indexes + _exclusiveIndexes ) - // intfAccountORMBase(_isTokenBase) { ; } QVariant IMPL_ORMGET_USER(intfAccountPrizes) { Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())); return this->Select(GET_METHOD_ARGS_CALL_VALUES); - -// return query.one(); - - // return this->selectFromTable({}, {}, GET_METHOD_CALL_ARGS_APICALL); } quint32 IMPL_ORMCREATE_USER(intfAccountPrizes) { @@ -1037,4 +1130,33 @@ stuAssetItemReq_t& stuAssetItemReq_t::fromVariant(const QVariant& _value, const return *this; }*/ +/******************************************************/ +/******************************************************/ +/******************************************************/ +//template class intfAccountUnits; +//template class intfAccountUnitsI18N; +//template class intfAccountProducts; +//template class intfAccountProductsI18N; +//template class intfAccountSaleables; +//template class intfAccountSaleablesI18N; +//template class intfAccountSaleablesFiles; +template class intfAccountUserAssets; +//template class intfAccountUserAssetsFiles; +template class intfAccountAssetUsage; +//template class intfAccountCoupons; +//template class intfAccountPrizes; + +//template class intfAccountUnits; +//template class intfAccountUnitsI18N; +//template class intfAccountProducts; +//template class intfAccountProductsI18N; +//template class intfAccountSaleables; +//template class intfAccountSaleablesI18N; +//template class intfAccountSaleablesFiles; +template class intfAccountUserAssets; +//template class intfAccountUserAssetsFiles; +template class intfAccountAssetUsage; +//template class intfAccountCoupons; +//template class intfAccountPrizes; + } //namespace Targoman::API::AAA diff --git a/Interfaces/AAA/Accounting_Interfaces.h b/Interfaces/AAA/Accounting_Interfaces.h index 5bb04a91..2eb88a5e 100644 --- a/Interfaces/AAA/Accounting_Interfaces.h +++ b/Interfaces/AAA/Accounting_Interfaces.h @@ -97,34 +97,46 @@ AccountPrizes | ANONY | USER | API | /******************************************************/ -template -class intfAccountORMBase -{ -public: - typedef typename std::conditional<_itmplIsTokenBase, - APICALLBOOM_TYPE_JWT_API_DECL, - APICALLBOOM_TYPE_JWT_USER_DECL>::type - ACCORM_JWT_TYPE_DECL; +//template +//class intfAccountORMBase +//{ +//public: +// typedef typename std::conditional<_itmplIsTokenBase, +// APICALLBOOM_TYPE_JWT_API_DECL, +// APICALLBOOM_TYPE_JWT_USER_DECL>::type +// APICALLBOOM_TYPE_JWT_TOKENBASE_DECL; - typedef Q_DECL_UNUSED typename std::conditional<_itmplIsTokenBase, - APICALLBOOM_TYPE_JWT_API_DECL, - APICALLBOOM_TYPE_JWT_USER_DECL>::type - ACCORM_JWT_TYPE_IMPL; +// typedef Q_DECL_UNUSED typename std::conditional<_itmplIsTokenBase, +// APICALLBOOM_TYPE_JWT_API_DECL, +// APICALLBOOM_TYPE_JWT_USER_DECL>::type +// APICALLBOOM_TYPE_JWT_TOKENBASE_IMPL; -public: - bool IsTokenBase() { return _itmplIsTokenBase; } -}; +//public: +// bool IsTokenBase() { return _itmplIsTokenBase; } +//}; + +#define ACCORM_TOKENBASE_TYPES(_isTokenBase) \ + public: \ + typedef typename std::conditional<_isTokenBase, \ + APICALLBOOM_TYPE_JWT_API_DECL, \ + APICALLBOOM_TYPE_JWT_USER_DECL>::type \ + APICALLBOOM_TYPE_JWT_TOKENBASE_DECL; \ + typedef Q_DECL_UNUSED typename std::conditional<_isTokenBase, \ + APICALLBOOM_TYPE_JWT_API_DECL, \ + APICALLBOOM_TYPE_JWT_USER_DECL>::type \ + APICALLBOOM_TYPE_JWT_TOKENBASE_IMPL; \ + public: \ + bool IsTokenBase() { return _isTokenBase; } /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountUnitsI18N : public intfSQLBasedModule//, public intfAccountORMBase +class intfAccountUnitsI18N : public intfSQLBasedModule { Q_OBJECT public: - intfAccountUnitsI18N(//bool _isTokenBase, - const QString& _schema, + intfAccountUnitsI18N(const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, const QList& _exclusiveIndexes = {}); @@ -136,13 +148,14 @@ class intfAccountUnitsI18N : public intfSQLBasedModule//, public intfAccountORMB }; /******************************************************/ -class intfAccountUnits : public intfSQLBasedModule//, public intfAccountORMBase +/******************************************************/ +/******************************************************/ +class intfAccountUnits : public intfSQLBasedModule { Q_OBJECT public: - intfAccountUnits(//bool _isTokenBase, - const QString& _schema, + intfAccountUnits(const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, const QList& _exclusiveIndexes = {}); @@ -160,13 +173,12 @@ private slots: /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountProductsI18N : public intfSQLBasedModule//, public intfAccountORMBase +class intfAccountProductsI18N : public intfSQLBasedModule { Q_OBJECT public: - intfAccountProductsI18N(//bool _isTokenBase, - const QString& _schema, + intfAccountProductsI18N(const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, const QList& _exclusiveIndexes = {}); @@ -178,13 +190,14 @@ class intfAccountProductsI18N : public intfSQLBasedModule//, public intfAccountO }; /******************************************************/ -class intfAccountProducts : public intfSQLBasedModule//, public intfAccountORMBase +/******************************************************/ +/******************************************************/ +class intfAccountProducts : public intfSQLBasedModule { Q_OBJECT public: - intfAccountProducts(//bool _isTokenBase, - const QString& _schema, + intfAccountProducts(const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, const QList& _exclusiveIndexes = {}); @@ -202,13 +215,12 @@ private slots: /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountSaleablesI18N : public intfSQLBasedModule//, public intfAccountORMBase +class intfAccountSaleablesI18N : public intfSQLBasedModule { Q_OBJECT public: - intfAccountSaleablesI18N(//bool _isTokenBase, - const QString& _schema, + intfAccountSaleablesI18N(const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, const QList& _exclusiveIndexes = {}); @@ -220,13 +232,14 @@ class intfAccountSaleablesI18N : public intfSQLBasedModule//, public intfAccount }; /******************************************************/ -class intfAccountSaleables : public intfSQLBasedModule//, public intfAccountORMBase +/******************************************************/ +/******************************************************/ +class intfAccountSaleables : public intfSQLBasedModule { Q_OBJECT public: - intfAccountSaleables(//bool _isTokenBase, - const QString& _schema, + intfAccountSaleables(const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, const QList& _exclusiveIndexes = {}); @@ -246,13 +259,14 @@ private slots: }; /******************************************************/ -class intfAccountSaleablesFiles : public intfSQLBasedModule//, public intfAccountORMBase +/******************************************************/ +/******************************************************/ +class intfAccountSaleablesFiles : public intfSQLBasedModule { Q_OBJECT public: - intfAccountSaleablesFiles(//bool _isTokenBase, - const QString& _schema, + intfAccountSaleablesFiles(const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, const QList& _exclusiveIndexes = {}); @@ -275,23 +289,20 @@ private slots: /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountUserAssets : public intfSQLBasedModule//, public intfAccountORMBase +class baseintfAccountUserAssets : public intfSQLBasedModule { Q_OBJECT public: - intfAccountUserAssets(//bool _isTokenBase, - const QString& _schema, - const QList& _exclusiveCols = {}, - const QList& _exclusiveRelations = {}, - const QList& _exclusiveIndexes = {}); + baseintfAccountUserAssets(const QString& _schema, + const QList& _cols = {}, + const QList& _relations = {}, + const QList& _indexes = {}); -public: - virtual ORMSelectQuery makeSelectQuery(INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, const QString &_alias = {}, bool _translate = true, bool _isRoot = true); +protected: +// QVariant ORMGET_INTERNAL private slots: - QVariant ORMGET_USER_OR_API("Get User Assets") - bool REST_UPDATE( disablePackage, ( @@ -312,13 +323,63 @@ private slots: }; /******************************************************/ -class intfAccountUserAssetsFiles : public intfSQLBasedModule//, public intfAccountORMBase +class baseintfAccountUserAssets_USER : public baseintfAccountUserAssets { Q_OBJECT + ACCORM_TOKENBASE_TYPES(false) public: - intfAccountUserAssetsFiles(//bool _isTokenBase, - const QString& _schema, + baseintfAccountUserAssets_USER(const QString& _schema, + const QList& _cols = {}, + const QList& _relations = {}, + const QList& _indexes = {}); + +private slots: +// QVariant ORMGET_TOKENBASE("Get User Assets") + QVariant ORMGET_USER("Get User Assets") +}; + +/******************************************************/ +class baseintfAccountUserAssets_API : public baseintfAccountUserAssets +{ + Q_OBJECT + ACCORM_TOKENBASE_TYPES(true) + +public: + baseintfAccountUserAssets_API(const QString& _schema, + const QList& _cols = {}, + const QList& _relations = {}, + const QList& _indexes = {}); + +private slots: +// QVariant ORMGET_TOKENBASE("Get User Assets") + QVariant ORMGET_API("Get User Assets") +}; + +/******************************************************/ +template +class intfAccountUserAssets : + public std::conditional<_itmplIsTokenBase, baseintfAccountUserAssets_API, baseintfAccountUserAssets_USER>::type //intfSQLBasedModule// , public intfAccountORMBase<_itmplIsTokenBase> +{ +public: + intfAccountUserAssets(const QString& _schema, + const QList& _exclusiveCols = {}, + const QList& _exclusiveRelations = {}, + const QList& _exclusiveIndexes = {}); + +public: + virtual ORMSelectQuery makeSelectQuery(INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, const QString &_alias = {}, bool _translate = true, bool _isRoot = true); +}; + +/******************************************************/ +/******************************************************/ +/******************************************************/ +class intfAccountUserAssetsFiles : public intfSQLBasedModule +{ + Q_OBJECT + +public: + intfAccountUserAssetsFiles(const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, const QList& _exclusiveIndexes = {}); @@ -337,31 +398,75 @@ private slots: /******************************************************/ /******************************************************/ /******************************************************/ -//template -class intfAccountAssetUsage : public intfSQLBasedModule//, public intfAccountORMBase<_itmplIsTokenBase> +class baseintfAccountAssetUsage : public intfSQLBasedModule { Q_OBJECT public: - intfAccountAssetUsage(//bool _isTokenBase, - const QString& _schema, - const QList& _exclusiveCols = {}, - const QList& _exclusiveRelations = {}, - const QList& _exclusiveIndexes = {}); + baseintfAccountAssetUsage(const QString& _schema, + const QList& _cols = {}, + const QList& _relations = {}, + const QList& _indexes = {}); + private slots: - QVariant ORMGET_USER("Get user Usage on each Asset") +}; + +/******************************************************/ +class baseintfAccountAssetUsage_USER : public baseintfAccountAssetUsage +{ + Q_OBJECT + ACCORM_TOKENBASE_TYPES(false) + +public: + baseintfAccountAssetUsage_USER(const QString& _schema, + const QList& _cols = {}, + const QList& _relations = {}, + const QList& _indexes = {}); + +private slots: +// QVariant ORMGET_TOKENBASE("Get User Assets") + QVariant ORMGET_USER("Get User Assets") +}; + +/******************************************************/ +class baseintfAccountAssetUsage_API : public baseintfAccountAssetUsage +{ + Q_OBJECT + ACCORM_TOKENBASE_TYPES(true) + +public: + baseintfAccountAssetUsage_API(const QString& _schema, + const QList& _cols = {}, + const QList& _relations = {}, + const QList& _indexes = {}); + +private slots: +// QVariant ORMGET_TOKENBASE("Get User Assets") + QVariant ORMGET_API("Get User Assets") +}; + +/******************************************************/ +template +class intfAccountAssetUsage : public std::conditional<_itmplIsTokenBase, baseintfAccountAssetUsage_API, baseintfAccountAssetUsage_USER>::type //intfSQLBasedModule// , public intfAccountORMBase<_itmplIsTokenBase> +{ +public: + intfAccountAssetUsage(//bool _isTokenBase, + const QString& _schema, + const QList& _exclusiveCols = {}, + const QList& _exclusiveRelations = {}, + const QList& _exclusiveIndexes = {}); + }; /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountCoupons : public intfSQLBasedModule//, public intfAccountORMBase +class intfAccountCoupons : public intfSQLBasedModule { Q_OBJECT public: - intfAccountCoupons(//bool _isTokenBase, - const QString& _schema, + intfAccountCoupons(const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, const QList& _exclusiveIndexes = {}); @@ -376,13 +481,12 @@ private slots: /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountPrizes : public intfSQLBasedModule//, public intfAccountORMBase +class intfAccountPrizes : public intfSQLBasedModule { Q_OBJECT public: - intfAccountPrizes(//bool _isTokenBase, - const QString& _schema, + intfAccountPrizes(const QString& _schema, const QList& _exclusiveCols = {}, const QList& _exclusiveRelations = {}, const QList& _exclusiveIndexes = {}); diff --git a/Interfaces/AAA/intfAccountingBasedModule.cpp b/Interfaces/AAA/intfAccountingBasedModule.cpp index 24593c1e..7f17c30a 100644 --- a/Interfaces/AAA/intfAccountingBasedModule.cpp +++ b/Interfaces/AAA/intfAccountingBasedModule.cpp @@ -42,8 +42,6 @@ using namespace Common; using namespace DBM; using namespace DBManager; -static QMap ServiceRegistry; - Targoman::Common::Configuration::tmplConfigurable Secret( makeConfig("Secret"), "Secret to be used for signing voucher and prevoucher", @@ -101,31 +99,32 @@ clsSimpleCrypt* simpleCryptInstance() return SimpleCryptInstance; } -intfAccountingBasedModule* serviceAccounting(const QString& _serviceName) { +static QMap ServiceRegistry; + +baseintfAccountingBasedModule* serviceAccounting(const QString& _serviceName) { return ServiceRegistry.value(_serviceName); } /***************************************************************************************************\ -|** intfAccountingBasedModule **********************************************************************| +|** baseintfAccountingBasedModule ******************************************************************| \***************************************************************************************************/ -intfAccountingBasedModule::intfAccountingBasedModule( +baseintfAccountingBasedModule::baseintfAccountingBasedModule( const QString &_module, const QString &_schema, - bool _isTokenBase, AssetUsageLimitsCols_t _AssetUsageLimitsCols, intfAccountUnits *_units, intfAccountProducts *_products, intfAccountSaleables *_saleables, intfAccountSaleablesFiles *_saleablesFiles, - intfAccountUserAssets *_userAssets, + baseintfAccountUserAssets *_userAssets, intfAccountUserAssetsFiles *_userAssetsFiles, - intfAccountAssetUsage *_assetUsages, + baseintfAccountAssetUsage *_assetUsages, intfAccountCoupons *_discounts, intfAccountPrizes *_prizes ) : intfSQLBasedModule(_module, _schema), ServiceName(_schema), - IsTokenBase(_isTokenBase), +// IsTokenBase(_isTokenBase), AccountUnits(_units), AccountProducts(_products), AccountSaleables(_saleables), @@ -150,18 +149,16 @@ intfAccountingBasedModule::intfAccountingBasedModule( if (Col.Total.size()) this->AssetUsageLimitsColsName.append(Col.Total); } - - ServiceRegistry.insert(this->ServiceName, this); } /******************************************************************\ |** credit ********************************************************| \******************************************************************/ -stuActiveCredit intfAccountingBasedModule::activeAccountObject(quint64 _usrID) { +stuActiveCredit baseintfAccountingBasedModule::activeAccountObject(quint64 _usrID) { return this->findBestMatchedCredit(_usrID); } -void intfAccountingBasedModule::checkUsageIsAllowed( +void baseintfAccountingBasedModule::checkUsageIsAllowed( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const ServiceUsage_t &_requestedUsage ) { @@ -222,7 +219,7 @@ void intfAccountingBasedModule::checkUsageIsAllowed( } } -stuActiveCredit intfAccountingBasedModule::findBestMatchedCredit( +stuActiveCredit baseintfAccountingBasedModule::findBestMatchedCredit( quint64 _usrID, const ServiceUsage_t& _requestedUsage ) { @@ -359,7 +356,7 @@ stuActiveCredit intfAccountingBasedModule::findBestMatchedCredit( /******************************************************************\ |** basket ********************************************************| \******************************************************************/ -Targoman::API::AAA::stuBasketActionResult IMPL_REST_POST(intfAccountingBasedModule, addToBasket, ( +Targoman::API::AAA::stuBasketActionResult IMPL_REST_POST(baseintfAccountingBasedModule, addToBasket, ( APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM, TAPI::SaleableCode_t _saleableCode, Targoman::API::AAA::OrderAdditives_t _orderAdditives, @@ -392,7 +389,7 @@ Targoman::API::AAA::stuBasketActionResult IMPL_REST_POST(intfAccountingBasedModu //-- -------------------------------- _apiToken = _apiToken.trimmed(); - if (this->IsTokenBase) { + if (this->IsTokenBase()) { if (_apiToken.isEmpty()) throw exHTTPInternalServerError("This product IS token base"); @@ -409,7 +406,7 @@ Targoman::API::AAA::stuBasketActionResult IMPL_REST_POST(intfAccountingBasedModu throw exAuthorization("API Token is not yours"); } - if ((this->IsTokenBase == false) && (_apiToken.isEmpty() == false)) + if ((this->IsTokenBase() == false) && (_apiToken.isEmpty() == false)) throw exHTTPInternalServerError("This product IS NOT token base"); //-- -------------------------------- @@ -691,7 +688,7 @@ Targoman::API::AAA::stuBasketActionResult IMPL_REST_POST(intfAccountingBasedModu PreVoucherItem.UUID); } -Targoman::API::AAA::stuBasketActionResult IMPL_REST_POST(intfAccountingBasedModule, updateBasketItem, ( +Targoman::API::AAA::stuBasketActionResult IMPL_REST_POST(baseintfAccountingBasedModule, updateBasketItem, ( APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM, Targoman::API::AAA::stuPreVoucher _lastPreVoucher, TAPI::MD5_t _itemUUID, @@ -719,7 +716,7 @@ Targoman::API::AAA::stuBasketActionResult IMPL_REST_POST(intfAccountingBasedModu throw exHTTPNotFound("item not found"); } -Targoman::API::AAA::stuBasketActionResult IMPL_REST_POST(intfAccountingBasedModule, removeBasketItem, ( +Targoman::API::AAA::stuBasketActionResult IMPL_REST_POST(baseintfAccountingBasedModule, removeBasketItem, ( APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM, Targoman::API::AAA::stuPreVoucher _lastPreVoucher, TAPI::MD5_t _itemUUID @@ -738,7 +735,7 @@ Targoman::API::AAA::stuBasketActionResult IMPL_REST_POST(intfAccountingBasedModu * updateBasketItem * removeBasketItem */ -Targoman::API::AAA::stuBasketActionResult intfAccountingBasedModule::internalUpdateBasketItem( +Targoman::API::AAA::stuBasketActionResult baseintfAccountingBasedModule::internalUpdateBasketItem( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, Targoman::API::AAA::stuPreVoucher &_lastPreVoucher, stuVoucherItem &_voucherItem, @@ -970,7 +967,7 @@ Targoman::API::AAA::stuBasketActionResult intfAccountingBasedModule::internalUpd * updateBasketItem * removeBasketItem */ -void intfAccountingBasedModule::processItemForBasket( +void baseintfAccountingBasedModule::processItemForBasket( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, INOUT stuAssetItem &_assetItem, const stuVoucherItem *_oldVoucherItem /*= nullptr*/ @@ -1093,7 +1090,7 @@ void intfAccountingBasedModule::processItemForBasket( fnComputeTotalPrice("finish"); } -void intfAccountingBasedModule::digestPrivs( +void baseintfAccountingBasedModule::digestPrivs( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, INOUT stuAssetItem &_assetItem, const stuVoucherItem *_oldVoucherItem /*= nullptr*/ @@ -1101,7 +1098,7 @@ void intfAccountingBasedModule::digestPrivs( ///@TODO: What should I do here? } -void intfAccountingBasedModule::computeSystemDiscount( +void baseintfAccountingBasedModule::computeSystemDiscount( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, INOUT stuAssetItem &_assetItem, const stuPendingSystemDiscount &_pendingSystemDiscount /*= {}*/, @@ -1162,7 +1159,7 @@ void intfAccountingBasedModule::computeSystemDiscount( ///@TODO: tblAccountSystemDiscounts and all its behaviors must be implemented } -void intfAccountingBasedModule::computeCouponDiscount( +void baseintfAccountingBasedModule::computeCouponDiscount( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, INOUT stuAssetItem &_assetItem, const stuVoucherItem *_oldVoucherItem /*= nullptr*/ @@ -1393,7 +1390,7 @@ void intfAccountingBasedModule::computeCouponDiscount( /******************************************************************\ |** process and cancel voucher item *******************************| \******************************************************************/ -bool intfAccountingBasedModule::increaseDiscountUsage( +bool baseintfAccountingBasedModule::increaseDiscountUsage( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const Targoman::API::AAA::stuVoucherItem &_voucherItem ) { @@ -1415,7 +1412,7 @@ bool intfAccountingBasedModule::increaseDiscountUsage( return true; } -bool intfAccountingBasedModule::decreaseDiscountUsage( +bool baseintfAccountingBasedModule::decreaseDiscountUsage( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const Targoman::API::AAA::stuVoucherItem &_voucherItem ) { @@ -1437,7 +1434,7 @@ bool intfAccountingBasedModule::decreaseDiscountUsage( return true; } -bool intfAccountingBasedModule::activateUserAsset( +bool baseintfAccountingBasedModule::activateUserAsset( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const Targoman::API::AAA::stuVoucherItem &_voucherItem, quint64 _voucherID @@ -1455,7 +1452,7 @@ bool intfAccountingBasedModule::activateUserAsset( }); } -bool intfAccountingBasedModule::removeFromUserAssets( +bool baseintfAccountingBasedModule::removeFromUserAssets( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, const Targoman::API::AAA::stuVoucherItem &_voucherItem ) { @@ -1470,7 +1467,7 @@ bool intfAccountingBasedModule::removeFromUserAssets( ); } -bool intfAccountingBasedModule::processVoucherItem( +bool baseintfAccountingBasedModule::processVoucherItem( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, quint64 _userID, const Targoman::API::AAA::stuVoucherItem &_voucherItem, @@ -1493,7 +1490,7 @@ bool intfAccountingBasedModule::processVoucherItem( return true; } -bool intfAccountingBasedModule::cancelVoucherItem( +bool baseintfAccountingBasedModule::cancelVoucherItem( INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM, quint64 _userID, const Targoman::API::AAA::stuVoucherItem &_voucherItem, @@ -1578,7 +1575,7 @@ void checkVoucherItemForTrustedActionSanity(stuVoucherItemForTrustedAction &_dat throw exHTTPBadRequest("Invalid voucher item sign"); } -bool IMPL_REST_POST(intfAccountingBasedModule, processVoucherItem, ( +bool IMPL_REST_POST(baseintfAccountingBasedModule, processVoucherItem, ( APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, Targoman::API::AAA::stuVoucherItemForTrustedAction _data )) { @@ -1587,7 +1584,7 @@ bool IMPL_REST_POST(intfAccountingBasedModule, processVoucherItem, ( return this->processVoucherItem(APICALLBOOM_PARAM, _data.UserID, _data.VoucherItem, _data.VoucherID); } -bool IMPL_REST_POST(intfAccountingBasedModule, cancelVoucherItem, ( +bool IMPL_REST_POST(baseintfAccountingBasedModule, cancelVoucherItem, ( APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM, Targoman::API::AAA::stuVoucherItemForTrustedAction _data )) { @@ -1596,4 +1593,44 @@ bool IMPL_REST_POST(intfAccountingBasedModule, cancelVoucherItem, ( return this->cancelVoucherItem(APICALLBOOM_PARAM, _data.UserID, _data.VoucherItem); } +/***************************************************************************************************\ +|** intfAccountingBasedModule **********************************************************************| +\***************************************************************************************************/ +template +intfAccountingBasedModule<_itmplIsTokenBase>::intfAccountingBasedModule( + const QString &_module, + const QString &_schema, +// bool _isTokenBase, + AssetUsageLimitsCols_t _AssetUsageLimitsCols, + intfAccountUnits *_units, + intfAccountProducts *_products, + intfAccountSaleables *_saleables, + intfAccountSaleablesFiles *_saleablesFiles, + intfAccountUserAssets<_itmplIsTokenBase> *_userAssets, + intfAccountUserAssetsFiles *_userAssetsFiles, + intfAccountAssetUsage<_itmplIsTokenBase> *_assetUsages, + intfAccountCoupons *_discounts, + intfAccountPrizes *_prizes +) : + baseintfAccountingBasedModule( + _module, + _schema, + _AssetUsageLimitsCols, + _units, + _products, + _saleables, + _saleablesFiles, + _userAssets, + _userAssetsFiles, + _assetUsages, + _discounts, + _prizes + ) +{ + ServiceRegistry.insert(this->ServiceName, this); +} + +template class intfAccountingBasedModule; +template class intfAccountingBasedModule; + } //namespace Targoman::API::AAA diff --git a/Interfaces/AAA/intfAccountingBasedModule.h b/Interfaces/AAA/intfAccountingBasedModule.h index 98d0ee9a..59cb7aa1 100644 --- a/Interfaces/AAA/intfAccountingBasedModule.h +++ b/Interfaces/AAA/intfAccountingBasedModule.h @@ -33,29 +33,30 @@ namespace Targoman::API::AAA { using namespace API; -class intfAccountingBasedModule : public intfSQLBasedModule +/******************************************************/ +class baseintfAccountingBasedModule : public intfSQLBasedModule { Q_OBJECT -protected: - intfAccountingBasedModule( - const QString &_module, - const QString &_schema, - bool _isTokenBase, +public: + baseintfAccountingBasedModule( + const QString &_module, + const QString &_schema, AssetUsageLimitsCols_t _AssetUsageLimitsCols, intfAccountUnits *_units, intfAccountProducts *_products, intfAccountSaleables *_saleables, intfAccountSaleablesFiles *_saleablesFiles, - intfAccountUserAssets *_userAssets, + baseintfAccountUserAssets *_userAssets, intfAccountUserAssetsFiles *_userAssetsFiles, - intfAccountAssetUsage *_assetUsages, + baseintfAccountAssetUsage *_assetUsages, intfAccountCoupons *_discounts = nullptr, intfAccountPrizes *_prizes = nullptr ); -// virtual ~intfAccountingBasedModule(); public: + virtual bool IsTokenBase() = 0; + virtual stuActiveCredit activeAccountObject(quint64 _usrID); protected: @@ -64,6 +65,7 @@ class intfAccountingBasedModule : public intfSQLBasedModule virtual bool isUnlimited(const UsageLimits_t& _limits) const = 0; virtual bool isEmpty(const UsageLimits_t& _limits) const = 0; +protected: void checkUsageIsAllowed( INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, const ServiceUsage_t& _requestedUsage @@ -180,6 +182,16 @@ class intfAccountingBasedModule : public intfSQLBasedModule return true; }; + +protected: + Targoman::API::AAA::stuBasketActionResult internalUpdateBasketItem( + INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, + Targoman::API::AAA::stuPreVoucher &_lastPreVoucher, + stuVoucherItem &_voucherItem, + qreal _newQty, + NULLABLE_TYPE(TAPI::CouponCode_t) _newDiscountCode = NULLABLE_NULL_VALUE + ); + protected slots: Targoman::API::AAA::stuBasketActionResult REST_POST( addToBasket, @@ -222,15 +234,6 @@ protected slots: "Only Pending items can be removed." ) -protected: - Targoman::API::AAA::stuBasketActionResult internalUpdateBasketItem( - INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, - Targoman::API::AAA::stuPreVoucher &_lastPreVoucher, - stuVoucherItem &_voucherItem, - qreal _newQty, - NULLABLE_TYPE(TAPI::CouponCode_t) _newDiscountCode = NULLABLE_NULL_VALUE - ); - protected slots: bool REST_POST( processVoucherItem, @@ -253,15 +256,13 @@ protected slots: protected: QString ServiceName; - bool IsTokenBase; - QScopedPointer AccountUnits; QScopedPointer AccountProducts; QScopedPointer AccountSaleables; QScopedPointer AccountSaleablesFiles; - QScopedPointer AccountUserAssets; + QScopedPointer AccountUserAssets; QScopedPointer AccountUserAssetsFiles; - QScopedPointer AccountAssetUsages; + QScopedPointer AccountAssetUsages; QScopedPointer AccountCoupons; QScopedPointer AccountPrizes; @@ -269,7 +270,35 @@ protected slots: QStringList AssetUsageLimitsColsName; }; -extern intfAccountingBasedModule* serviceAccounting(const QString& _serviceName); +/******************************************************/ +template +class intfAccountingBasedModule : public baseintfAccountingBasedModule +{ +protected: + intfAccountingBasedModule( + const QString &_module, + const QString &_schema, +// bool _isTokenBase, + AssetUsageLimitsCols_t _AssetUsageLimitsCols, + intfAccountUnits *_units, + intfAccountProducts *_products, + intfAccountSaleables *_saleables, + intfAccountSaleablesFiles *_saleablesFiles, + intfAccountUserAssets<_itmplIsTokenBase> *_userAssets, + intfAccountUserAssetsFiles *_userAssetsFiles, + intfAccountAssetUsage<_itmplIsTokenBase> *_assetUsages, + intfAccountCoupons *_discounts = nullptr, + intfAccountPrizes *_prizes = nullptr + ); +// virtual ~intfAccountingBasedModule(); + +protected: + inline bool IsTokenBase() { + return _itmplIsTokenBase; + } +}; + +extern baseintfAccountingBasedModule* serviceAccounting(const QString& _serviceName); } //namespace Targoman::API::AAA diff --git a/Interfaces/API/intfPureModule.h b/Interfaces/API/intfPureModule.h index a447f03b..9d19f869 100644 --- a/Interfaces/API/intfPureModule.h +++ b/Interfaces/API/intfPureModule.h @@ -80,12 +80,10 @@ using namespace TAPI; #define GET_METHOD_ARGS_ANONYMOUSE_DECL_APICALL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL) #define GET_METHOD_ARGS_USER_DECL_APICALL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(APICALLBOOM_TYPE_JWT_USER_DECL) #define GET_METHOD_ARGS_API_DECL_APICALL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(APICALLBOOM_TYPE_JWT_API_DECL) -#define GET_METHOD_ARGS_USER_OR_API_DECL_APICALL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(APICALLBOOM_TYPE_JWT_USER_OR_API_DECL) #define GET_METHOD_ARGS_ANONYMOUSE_IMPL_APICALL INTERNAL_GET_METHOD_ARGS_IMPL_APICALL(APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL) #define GET_METHOD_ARGS_USER_IMPL_APICALL INTERNAL_GET_METHOD_ARGS_IMPL_APICALL(APICALLBOOM_TYPE_JWT_USER_IMPL) #define GET_METHOD_ARGS_API_IMPL_APICALL INTERNAL_GET_METHOD_ARGS_IMPL_APICALL(APICALLBOOM_TYPE_JWT_API_IMPL) -#define GET_METHOD_ARGS_USER_OR_API_IMPL_APICALL INTERNAL_GET_METHOD_ARGS_IMPL_APICALL(APICALLBOOM_TYPE_JWT_USER_OR_API_IMPL) #define ORMGET_ANONYMOUSE(_doc, ...) apiGET(GET_METHOD_ARGS_ANONYMOUSE_DECL_APICALL) __VA_ARGS__; \ QString signOfGET() { return TARGOMAN_M2STR((GET_METHOD_ARGS_USER_DECL_APICALL)); } \ @@ -103,14 +101,23 @@ using namespace TAPI; QString signOfGET##_name() { return TARGOMAN_M2STR((GET_METHOD_ARGS_USER_DECL_APICALL)); } \ QString docOfGET##_name() { return _doc; } -#define ORMGET_USER_OR_API(_doc, ...) apiGET(GET_METHOD_ARGS_USER_OR_API_DECL_APICALL) __VA_ARGS__; \ - QString signOfGET() { return TARGOMAN_M2STR((GET_METHOD_ARGS_USER_OR_API_DECL_APICALL)); } \ +#define ORMGET_API(_doc, ...) apiGET(GET_METHOD_ARGS_API_DECL_APICALL) __VA_ARGS__; \ + QString signOfGET() { return TARGOMAN_M2STR((GET_METHOD_ARGS_API_DECL_APICALL)); } \ QString docOfGET() { return _doc; } #define IMPL_ORMGET_ANONYMOUSE(_module) _module::apiGET(GET_METHOD_ARGS_ANONYMOUSE_IMPL_APICALL) #define IMPL_ORMGET_USER(_module) _module::apiGET(GET_METHOD_ARGS_USER_IMPL_APICALL) #define IMPL_ORMGET_API(_module) _module::apiGET(GET_METHOD_ARGS_API_IMPL_APICALL) -#define IMPL_ORMGET_USER_OR_API(_module) _module::apiGET(GET_METHOD_ARGS_USER_OR_API_IMPL_APICALL) + +//tokenbase +#define GET_METHOD_ARGS_TOKENBASE_DECL_APICALL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(APICALLBOOM_TYPE_JWT_TOKENBASE_DECL) +#define GET_METHOD_ARGS_TOKENBASE_IMPL_APICALL INTERNAL_GET_METHOD_ARGS_IMPL_APICALL(APICALLBOOM_TYPE_JWT_TOKENBASE_IMPL) + +#define ORMGET_TOKENBASE(_doc, ...) apiGET(GET_METHOD_ARGS_TOKENBASE_DECL_APICALL) __VA_ARGS__; \ + QString signOfGET() { return TARGOMAN_M2STR((GET_METHOD_ARGS_TOKENBASE_DECL_APICALL)); } \ + QString docOfGET() { return _doc; } + +#define IMPL_ORMGET_TOKENBASE(_module) _module::apiGET(GET_METHOD_ARGS_TOKENBASE_IMPL_APICALL) //used by intfSQLBasedModule #define GET_METHOD_ARGS_DECL_INTERNAL INTERNAL_GET_METHOD_ARGS_DECL_APICALL(INTFAPICALLBOOM_DECL) diff --git a/Interfaces/Server/APICallBoom.h b/Interfaces/Server/APICallBoom.h index 48a42437..036bda38 100644 --- a/Interfaces/Server/APICallBoom.h +++ b/Interfaces/Server/APICallBoom.h @@ -156,8 +156,8 @@ class intfAPICallBoom ); } inline bool canProvideJWT() { - return (this->tokenAllowANONYMOUSE() - && (this->tokenAllowUSER() || this->tokenAllowAPI()) + return (/*this->tokenAllowANONYMOUSE() + &&*/ (this->tokenAllowUSER() || this->tokenAllowAPI()) ); } diff --git a/ModuleHelpers/MT/Interfaces/intfMTAccounting.cpp b/ModuleHelpers/MT/Interfaces/intfMTAccounting.cpp index 54f905f6..861afff1 100644 --- a/ModuleHelpers/MT/Interfaces/intfMTAccounting.cpp +++ b/ModuleHelpers/MT/Interfaces/intfMTAccounting.cpp @@ -139,20 +139,39 @@ intfAccountSaleablesFilesMT::intfAccountSaleablesFilesMT( /******************************************************************/ /******************************************************************/ /******************************************************************/ -intfAccountUserAssetsMT::intfAccountUserAssetsMT( +baseintfAccountUserAssetsMT::baseintfAccountUserAssetsMT( +// const QString& _schema, +// const QList& _exclusiveCols, +// const QList& _exclusiveRelations, +// const QList& _exclusiveIndexes +//) : +// baseintfAccountUserAssets( +// _schema, +// _exclusiveCols, +// _exclusiveRelations, +// _exclusiveIndexes + ) +{ ; } + +/******************************************************************/ +template +intfAccountUserAssetsMT<_itmplIsTokenBase>::intfAccountUserAssetsMT( const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, const QList& _exclusiveIndexes ) : - intfAccountUserAssets( + intfAccountUserAssets<_itmplIsTokenBase>( _schema, tblAccountUserAssetsMTBase::Private::ExtraORMFields + _exclusiveCols, tblAccountUserAssetsMTBase::Private::ExtraRelations(_schema) + _exclusiveRelations, tblAccountUserAssetsMTBase::Private::ExtraIndexes + _exclusiveIndexes - ) + ), + baseintfAccountUserAssetsMT() { ; } +/******************************************************************/ +/******************************************************************/ /******************************************************************/ intfAccountUserAssetsFilesMT::intfAccountUserAssetsFilesMT( const QString& _schema, @@ -171,18 +190,35 @@ intfAccountUserAssetsFilesMT::intfAccountUserAssetsFilesMT( /******************************************************************/ /******************************************************************/ /******************************************************************/ -intfAccountAssetUsageMT::intfAccountAssetUsageMT( +baseintfAccountAssetUsageMT::baseintfAccountAssetUsageMT( +// const QString& _schema, +// const QList& _exclusiveCols, +// const QList& _exclusiveRelations, +// const QList& _exclusiveIndexes +//) : +// baseintfAccountAssetUsage( +// _schema, +// _exclusiveCols, +// _exclusiveRelations, +// _exclusiveIndexes + ) +{ ; } + +/******************************************************************/ +template +intfAccountAssetUsageMT<_itmplIsTokenBase>::intfAccountAssetUsageMT( const QString& _schema, const QList& _exclusiveCols, const QList& _exclusiveRelations, const QList& _exclusiveIndexes ) : - intfAccountAssetUsage( + intfAccountAssetUsage<_itmplIsTokenBase>( _schema, tblAccountAssetUsageMTBase::Private::ExtraORMFields + _exclusiveCols, tblAccountAssetUsageMTBase::Private::ExtraRelations(_schema) + _exclusiveRelations, tblAccountAssetUsageMTBase::Private::ExtraIndexes + _exclusiveIndexes - ) + ), + baseintfAccountAssetUsageMT() { ; } /******************************************************************/ @@ -219,4 +255,33 @@ intfAccountCouponsMT::intfAccountCouponsMT( // ) //{ ; } +/******************************************************/ +/******************************************************/ +/******************************************************/ +//template class intfAccountUnitsMT; +//template class intfAccountUnitsI18NMT; +//template class intfAccountProductsMT; +//template class intfAccountProductsI18NMT; +//template class intfAccountSaleablesMT; +//template class intfAccountSaleablesI18NMT; +//template class intfAccountSaleablesFilesMT; +template class intfAccountUserAssetsMT; +//template class intfAccountUserAssetsFilesMT; +template class intfAccountAssetUsageMT; +//template class intfAccountCouponsMT; +//template class intfAccountPrizesMT; + +//template class intfAccountUnitsMT; +//template class intfAccountUnitsI18NMT; +//template class intfAccountProductsMT; +//template class intfAccountProductsI18NMT; +//template class intfAccountSaleablesMT; +//template class intfAccountSaleablesI18NMT; +//template class intfAccountSaleablesFilesMT; +template class intfAccountUserAssetsMT; +//template class intfAccountUserAssetsFilesMT; +template class intfAccountAssetUsageMT; +//template class intfAccountCouponsMT; +//template class intfAccountPrizesMT; + } //namespace Targoman::API::ModuleHelpers::MT::Interfaces diff --git a/ModuleHelpers/MT/Interfaces/intfMTAccounting.h b/ModuleHelpers/MT/Interfaces/intfMTAccounting.h index 4f8158ef..68e58df7 100644 --- a/ModuleHelpers/MT/Interfaces/intfMTAccounting.h +++ b/ModuleHelpers/MT/Interfaces/intfMTAccounting.h @@ -407,6 +407,8 @@ class intfAccountUnitsMT : public intfAccountUnits const QList& _exclusiveIndexes = {}); }; +/******************************************************/ +/******************************************************/ /******************************************************/ class intfAccountUnitsI18NMT : public intfAccountUnitsI18N { @@ -433,6 +435,8 @@ class intfAccountProductsMT : public intfAccountProducts const QList& _exclusiveIndexes = {}); }; +/******************************************************/ +/******************************************************/ /******************************************************/ class intfAccountProductsI18NMT : public intfAccountProductsI18N { @@ -459,6 +463,8 @@ class intfAccountSaleablesMT : public intfAccountSaleables const QList& _exclusiveIndexes = {}); }; +/******************************************************/ +/******************************************************/ /******************************************************/ class intfAccountSaleablesI18NMT : public intfAccountSaleablesI18N { @@ -471,6 +477,8 @@ class intfAccountSaleablesI18NMT : public intfAccountSaleablesI18N const QList& _exclusiveIndexes = {}); }; +/******************************************************/ +/******************************************************/ /******************************************************/ class intfAccountSaleablesFilesMT : public intfAccountSaleablesFiles { @@ -486,9 +494,22 @@ class intfAccountSaleablesFilesMT : public intfAccountSaleablesFiles /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountUserAssetsMT : public intfAccountUserAssets +class baseintfAccountUserAssetsMT //: private QObject { - Q_OBJECT +// Q_OBJECT + +public: + baseintfAccountUserAssetsMT(); + +protected slots: +//APICALLBOOM_TYPE_JWT_TOKENBASE_DECL +//APICALLBOOM_TYPE_JWT_TOKENBASE_IMPL +}; + +template +class intfAccountUserAssetsMT : public intfAccountUserAssets<_itmplIsTokenBase>, public baseintfAccountUserAssetsMT +{ +// Q_OBJECT public: intfAccountUserAssetsMT(const QString& _schema, @@ -512,9 +533,22 @@ class intfAccountUserAssetsFilesMT : public intfAccountUserAssetsFiles /******************************************************/ /******************************************************/ /******************************************************/ -class intfAccountAssetUsageMT : public intfAccountAssetUsage +class baseintfAccountAssetUsageMT //: private QObject { - Q_OBJECT +// Q_OBJECT + +public: + baseintfAccountAssetUsageMT(); + +protected slots: +//APICALLBOOM_TYPE_JWT_TOKENBASE_DECL +//APICALLBOOM_TYPE_JWT_TOKENBASE_IMPL +}; + +template +class intfAccountAssetUsageMT : public intfAccountAssetUsage<_itmplIsTokenBase>, public baseintfAccountAssetUsageMT +{ +// Q_OBJECT public: intfAccountAssetUsageMT(const QString& _schema, @@ -541,9 +575,10 @@ class intfAccountCouponsMT : public intfAccountCoupons /******************************************************/ /******************************************************/ //There is no Prize in this module -/*class intfAccountPrizesMT : public intfAccountPrizes +/* +class intfAccountPrizesMT : public intfAccountPrizes { - Q_OBJECT +// Q_OBJECT public: intfAccountPrizesMT(); diff --git a/ModuleHelpers/MT/Interfaces/intfMTHelpers.h b/ModuleHelpers/MT/Interfaces/intfMTHelpers.h index 608bede2..4f01532e 100644 --- a/ModuleHelpers/MT/Interfaces/intfMTHelpers.h +++ b/ModuleHelpers/MT/Interfaces/intfMTHelpers.h @@ -420,12 +420,14 @@ class intfHelperORMBase typedef typename std::conditional<_itmplTokenActorType == TAPI::enuTokenActorType::USER, APICALLBOOM_TYPE_JWT_USER_DECL, APICALLBOOM_TYPE_JWT_API_DECL>::type - MT_JWT_TYPE_DECL; + APICALLBOOM_TYPE_JWT_TOKENBASE_DECL; +// MT_JWT_TYPE_DECL; typedef Q_DECL_UNUSED typename std::conditional<_itmplTokenActorType == TAPI::enuTokenActorType::USER, APICALLBOOM_TYPE_JWT_USER_DECL, APICALLBOOM_TYPE_JWT_API_DECL>::type - MT_JWT_TYPE_IMPL; + APICALLBOOM_TYPE_JWT_TOKENBASE_IMPL; +// MT_JWT_TYPE_IMPL; public: TAPI::enuTokenActorType::Type tokenActorType() { return _itmplTokenActorType; } diff --git a/Modules/Account/moduleSrc/ORM/APITokens.cpp b/Modules/Account/moduleSrc/ORM/APITokens.cpp index d95f77c8..7b19e3c3 100644 --- a/Modules/Account/moduleSrc/ORM/APITokens.cpp +++ b/Modules/Account/moduleSrc/ORM/APITokens.cpp @@ -256,21 +256,21 @@ QVariantMap IMPL_REST_UPDATE(APITokens, , ( if (NULLABLE_HAS_VALUE(_expireDate)) { TokenJWTPayload["exp"] = (NULLABLE_VALUE(_expireDate)).toSecsSinceEpoch(); NewToken = QJWT::encryptAndSigned(TokenJWTPayload); - MethodResult.insert("token", NewToken); ++ToUpdateCount; UpdateQuery .set(tblAPITokens::Fields::aptToken, NewToken) .set(tblAPITokens::Fields::aptExpiryDate, NULLABLE_VALUE(_expireDate)) ; + + MethodResult.insert("token", NewToken); } if (ToUpdateCount == 0) throw exHTTPInternalServerError("Nothing to do"); try { - if (UpdateQuery.execute(CurrentUserID) == 0) - throw exHTTPInternalServerError("Error in updating"); + UpdateQuery.execute(CurrentUserID); } catch (const std::exception &_exp) { QString ExpStr = _exp.what(); if (ExpStr.contains("Duplicate entry", Qt::CaseInsensitive)) diff --git a/Modules/Advert/moduleSrc/Advert.cpp b/Modules/Advert/moduleSrc/Advert.cpp index e18f24bf..0bbedbbc 100644 --- a/Modules/Advert/moduleSrc/Advert.cpp +++ b/Modules/Advert/moduleSrc/Advert.cpp @@ -69,7 +69,7 @@ Advert::Advert() : intfAccountingBasedModule( AdvertDomain, AdvertSchema, - false, +// false, { { "show", { /* day */ tblAccountSaleables::ExtraFields::slbShowPerDay, diff --git a/Modules/Advert/moduleSrc/Advert.h b/Modules/Advert/moduleSrc/Advert.h index 9c02ca96..e8a218c5 100644 --- a/Modules/Advert/moduleSrc/Advert.h +++ b/Modules/Advert/moduleSrc/Advert.h @@ -56,7 +56,7 @@ TARGOMAN_ACTIONLOG_PREPARENT; TARGOMAN_OBJECTSTORAGE_PREPARENT; TARGOMAN_FAQ_PREPARENT; -class Advert : public intfAccountingBasedModule +class Advert : public intfAccountingBasedModule { Q_OBJECT Q_PLUGIN_METADATA(IID INTFPUREMODULE_IID) diff --git a/Modules/Advert/moduleSrc/ORM/Accounting.cpp b/Modules/Advert/moduleSrc/ORM/Accounting.cpp index 47408cf9..fcc7b8c1 100644 --- a/Modules/Advert/moduleSrc/ORM/Accounting.cpp +++ b/Modules/Advert/moduleSrc/ORM/Accounting.cpp @@ -37,7 +37,6 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountUnits) AccountUnits::AccountUnits() : intfAccountUnits( -// false, AdvertSchema, tblAccountUnits::Private::ExtraORMFields, tblAccountUnits::Private::ExtraRelations, @@ -51,7 +50,6 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountUnitsI18N) AccountUnitsI18N::AccountUnitsI18N() : intfAccountUnitsI18N( -// false, AdvertSchema, tblAccountUnitsI18N::Private::ExtraORMFields, tblAccountUnitsI18N::Private::ExtraRelations, @@ -65,7 +63,6 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountProducts) AccountProducts::AccountProducts() : intfAccountProducts( -// false, AdvertSchema, tblAccountProducts::Private::ExtraORMFields, tblAccountProducts::Private::ExtraRelations, @@ -79,7 +76,6 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountProductsI18N) AccountProductsI18N::AccountProductsI18N() : intfAccountProductsI18N( -// false, AdvertSchema, tblAccountProductsI18N::Private::ExtraORMFields, tblAccountProductsI18N::Private::ExtraRelations, @@ -93,7 +89,6 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountSaleables) AccountSaleables::AccountSaleables() : intfAccountSaleables( -// false, AdvertSchema, tblAccountSaleables::Private::ExtraORMFields, tblAccountSaleables::Private::ExtraRelations, @@ -107,7 +102,6 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountSaleablesI18N) AccountSaleablesI18N::AccountSaleablesI18N() : intfAccountSaleablesI18N( -// false, AdvertSchema, tblAccountSaleablesI18N::Private::ExtraORMFields, tblAccountSaleablesI18N::Private::ExtraRelations, @@ -119,7 +113,6 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountSaleablesFiles) AccountSaleablesFiles::AccountSaleablesFiles() : intfAccountSaleablesFiles( -// false, AdvertSchema, tblAccountSaleablesFiles::Private::ExtraORMFields, tblAccountSaleablesFiles::Private::ExtraRelations, @@ -133,7 +126,6 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountUserAssets) AccountUserAssets::AccountUserAssets() : intfAccountUserAssets( -// false, AdvertSchema, tblAccountUserAssets::Private::ExtraORMFields, tblAccountUserAssets::Private::ExtraRelations, @@ -145,7 +137,6 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountUserAssetsFiles) AccountUserAssetsFiles::AccountUserAssetsFiles() : intfAccountUserAssetsFiles( -// false, AdvertSchema, tblAccountUserAssetsFiles::Private::ExtraORMFields, tblAccountUserAssetsFiles::Private::ExtraRelations, @@ -159,7 +150,6 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountAssetUsage) AccountAssetUsage::AccountAssetUsage() : intfAccountAssetUsage( -// false, AdvertSchema, tblAccountAssetUsage::Private::ExtraORMFields, tblAccountAssetUsage::Private::ExtraRelations, @@ -173,7 +163,6 @@ TARGOMAN_API_SUBMODULE_IMPLEMENT(Advert, AccountCoupons) AccountCoupons::AccountCoupons() : intfAccountCoupons( -// false, AdvertSchema, tblAccountCoupons::Private::ExtraORMFields, tblAccountCoupons::Private::ExtraRelations, diff --git a/Modules/Advert/moduleSrc/ORM/Accounting.h b/Modules/Advert/moduleSrc/ORM/Accounting.h index 1064ec97..3ea8d13f 100644 --- a/Modules/Advert/moduleSrc/ORM/Accounting.h +++ b/Modules/Advert/moduleSrc/ORM/Accounting.h @@ -502,7 +502,7 @@ class AccountSaleablesFiles : public intfAccountSaleablesFiles /******************************************************/ /******************************************************/ /******************************************************/ -class AccountUserAssets : public intfAccountUserAssets +class AccountUserAssets : public intfAccountUserAssets { Q_OBJECT TARGOMAN_API_SUBMODULE_DEFINE(Advert, AccountUserAssets) @@ -522,7 +522,7 @@ class AccountUserAssetsFiles : public intfAccountUserAssetsFiles /******************************************************/ /******************************************************/ /******************************************************/ -class AccountAssetUsage : public intfAccountAssetUsage +class AccountAssetUsage : public intfAccountAssetUsage { Q_OBJECT TARGOMAN_API_SUBMODULE_DEFINE(Advert, AccountAssetUsage) @@ -545,10 +545,11 @@ class AccountCoupons : public intfAccountCoupons /******************************************************/ /******************************************************/ //There is no Prize in the advertisement module -/*class clsAccountPrizes: public Accounting::intfAccountPrizes +/* +class clsAccountPrizes: public intfAccountPrizes { Q_OBJECT - TARGOMAN_API_SUBMODULE_DEFINE(Advert,clsAccountPrizes) + TARGOMAN_API_SUBMODULE_DEFINE(Advert, clsAccountPrizes) private slots: public: diff --git a/Modules/MT/moduleSrc/MT.cpp b/Modules/MT/moduleSrc/MT.cpp index 405c0d4d..7161e485 100644 --- a/Modules/MT/moduleSrc/MT.cpp +++ b/Modules/MT/moduleSrc/MT.cpp @@ -60,7 +60,7 @@ MT::MT() : intfAccountingBasedModule( MTDomain, MTSchema, - true, +// true, { { "words", { /* day */ {}, //tblAccountSaleables::ExtraFields::slbWordsPerDay, diff --git a/Modules/MT/moduleSrc/MT.h b/Modules/MT/moduleSrc/MT.h index 1fb3010c..c2d2dcec 100644 --- a/Modules/MT/moduleSrc/MT.h +++ b/Modules/MT/moduleSrc/MT.h @@ -48,7 +48,7 @@ TARGOMAN_ACTIONLOG_PREPARENT; TARGOMAN_OBJECTSTORAGE_PREPARENT; TARGOMAN_FAQ_PREPARENT; -class MT : public intfAccountingBasedModule +class MT : public intfAccountingBasedModule { Q_OBJECT Q_PLUGIN_METADATA(IID INTFPUREMODULE_IID) diff --git a/Modules/MT/moduleSrc/ORM/Accounting.h b/Modules/MT/moduleSrc/ORM/Accounting.h index 7a5b4108..da5ec8d5 100644 --- a/Modules/MT/moduleSrc/ORM/Accounting.h +++ b/Modules/MT/moduleSrc/ORM/Accounting.h @@ -419,7 +419,7 @@ class AccountSaleablesFiles : public intfAccountSaleablesFilesMT /******************************************************/ /******************************************************/ /******************************************************/ -class AccountUserAssets : public intfAccountUserAssetsMT +class AccountUserAssets : public intfAccountUserAssetsMT { Q_OBJECT TARGOMAN_API_SUBMODULE_DEFINE(MT, AccountUserAssets) @@ -439,7 +439,7 @@ class AccountUserAssetsFiles : public intfAccountUserAssetsFilesMT /******************************************************/ /******************************************************/ /******************************************************/ -class AccountAssetUsage : public intfAccountAssetUsageMT +class AccountAssetUsage : public intfAccountAssetUsageMT { Q_OBJECT TARGOMAN_API_SUBMODULE_DEFINE(MT, AccountAssetUsage) @@ -462,7 +462,8 @@ class AccountCoupons : public intfAccountCouponsMT /******************************************************/ /******************************************************/ //There is no Prize in this module -/*class AccountPrizes : public intfAccountPrizesMT +/* +class AccountPrizes : public intfAccountPrizesMT { Q_OBJECT TARGOMAN_API_SUBMODULE_DEFINE(MT,clsAccountPrizes) diff --git a/Modules/TargomanMT/moduleSrc/ORM/Accounting.h b/Modules/TargomanMT/moduleSrc/ORM/Accounting.h index 505da1d9..9c1e4329 100644 --- a/Modules/TargomanMT/moduleSrc/ORM/Accounting.h +++ b/Modules/TargomanMT/moduleSrc/ORM/Accounting.h @@ -419,7 +419,7 @@ class AccountSaleablesFiles : public intfAccountSaleablesFilesMT /******************************************************/ /******************************************************/ /******************************************************/ -class AccountUserAssets : public intfAccountUserAssetsMT +class AccountUserAssets : public intfAccountUserAssetsMT { Q_OBJECT TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, AccountUserAssets) @@ -439,7 +439,7 @@ class AccountUserAssetsFiles : public intfAccountUserAssetsFilesMT /******************************************************/ /******************************************************/ /******************************************************/ -class AccountAssetUsage : public intfAccountAssetUsageMT +class AccountAssetUsage : public intfAccountAssetUsageMT { Q_OBJECT TARGOMAN_API_SUBMODULE_DEFINE(TargomanMT, AccountAssetUsage) @@ -462,7 +462,8 @@ class AccountCoupons : public intfAccountCouponsMT /******************************************************/ /******************************************************/ //There is no Prize in this module -/*class AccountPrizes : public intfAccountPrizesMT +/* +class AccountPrizes : public intfAccountPrizesMT { Q_OBJECT TARGOMAN_API_SUBMODULE_DEFINE(Targoman,clsAccountPrizes) diff --git a/Modules/TargomanMT/moduleSrc/TargomanMT.cpp b/Modules/TargomanMT/moduleSrc/TargomanMT.cpp index a0a89324..c4484c1d 100644 --- a/Modules/TargomanMT/moduleSrc/TargomanMT.cpp +++ b/Modules/TargomanMT/moduleSrc/TargomanMT.cpp @@ -60,7 +60,7 @@ TargomanMT::TargomanMT() : intfAccountingBasedModule( TargomanMTDomain, TargomanMTSchema, - false, +// false, { // { "show", { // /* day */ tblAccountSaleables::ExtraFields::slbShowPerDay, diff --git a/Modules/TargomanMT/moduleSrc/TargomanMT.h b/Modules/TargomanMT/moduleSrc/TargomanMT.h index 591af5d5..23f32b0d 100644 --- a/Modules/TargomanMT/moduleSrc/TargomanMT.h +++ b/Modules/TargomanMT/moduleSrc/TargomanMT.h @@ -48,7 +48,7 @@ TARGOMAN_ACTIONLOG_PREPARENT; TARGOMAN_OBJECTSTORAGE_PREPARENT; TARGOMAN_FAQ_PREPARENT; -class TargomanMT : public intfAccountingBasedModule +class TargomanMT : public intfAccountingBasedModule { Q_OBJECT Q_PLUGIN_METADATA(IID INTFPUREMODULE_IID)