Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 69 additions & 6 deletions Interfaces/AAA/Accounting_Interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
#include "Accounting_Interfaces.h"
#include "Interfaces/AAA/Authorization.h"
#include "Interfaces/Common/QtTypes.hpp"
#include "Interfaces/Helpers/TokenHelper.h"

using namespace Targoman::API;
using namespace Targoman::API::AAA;
using namespace Targoman::API::Helpers;

//TAPI_REGISTER_TARGOMAN_ENUM(Targoman::API::AAA, enuPreVoucherType);
TAPI_REGISTER_TARGOMAN_ENUM(Targoman::API::AAA, enuVoucherType);
Expand Down Expand Up @@ -658,9 +660,55 @@ baseintfAccountUserAssets_API::baseintfAccountUserAssets_API(
// , 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);
quint64 checkAPITokenOwner(
INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM,
QString _apiToken
) {
if (APICALLBOOM_PARAM.jwtActorType() != TAPI::enuTokenActorType::USER)
throw exAuthorization("JWT is not USER type");

_apiToken = _apiToken.trimmed();
if (_apiToken.isEmpty())
throw exHTTPInternalServerError("API Token not provided");

enuTokenBanType TokenBanType = TokenHelper::GetTokenBanType(_apiToken);
if (TokenBanType == enuTokenBanType::Block)
throw exAuthorization("This API Token is blocked");

TAPI::JWT_t APITokenJWTPayload;
QJWT::extractAndDecryptPayload(_apiToken, APITokenJWTPayload);

clsJWT APITokenJWT(APITokenJWTPayload);

if (APITokenJWT.actorType() != TAPI::enuTokenActorType::API)
throw exAuthorization("Just API Token is allowed");

if (APITokenJWT.ownerID() != APICALLBOOM_PARAM.getActorID())
throw exAuthorization("API Token is not yours");

quint64 APITokenID = APITokenJWT.actorID();

return APITokenID;
}

QVariant IMPL_REST_GET(baseintfAccountUserAssets_API, , (
APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM,
QString _apiToken,
TAPI::PKsByPath_t _pksByPath,
quint64 _pageIndex,
quint16 _pageSize,
TAPI::Cols_t _cols,
TAPI::Filter_t _filters,
TAPI::OrderBy_t _orderBy,
TAPI::GroupBy_t _groupBy,
bool _reportCount
)) {
bool _translate = true;

quint64 APITokenID = checkAPITokenOwner(APICALLBOOM_PARAM, _apiToken);

// if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false)
this->setSelfFilters({{ tblAccountUserAssetsBase::Fields::uas_actorID, APITokenID }}, _filters);

auto fnTouchQuery = [this, &_cols](ORMSelectQuery &_query) {
if (_cols.isEmpty())
Expand Down Expand Up @@ -904,9 +952,24 @@ baseintfAccountAssetUsage_API::baseintfAccountAssetUsage_API(
// , 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);
QVariant IMPL_REST_GET(baseintfAccountAssetUsage_API, , (
APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM,
QString _apiToken,
TAPI::PKsByPath_t _pksByPath,
quint64 _pageIndex,
quint16 _pageSize,
TAPI::Cols_t _cols,
TAPI::Filter_t _filters,
TAPI::OrderBy_t _orderBy,
TAPI::GroupBy_t _groupBy,
bool _reportCount
)) {
bool _translate = true;

quint64 APITokenID = checkAPITokenOwner(APICALLBOOM_PARAM, _apiToken);

// if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false)
this->setSelfFilters({{ tblAccountUserAssetsBase::Fields::uas_actorID, APITokenID }}, _filters);

return this->Select(GET_METHOD_ARGS_CALL_VALUES);
}
Expand Down
42 changes: 37 additions & 5 deletions Interfaces/AAA/Accounting_Interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,23 @@ class baseintfAccountUserAssets_API : public baseintfAccountUserAssets

private slots:
// QVariant ORMGET_TOKENBASE("Get User Assets")
QVariant ORMGET_API("Get User Assets")
// QVariant ORMGET_API("Get User Assets")
QVariant REST_GET(
,
(
APICALLBOOM_TYPE_JWT_USER_DECL &APICALLBOOM_PARAM,
QString _apiToken,
TAPI::PKsByPath_t _pksByPath = {},
quint64 _pageIndex = 0,
quint16 _pageSize = 20,
TAPI::Cols_t _cols = {},
TAPI::Filter_t _filters = {},
TAPI::OrderBy_t _orderBy = {},
TAPI::GroupBy_t _groupBy = {},
bool _reportCount = true
),
"Get User Assets"
);
};

/******************************************************/
Expand Down Expand Up @@ -424,8 +440,8 @@ class baseintfAccountAssetUsage_USER : public baseintfAccountAssetUsage
const QList<DBM::stuDBIndex>& _indexes = {});

private slots:
// QVariant ORMGET_TOKENBASE("Get User Assets")
QVariant ORMGET_USER("Get User Assets")
// QVariant ORMGET_TOKENBASE("Get User Asset Usage")
QVariant ORMGET_USER("Get User Asset Usage")
};

/******************************************************/
Expand All @@ -441,8 +457,24 @@ class baseintfAccountAssetUsage_API : public baseintfAccountAssetUsage
const QList<DBM::stuDBIndex>& _indexes = {});

