Address PR feedback

This commit is contained in:
Gavin Bisesi 2015-08-21 23:03:15 -04:00
parent 39fcabe921
commit 66f14c1168
2 changed files with 23 additions and 34 deletions

View file

@ -231,23 +231,13 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(banUser_processUserInfoResponse(Response)));
client->sendCommand(pend);
} else if (actionClicked == aPromoteToMod) {
} else if (actionClicked == aPromoteToMod || actionClicked == aDemoteFromMod) {
Command_AdjustMod cmd;
cmd.set_user_name(userName.toStdString());
cmd.set_should_be_mod(true);
cmd.set_should_be_mod(actionClicked == aPromoteToMod);
// client->sendCommand(client->prepareAdminCommand(cmd));
PendingCommand *pend = client->prepareAdminCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(adjustMod_processUserResponse(Response,CommandContainer)));
client->sendCommand(pend);
} else if (actionClicked == aDemoteFromMod) {
Command_AdjustMod cmd;
cmd.set_user_name(userName.toStdString());
cmd.set_should_be_mod(false);
// client->sendCommand(client->prepareAdminCommand(cmd));
PendingCommand *pend = client->prepareAdminCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(adjustMod_processUserResponse(Response,CommandContainer)));
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(adjustMod_processUserResponse(Response, CommandContainer)));
client->sendCommand(pend);
}

View file

@ -19,6 +19,7 @@
***************************************************************************/
#include <iostream>
#include <QSqlError>
#include <QSqlQuery>
#include <QHostAddress>
#include <QDebug>
@ -1008,47 +1009,45 @@ Response::ResponseCode ServerSocketInterface::cmdAdjustMod(const Command_AdjustM
QString userName = QString::fromStdString(cmd.user_name());
if (cmd.should_be_mod()) {
logDebugMessage("Received admin command: promote user");
QSqlQuery *query = sqlInterface->prepareQuery(
"update {prefix}_users set admin = :adminlevel where name = :username");
query->bindValue(":adminlevel", 2);
query->bindValue(":username", userName);
if (!sqlInterface->execSqlQuery(query))
if (!sqlInterface->execSqlQuery(query)){
logger->logMessage(QString::fromStdString("Failed to promote user %1: %2").arg(userName).arg(query->lastError().text()));
return Response::RespInternalError;
}
ServerSocketInterface *user = static_cast<ServerSocketInterface *>(server->getUsers().value(userName));
Event_NotifyUser event;
event.set_type(Event_NotifyUser::PROMOTED);
SessionEvent *se = user->prepareSessionEvent(event);
user->sendProtocolItem(*se);
delete se;
if (user) {
Event_NotifyUser event;
event.set_type(Event_NotifyUser::PROMOTED);
SessionEvent *se = user->prepareSessionEvent(event);
user->sendProtocolItem(*se);
delete se;
}
} else {
logDebugMessage("Received admin command: demote user");
QSqlQuery *query = sqlInterface->prepareQuery("update {prefix}_users set admin = :adminlevel where name = :username");
query->bindValue(":adminlevel", 0);
query->bindValue(":username", userName);
if (!sqlInterface->execSqlQuery(query))
if (!sqlInterface->execSqlQuery(query)){
logger->logMessage(QString::fromStdString("Failed to demote user %1: %2").arg(userName).arg(query->lastError().text()));
return Response::RespInternalError;
}
QList<ServerSocketInterface *> userList;
ServerSocketInterface *user = static_cast<ServerSocketInterface *>(server->getUsers().value(userName));
userList.append(user);
if (!userList.isEmpty()) {
if (user) {
Event_ConnectionClosed event;
event.set_reason(Event_ConnectionClosed::DEMOTED);
event.set_reason_str("Your moderator status has been revoked.");
event.set_end_time(QDateTime::currentDateTime().toTime_t());
for (int i = 0; i < userList.size(); ++i) {
SessionEvent *se = userList[i]->prepareSessionEvent(event);
userList[i]->sendProtocolItem(*se);
delete se;
QMetaObject::invokeMethod(userList[i], "prepareDestroy", Qt::QueuedConnection);
}
userList.clear();
SessionEvent *se = user->prepareSessionEvent(event);
user->sendProtocolItem(*se);
delete se;
}
QMetaObject::invokeMethod(user, "prepareDestroy", Qt::QueuedConnection);
}
return Response::RespOk;