Skip to content

Commit

Permalink
Merge pull request #193 from Targoman/check_base_ticket_owner
Browse files Browse the repository at this point in the history
Check base ticket owner
  • Loading branch information
kambizzandi authored Aug 13, 2022
2 parents 20945ae + 87c001f commit 2897ec0
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Interfaces/DBM/QueryBuilders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ class clsBaseQueryData : public QSharedData
}

if (this->Alias.length())
this->BaseQueryPreparedItems.From += " " + this->Alias;
this->BaseQueryPreparedItems.From += " AS " + this->Alias;
}

friend clsQueryJoinTraitData<itmplDerived>;
Expand Down Expand Up @@ -1424,7 +1424,7 @@ class clsQueryJoinTraitData : public QSharedData
j += " ";
j += ReferenceTable;
if (Join.Alias.size())
j += " " + Join.Alias;
j += " AS " + Join.Alias;
if (Join.JoinType != enuJoinType::CROSS) {
if (Join.On.isEmpty())
throw exHTTPInternalServerError("Condition part of relation not defined.");
Expand Down Expand Up @@ -1874,7 +1874,7 @@ itmplDerived& tmplQueryJoinTrait<itmplDerived>::inlineJoin(enuJoinType::Type _jo

clsTable* ForeignTable = clsTable::Registry[_foreignTable];

ORMSelectQuery Query = ForeignTable->makeSelectQuery(this->JoinTraitData->Owner->Data->APICALLBOOM_PARAM, _alias);
ORMSelectQuery Query = ForeignTable->makeSelectQuery(this->JoinTraitData->Owner->Data->APICALLBOOM_PARAM); //, _alias);

//no union, no where, no group by, no having
if (Query.isPure()) {
Expand Down
2 changes: 1 addition & 1 deletion Modules/MT/MT.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
include($$QBUILD_PATH/templates/projectConfigs.pri)

addSubdirs(moduleSrc, Dependencies)
#addSubdirs(functionalTest, Dependencies)
addSubdirs(functionalTest, Dependencies)

OTHER_FILES += \
migrations/db/* \
Expand Down
26 changes: 26 additions & 0 deletions Modules/MT/functionalTest/functionalTest.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
################################################################################
# QBuildSystem
#
# Copyright(c) 2021 by Targoman Intelligent Processing <http://tip.co.ir>
#
# Redistribution and use in source and binary forms are allowed under the
# terms of BSD License 2.0.
################################################################################
TEST_NAME = mtFunctionalTest

HEADERS += \
testMT.hpp

SOURCES += \
$$BASE_PROJECT_PATH/3rdParty/QtCurl/libsrc/QtCUrl.cpp \
main.cpp \

LIBS += -lcurl

BASE_TEST_PATH = $$BASE_PROJECT_PATH/Interfaces/Test
INCLUDEPATH += $$BASE_TEST_PATH
include($$BASE_TEST_PATH/Test.pri)

################################################################################
include($$QBUILD_PATH/templates/unitTestConfigs.pri)
LIBS -= -lTargomanAPI
77 changes: 77 additions & 0 deletions Modules/MT/functionalTest/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/******************************************************************************
# TargomanAPI: REST API for Targoman
#
# Copyright 2014-2020 by Targoman Intelligent Processing <http://tip.co.ir>
#
# TargomanAPI is free software: you can redistribute it and/or modify
# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# TargomanAPI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU AFFERO GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
# along with Targoman. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/**
* @author S. Mehran M. Ziabary <ziabary@targoman.com>
* @author Kambiz Zandi <kambizzandi@gmail.com>
*/

#include <QtTest>
#include "testBase.hpp"
#include "testMT.hpp"

TAPI_MARSHAL_TEST_VARIABLES

int main(int _argc, char *_argv[]) {
qDebug() << "--------------------------------------------------";
qDebug() << "-- test module: MT -------------------------------";
qDebug() << "--------------------------------------------------";

//---------------------
QString DBPrefix;
int progArgsCount = 0;
char **progArgs = findDBPrefixFromArguments(_argc, _argv, DBPrefix, progArgsCount);

//---------------------
QCoreApplication App(progArgsCount, progArgs);
App.setAttribute(Qt::AA_Use96Dpi, true);

clsDAC::addDBEngine(enuDBEngines::MySQL);
clsDAC::setConnectionString(QString("HOST=%1;PORT=%2;USER=%3;PASSWORD=%4;SCHEMA=%5%6")
.arg(TARGOMAN_M2STR(UNITTEST_DB_HOST))
.arg(TARGOMAN_M2STR(UNITTEST_DB_PORT))
.arg(TARGOMAN_M2STR(UNITTEST_DB_USER))
.arg(TARGOMAN_M2STR(UNITTEST_DB_PASSWORD))
.arg(DBPrefix)
.arg(TARGOMAN_M2STR(UNITTEST_DB_SCHEMA))
);

bool BreakOnFirstFail = true;
int FailedTests = 0;

try {
FailedTests += QTest::qExec(new testBase(DBPrefix), progArgsCount, progArgs);
if (BreakOnFirstFail && !FailedTests) FailedTests += QTest::qExec(new testMT(DBPrefix), progArgsCount, progArgs);
} catch (exTargomanBase &e) {
++FailedTests;
qDebug() << "*** EXCEPTION ***" << QString("error(%1):%2").arg(e.code()).arg(e.what());
} catch (std::exception &e) {
++FailedTests;
qDebug() << "*** EXCEPTION ***" << e.what();
}

if (FailedTests > 0) {
qDebug() << "total number of failed tests: " << FailedTests;
} else {
qDebug() << "all tests passed :)";
}

clsDAC::shutdown();

return FailedTests;
}
70 changes: 70 additions & 0 deletions Modules/MT/functionalTest/testMT.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/******************************************************************************
* TargomanAAA: Authentication, Authorization, Accounting framework *
* *
* Copyright 2014-2019 by Targoman Intelligent Processing <http://tip.co.ir> *
* *
* TargomanAAA is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* TargomanAAA is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License *
* along with Targoman. If not, see <http://www.gnu.org/licenses/>. *
* *
******************************************************************************/
/**
* @author S. Mehran M. Ziabary <ziabary@targoman.com>
* @author Kambiz Zandi <kambizzandi@gmail.com>
*/

#ifndef TEST_MT_HPP
#define TEST_MT_HPP

#include <QRandomGenerator>
#include "Interfaces/Test/testCommon.hpp"
#include "Interfaces/AAA/clsJWT.hpp"
#include <cstdlib>
#include <unistd.h>

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

#include "Interfaces/DBM/QueryBuilders.h"
using namespace Targoman::API::DBM;

#include "Interfaces/AAA/Accounting_Defs.hpp"
using namespace Targoman::API::AAA;

#include "Interfaces/Helpers/SecurityHelper.h"
using namespace Targoman::API::Helpers;

class testMT : public clsBaseTest
{
Q_OBJECT

public:
testMT(const QString &_dbPrefix) : clsBaseTest(_dbPrefix) { ; }

void cleanupUnitTestData() {
clsDAC DAC;
DAC.execQuery("", QString("UPDATE %1AAA.tblUser SET usrStatus='R' WHERE usrEmail IN(?,?)").arg(this->DBPrefix), { UT_UserEmail, UT_AdminUserEmail });
}

private slots:
void initTestCase() {
initUnitTestData(false);
}

void cleanupTestCase() {
gEncodedAdminJWT = "";
gEncodedJWT = "";
cleanupUnitTestData();
}

};

#endif // TEST_MT_HPP
10 changes: 9 additions & 1 deletion Modules/Ticketing/moduleSrc/ORM/Tickets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,17 @@ QVariant Tickets::apiGET(
.orCond(
clsCondition({ tblTickets::Fields::tktTarget_usrID, enuConditionOperator::Null })
.andCond({ tblTickets::Fields::tktType, enuConditionOperator::Equal, enuTicketType::Broadcast })
);
)
.orCond(
clsCondition({ "Base", tblTickets::Fields::tktTarget_usrID, enuConditionOperator::Equal, CurrentUserID })
.orCond({ "Base", tblTickets::Fields::tktCreatedBy_usrID, enuConditionOperator::Equal, CurrentUserID })
)
;

auto fnTouchQuery = [this, &APICALLBOOM_PARAM, &_baseTicketID, &_inReplyTicketID, &CurrentUserID](ORMSelectQuery &_query) {
if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false)
_query.leftJoinWith(tblTickets::Relation::Base, "Base");

_query
.addCols(this->selectableColumnNames())
.leftJoin(tblUnits::Name)
Expand Down
15 changes: 11 additions & 4 deletions Modules/Ticketing/moduleSrc/ORM/Tickets.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ namespace tblTickets {
}

namespace Relation {
constexpr char Base[] = "Base";
constexpr char InReply[] = "InReply";
constexpr char TicketRead[] = "TicketRead";
}

Expand All @@ -109,12 +111,17 @@ namespace tblTickets {

const QList<stuRelation> Relations = {
//Col Reference Table ForeignCol Rename LeftJoin
{ Fields::tktInReply_tktID, R(TicketingSchema, tblTickets::Name), Fields::tktID, "InReply_", true },
{ Relation::Base, {
Fields::tktBase_tktID, R(TicketingSchema, tblTickets::Name), Fields::tktID, "Base_", true }
},
{ Relation::InReply, {
Fields::tktInReply_tktID, R(TicketingSchema, tblTickets::Name), Fields::tktID, "InReply_", true }
},
{ Fields::tktTarget_usrID, R(AAASchema, tblUser::Name), tblUser::Fields::usrID, "Target_", true },
{ Fields::tktID, R(TicketingSchema, tblTicketRead::Name), tblTicketRead::Fields::tkr_tktID, "ReadInfo_", true },
{ Fields::tkt_untID, R(TicketingSchema, tblUnits::Name), tblUnits::Fields::untID },
{ Relation::TicketRead,
{ Fields::tktID, R(TicketingSchema, tblTicketRead::Name), tblTicketRead::Fields::tkr_tktID } },
{ Relation::TicketRead, {
Fields::tktID, R(TicketingSchema, tblTicketRead::Name), tblTicketRead::Fields::tkr_tktID } // "ReadInfo_", true }
},
ORM_RELATION_OF_CREATOR(Fields::tktCreatedBy_usrID),
ORM_RELATION_OF_UPDATER(Fields::tktUpdatedBy_usrID),
};
Expand Down

0 comments on commit 2897ec0

Please sign in to comment.