private slots:
// QVariant ORMGET_TOKENBASE("Get User Assets")
QVariant ORMGET_API("Get User Assets")
// QVariant ORMGET_TOKENBASE("Get User Asset Usage")
// QVariant ORMGET_API("Get User Asset Usage")
QVariant REST_GET(
,
(
APICALLBOOM_TYPE_JWT_USER_DECL &APICALLBOOM_PARAM,
QString _apiToken,
TAPI::PKsByPath_t _pksByPath = {},
quint64 _pageIndex = 0,
quint16 _pageSize = 20,
TAPI::Cols_t _cols = {},
TAPI::Filter_t _filters = {},
TAPI::OrderBy_t _orderBy = {},
TAPI::GroupBy_t _groupBy = {},
bool _reportCount = true
),
"Get User Asset Usage"
);
};

/******************************************************/
Expand Down
5 changes: 2 additions & 3 deletions Interfaces/AAA/intfAccountingBasedModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ baseintfAccountingBasedModule::baseintfAccountingBasedModule(
) :
intfSQLBasedModule(_module, _schema),
ServiceName(_schema),
// IsTokenBase(_isTokenBase),
AccountUnits(_units),
AccountProducts(_products),
AccountSaleables(_saleables),
Expand Down Expand Up @@ -209,8 +208,8 @@ void baseintfAccountingBasedModule::checkUsageIsAllowed(
return;

for (auto UsageIter = _requestedUsage.begin();
UsageIter != _requestedUsage.end();
UsageIter++
UsageIter != _requestedUsage.end();
UsageIter++
) {
if (ActiveCredit.Digested.Limits.contains(UsageIter.key()) == false)
continue;
Expand Down
38 changes: 24 additions & 14 deletions Interfaces/AAA/intfAccountingBasedModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ class baseintfAccountingBasedModule : 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
);

stuActiveCredit findBestMatchedCredit(quint64 _usrID, const ServiceUsage_t& _requestedUsage = {});

protected:
//-- used by addToBasket: ----------------------------------------
virtual void processItemForBasket(
INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM,
Expand Down Expand Up @@ -253,6 +253,17 @@ protected slots:
"Cancel voucher item"
)

public:
intfAccountUnits* accountUnits() { return this->AccountUnits.data(); }
intfAccountProducts* accountProducts() { return this->AccountProducts.data(); }
intfAccountSaleables* accountSaleables() { return this->AccountSaleables.data(); }
intfAccountSaleablesFiles* accountSaleablesFiles() { return this->AccountSaleablesFiles.data(); }
baseintfAccountUserAssets* accountUserAssets() { return this->AccountUserAssets.data(); }
intfAccountUserAssetsFiles* accountUserAssetsFiles() { return this->AccountUserAssetsFiles.data(); }
baseintfAccountAssetUsage* accountAssetUsages() { return this->AccountAssetUsages.data(); }
intfAccountCoupons* accountCoupons() { return this->AccountCoupons.data(); }
intfAccountPrizes* accountPrizes() { return this->AccountPrizes.data(); }

protected:
QString ServiceName;

Expand All @@ -276,19 +287,18 @@ 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
const QString &_module,
const QString &_schema,
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();

Expand Down
48 changes: 0 additions & 48 deletions ModuleHelpers/MT/Classes/clsDerivedHelperSubmodules.cpp

This file was deleted.

57 changes: 0 additions & 57 deletions ModuleHelpers/MT/Classes/clsDerivedHelperSubmodules.h

This file was deleted.

2 changes: 1 addition & 1 deletion ModuleHelpers/MT/Gateways/intfBaseNMTGateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ QVariantMap intfBaseNMTGateway::doTranslation(
return Result;
} else {
QJsonParseError JsonError;
QJsonDocument Doc = QJsonDocument::fromJson(CUrlResult.toUtf8(),& JsonError);
QJsonDocument Doc = QJsonDocument::fromJson(CUrlResult.toUtf8(), &JsonError);
if (JsonError.error != QJsonParseError::NoError) {
Result[RESULTItems::ERRNO] = enuTranslationError::JsonParseError;
Result[RESULTItems::MESSAGE] = "Unable to parse JSON: " + JsonError.errorString() + '"' + CUrlResult + '"';
Expand Down
Loading