diff --git a/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.cpp b/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.cpp index de7edb9..466e8bd 100644 --- a/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.cpp +++ b/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.cpp @@ -592,6 +592,28 @@ void RecognizeSystem::xmlParser(QByteArray array) } + if(xmlReader.name() == "TryBlock") + { + bool result = false; + QString type = ""; + + foreach(const QXmlStreamAttribute &attr, xmlReader.attributes()) + { + QString name = attr.name().toString(); + QString value = attr.value().toString(); + + if (name == "Result"){ + result = value == "true" ? true : false; + } + + if (name == "Type"){ + type = value; + } + } + + emit sigTryBlock(result, type); + } + if(xmlReader.name() == "VersionList") { diff --git a/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.h b/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.h index 56f1c6f..d9b5b1b 100644 --- a/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.h +++ b/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.h @@ -37,6 +37,7 @@ signals: void sigErrorAuth(QString error); void sigAuth(ServerAuthorization *serverAuth); void sigDeAuth(ServerDeAuthorization *serverDeAuth); + void sigTryBlock(bool result, QString type); void sigAnswerQueryToDB(QList* listInstructors, QList* listTrainees, QList* listGroups); diff --git a/LibInstructorsAndTrainees/connectorToServer/connectortoserver.cpp b/LibInstructorsAndTrainees/connectorToServer/connectortoserver.cpp index dec6cfa..7208aa4 100644 --- a/LibInstructorsAndTrainees/connectorToServer/connectortoserver.cpp +++ b/LibInstructorsAndTrainees/connectorToServer/connectortoserver.cpp @@ -150,6 +150,8 @@ void ConnectorToServer::bindConnection() connect(recognizeSystem,&RecognizeSystem::sigAuth,this,&ConnectorToServer::slot_Auth); connect(recognizeSystem,&RecognizeSystem::sigDeAuth,this,&ConnectorToServer::sigDeLoginResult); + connect(recognizeSystem,&RecognizeSystem::sigTryBlock,this,&ConnectorToServer::sigTryBlockResult); + connect(recognizeSystem,&RecognizeSystem::sigServerBlocked,this,&ConnectorToServer::slot_ServerBlocked); connect(recognizeSystem,&RecognizeSystem::sigErrorAuth,this,&ConnectorToServer::slot_ErrorAuth); diff --git a/LibInstructorsAndTrainees/connectorToServer/connectortoserver.h b/LibInstructorsAndTrainees/connectorToServer/connectortoserver.h index bbaa682..d884ec9 100644 --- a/LibInstructorsAndTrainees/connectorToServer/connectortoserver.h +++ b/LibInstructorsAndTrainees/connectorToServer/connectortoserver.h @@ -130,6 +130,9 @@ signals: void sigLoginResult(ServerAuthorization * serverAuth); void sigDeLoginResult(ServerDeAuthorization * serverDeAuth); + + void sigTryBlockResult(bool result, QString type); + void sigServerBlocked(); void sigErrorAuth(QString error); diff --git a/LibInstructorsAndTrainees/instructorsandtraineeswidget.cpp b/LibInstructorsAndTrainees/instructorsandtraineeswidget.cpp index 8f34e79..f472fff 100644 --- a/LibInstructorsAndTrainees/instructorsandtraineeswidget.cpp +++ b/LibInstructorsAndTrainees/instructorsandtraineeswidget.cpp @@ -51,6 +51,9 @@ InstructorsAndTraineesWidget::InstructorsAndTraineesWidget(QWidget *parent) : connectorToServer = new ConnectorToServer(); connect(connectorToServer, &ConnectorToServer::sigLoginResult, this, &InstructorsAndTraineesWidget::slot_checkLoginResult); connect(connectorToServer, &ConnectorToServer::sigDeLoginResult, this, &InstructorsAndTraineesWidget::slot_checkDeLoginResult); + + connect(connectorToServer, &ConnectorToServer::sigTryBlockResult, this, &InstructorsAndTraineesWidget::slot_checkTryBlockResult); + connect(connectorToServer, &ConnectorToServer::sigServerBlocked, this, &InstructorsAndTraineesWidget::slot_ServerBlocked); connect(connectorToServer, &ConnectorToServer::sigErrorAuth, this, &InstructorsAndTraineesWidget::slot_ErrorAuth); connect(connectorToServer, &ConnectorToServer::signal_SetVersion, this, &InstructorsAndTraineesWidget::slot_SetVersion); @@ -289,6 +292,11 @@ void InstructorsAndTraineesWidget::slot_checkDeLoginResult(ServerDeAuthorization } } +void InstructorsAndTraineesWidget::slot_checkTryBlockResult(bool result, QString type) +{ + +} + void InstructorsAndTraineesWidget::slot_ServerBlocked() { if(flTryLogin) @@ -695,6 +703,8 @@ void InstructorsAndTraineesWidget::on_btnSettings_clicked() connect(dlgSettings, &DialogSettings::signal_LanguageChanged, this, &InstructorsAndTraineesWidget::slot_LanguageChanged); connect(dlgSettings, &DialogSettings::signal_UpdateStyleSheet, this, &InstructorsAndTraineesWidget::slot_UpdateStyleSheet); + connect(connectorToServer, &ConnectorToServer::sigTryBlockResult, dlgSettings, &DialogSettings::slot_checkTryBlockResult); + switch( dlgSettings->exec() ) { case QDialog::Accepted: diff --git a/LibInstructorsAndTrainees/instructorsandtraineeswidget.h b/LibInstructorsAndTrainees/instructorsandtraineeswidget.h index 23d1bb4..40b2183 100644 --- a/LibInstructorsAndTrainees/instructorsandtraineeswidget.h +++ b/LibInstructorsAndTrainees/instructorsandtraineeswidget.h @@ -54,6 +54,8 @@ public Q_SLOTS: //Слот обработки результата деавторизации void slot_checkDeLoginResult(ServerDeAuthorization * serverDeAuth); + void slot_checkTryBlockResult(bool result, QString type); + void slot_ServerBlocked(); void slot_ErrorAuth(QString error); void slot_SetVersion(StreamingVersionData* serverVersion); diff --git a/LibInstructorsAndTrainees/settings/dialogsettings.cpp b/LibInstructorsAndTrainees/settings/dialogsettings.cpp index 2798cce..3600e3f 100644 --- a/LibInstructorsAndTrainees/settings/dialogsettings.cpp +++ b/LibInstructorsAndTrainees/settings/dialogsettings.cpp @@ -5,6 +5,7 @@ #include #include #include "dialogversioncontrol.h" +#include "specialmessagebox.h" DialogSettings::DialogSettings(ConnectorToServer* connectorToServer, bool instructorIsLogged, QWidget *parent) : QDialog(parent), @@ -12,7 +13,8 @@ DialogSettings::DialogSettings(ConnectorToServer* connectorToServer, bool instru settings(nullptr), connectorToServer(nullptr), dlgVersionControl(nullptr), - flSettingsServerChanged(false) + flSettingsServerChanged(false), + flTryVersionControl(false) { ui->setupUi(this); @@ -214,19 +216,12 @@ void DialogSettings::on_btnSetVersion_clicked() if(connectorToServer) if(connectorToServer->getIsConnected()) { + flTryVersionControl = true; + connectorToServer->sendQueryBlockAuth(true, "VersionControl"); - dlgVersionControl = new DialogVersionControl(connectorToServer, this); - dlgVersionControl->initialize(connectorToServer->getLoginName()); - dlgVersionControl->exec(); - - if(dlgVersionControl) - { - delete dlgVersionControl; - dlgVersionControl = nullptr; - } - - connectorToServer->sendQueryBlockAuth(false, "VersionControl"); + //TODO пока сразу + //slot_VersionControl(); } } @@ -258,3 +253,38 @@ void DialogSettings::on_DialogSettings_accepted() emit signal_LanguageChanged(language); } + +void DialogSettings::slot_VersionControl() +{ + dlgVersionControl = new DialogVersionControl(connectorToServer, this); + dlgVersionControl->initialize(connectorToServer->getLoginName()); + dlgVersionControl->exec(); + + if(dlgVersionControl) + { + delete dlgVersionControl; + dlgVersionControl = nullptr; + } + + connectorToServer->sendQueryBlockAuth(false, "VersionControl"); +} + +void DialogSettings::slot_checkTryBlockResult(bool result, QString type) +{ + if(flTryVersionControl) + { + if(type == "VersionControl") + { + if(result) + {//Одобрено + slot_VersionControl(); + } + else + {//Отказ + SpecMsgBox::WarningClose(this, tr("The server rejected your request to access version control.\nAnother instructor is managing versions.\nPlease try again later.")); + } + + flTryVersionControl = false; + } + } +} diff --git a/LibInstructorsAndTrainees/settings/dialogsettings.h b/LibInstructorsAndTrainees/settings/dialogsettings.h index 0712cab..3577d26 100644 --- a/LibInstructorsAndTrainees/settings/dialogsettings.h +++ b/LibInstructorsAndTrainees/settings/dialogsettings.h @@ -46,6 +46,11 @@ private slots: void on_editPort_textChanged(const QString &arg1); void on_DialogSettings_accepted(); +public slots: + void slot_VersionControl(); + + void slot_checkTryBlockResult(bool result, QString type); + private: bool saveSettings(); @@ -59,6 +64,8 @@ private: DialogVersionControl *dlgVersionControl; bool flSettingsServerChanged; + + bool flTryVersionControl; }; #endif // DIALOGSETTINGS_H diff --git a/LibServer/Systems/Parsers/clientanswerparser.cpp b/LibServer/Systems/Parsers/clientanswerparser.cpp index e1ce8b3..cae3427 100644 --- a/LibServer/Systems/Parsers/clientanswerparser.cpp +++ b/LibServer/Systems/Parsers/clientanswerparser.cpp @@ -43,6 +43,20 @@ QByteArray ClientAnswerParser::deAuthorization(bool result, QString login) return dataParser->xmlAnswer(listTag); } +QByteArray ClientAnswerParser::tryBlock(bool result, QString type) +{ + QList listTag; + + SAttribute attribute1 = {"Result", result? "true" : "false"}; + SAttribute attribute2 = {"Type", type}; + QList listAttr = {attribute1, attribute2}; + SXmlAnswerTag tag = {"TryBlock", listAttr}; + + listTag.append(tag); + + return dataParser->xmlAnswer(listTag); +} + QByteArray ClientAnswerParser::message(QString loginFrom,QString loginTo,QString text) { QList listTag; diff --git a/LibServer/Systems/Parsers/clientanswerparser.h b/LibServer/Systems/Parsers/clientanswerparser.h index 423b4e5..81ed702 100644 --- a/LibServer/Systems/Parsers/clientanswerparser.h +++ b/LibServer/Systems/Parsers/clientanswerparser.h @@ -16,6 +16,7 @@ public: QByteArray authorization(bool result, QString instructorName, QString clientName, QString accessType, QString login, int id); QByteArray deAuthorization(bool result, QString login); + QByteArray tryBlock(bool result, QString type); QByteArray message(QString loginFrom,QString loginTo,QString text); QByteArray task(QString text); QByteArray notify(QString code); diff --git a/LibServer/Systems/processingsystem.cpp b/LibServer/Systems/processingsystem.cpp index 7474693..c6c1d2a 100644 --- a/LibServer/Systems/processingsystem.cpp +++ b/LibServer/Systems/processingsystem.cpp @@ -188,7 +188,19 @@ void ProcessingSystem::processingClientDeAutorization(ClientHandler *client, Cli void ProcessingSystem::processingClientBlockAuth(ClientHandler *client, bool block, QString type) { + QByteArray arrayAnswer; + bool res = emit providerDBLMS->signal_BlockAutorization(block, client->getClient()->getFullName(), type); + + if(res) + {//Блокировка одобрена + arrayAnswer = dataParser->ClientAnswer()->tryBlock(true, type); + } + else + {//Отказ + arrayAnswer = dataParser->ClientAnswer()->tryBlock(false, type); + } + client->sendXmlAnswer(arrayAnswer); } //упращенная деавторизация при выключении сервера diff --git a/LibServer/multithreadserver/multithreadserver.cpp b/LibServer/multithreadserver/multithreadserver.cpp index 00f1088..5c440af 100644 --- a/LibServer/multithreadserver/multithreadserver.cpp +++ b/LibServer/multithreadserver/multithreadserver.cpp @@ -149,16 +149,50 @@ void MultiThreadServer::slotDisconnectClient(QString peerAddress, QString peerPo bool MultiThreadServer::slot_BlockAutorization(bool block, QString whoFullName, QString type) { - bool res = true; + bool res = false; bool blockRes = false; QString key = whoFullName + " [type:" + type + "]"; QString strTypes = ""; if(block) { - this->blockAutorization(); - blockersMap.insert(key, type); - blockRes = true; + if(whoFullName == "SERVER") + { + this->blockAutorization(); + blockersMap.insert(key, type); + blockRes = true; + res = true; + } + else + { + bool flExist = false; + + foreach(QString keyLocal, blockersMap.keys()) + { + if(blockersMap[keyLocal] == type) + { + flExist = true; + break; + } + } + + if(!flExist) + { + this->blockAutorization(); + blockersMap.insert(key, type); + blockRes = true; + res = true; + } + else + { + if(!blockersMap.count()) + blockRes = false; + else + blockRes = true; + + res = false; + } + } } else { @@ -170,6 +204,8 @@ bool MultiThreadServer::slot_BlockAutorization(bool block, QString whoFullName, } else blockRes = true; + + res = true; } if(res)