mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 03:28:49 -07:00
Support Mod/Admin Notes Section (#5361)
This commit is contained in:
parent
14807ba036
commit
1f58f7e93d
13 changed files with 175 additions and 3 deletions
|
|
@ -11,6 +11,7 @@
|
|||
#include "pb/commands.pb.h"
|
||||
#include "pb/moderator_commands.pb.h"
|
||||
#include "pb/response_ban_history.pb.h"
|
||||
#include "pb/response_get_admin_notes.pb.h"
|
||||
#include "pb/response_get_games_of_user.pb.h"
|
||||
#include "pb/response_get_user_info.pb.h"
|
||||
#include "pb/response_warn_history.pb.h"
|
||||
|
|
@ -47,6 +48,7 @@ UserContextMenu::UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *parent,
|
|||
aDemoteFromMod = new QAction(QString(), this);
|
||||
aPromoteToJudge = new QAction(QString(), this);
|
||||
aDemoteFromJudge = new QAction(QString(), this);
|
||||
aGetAdminNotes = new QAction(QString(), this);
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
|
@ -69,6 +71,7 @@ void UserContextMenu::retranslateUi()
|
|||
aDemoteFromMod->setText(tr("Dem&ote user from moderator"));
|
||||
aPromoteToJudge->setText(tr("Promote user to &judge"));
|
||||
aDemoteFromJudge->setText(tr("Demote user from judge"));
|
||||
aGetAdminNotes->setText(tr("View admin notes"));
|
||||
}
|
||||
|
||||
void UserContextMenu::gamesOfUserReceived(const Response &resp, const CommandContainer &commandContainer)
|
||||
|
|
@ -221,6 +224,21 @@ void UserContextMenu::warnUserHistory_processResponse(const Response &resp)
|
|||
tr("Failed to collect warning information."));
|
||||
}
|
||||
|
||||
void UserContextMenu::getAdminNotes_processResponse(const Response &resp)
|
||||
{
|
||||
const Response_GetAdminNotes &response = resp.GetExtension(Response_GetAdminNotes::ext);
|
||||
|
||||
if (resp.response_code() != Response::RespOk) {
|
||||
QMessageBox::information(static_cast<QWidget *>(parent()), tr("Failed"), tr("Failed to get admin notes."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto *dlg = new AdminNotesDialog(QString::fromStdString(response.user_name()),
|
||||
QString::fromStdString(response.notes()), static_cast<QWidget *>(parent()));
|
||||
connect(dlg, &AdminNotesDialog::accepted, this, &UserContextMenu::updateAdminNotes_dialogFinished);
|
||||
dlg->show();
|
||||
}
|
||||
|
||||
void UserContextMenu::adjustMod_processUserResponse(const Response &resp, const CommandContainer &commandContainer)
|
||||
{
|
||||
|
||||
|
|
@ -281,6 +299,17 @@ void UserContextMenu::warnUser_dialogFinished()
|
|||
client->sendCommand(client->prepareModeratorCommand(cmd));
|
||||
}
|
||||
|
||||
void UserContextMenu::updateAdminNotes_dialogFinished()
|
||||
{
|
||||
auto *dlg = static_cast<AdminNotesDialog *>(sender());
|
||||
|
||||
Command_UpdateAdminNotes cmd;
|
||||
cmd.set_user_name(dlg->getName().toStdString());
|
||||
cmd.set_notes(dlg->getNotes().toStdString());
|
||||
|
||||
client->sendCommand(client->prepareModeratorCommand(cmd));
|
||||
}
|
||||
|
||||
void UserContextMenu::showContextMenu(const QPoint &pos,
|
||||
const QString &userName,
|
||||
UserLevelFlags userLevel,
|
||||
|
|
@ -347,6 +376,8 @@ void UserContextMenu::showContextMenu(const QPoint &pos,
|
|||
menu->addSeparator();
|
||||
menu->addAction(aBan);
|
||||
menu->addAction(aBanHistory);
|
||||
menu->addSeparator();
|
||||
menu->addAction(aGetAdminNotes);
|
||||
|
||||
menu->addSeparator();
|
||||
if (userLevel.testFlag(ServerInfo_User::IsModerator) &&
|
||||
|
|
@ -380,6 +411,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos,
|
|||
aWarnHistory->setEnabled(anotherUser);
|
||||
aBan->setEnabled(anotherUser);
|
||||
aBanHistory->setEnabled(anotherUser);
|
||||
aGetAdminNotes->setEnabled(anotherUser);
|
||||
aPromoteToMod->setEnabled(anotherUser);
|
||||
aDemoteFromMod->setEnabled(anotherUser);
|
||||
|
||||
|
|
@ -478,6 +510,14 @@ void UserContextMenu::showContextMenu(const QPoint &pos,
|
|||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
||||
SLOT(warnUserHistory_processResponse(Response)));
|
||||
client->sendCommand(pend);
|
||||
} else if (actionClicked == aGetAdminNotes) {
|
||||
Command_GetAdminNotes cmd;
|
||||
cmd.set_user_name(userName.toStdString());
|
||||
auto *pend = client->prepareModeratorCommand(cmd);
|
||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
||||
SLOT(getAdminNotes_processResponse(Response)));
|
||||
client->sendCommand(pend);
|
||||
|
||||
} else if (actionClicked == aCopyToClipBoard) {
|
||||
QClipboard *clipboard = QGuiApplication::clipboard();
|
||||
clipboard->setText(deckHash);
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ private:
|
|||
QAction *aPromoteToMod, *aDemoteFromMod;
|
||||
QAction *aPromoteToJudge, *aDemoteFromJudge;
|
||||
QAction *aWarnUser, *aWarnHistory;
|
||||
QAction *aGetAdminNotes;
|
||||
signals:
|
||||
void openMessageDialog(const QString &userName, bool focus);
|
||||
private slots:
|
||||
|
|
@ -43,9 +44,11 @@ private slots:
|
|||
void warnUser_processUserInfoResponse(const Response &resp);
|
||||
void banUserHistory_processResponse(const Response &resp);
|
||||
void warnUserHistory_processResponse(const Response &resp);
|
||||
void getAdminNotes_processResponse(const Response &resp);
|
||||
void adjustMod_processUserResponse(const Response &resp, const CommandContainer &commandContainer);
|
||||
void banUser_dialogFinished();
|
||||
void warnUser_dialogFinished();
|
||||
void updateAdminNotes_dialogFinished();
|
||||
void gamesOfUserReceived(const Response &resp, const CommandContainer &commandContainer);
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -284,6 +284,32 @@ int BanDialog::getDeleteMessages() const
|
|||
return deleteMessages->isChecked() ? -1 : 0;
|
||||
}
|
||||
|
||||
AdminNotesDialog::AdminNotesDialog(const QString &_userName, const QString &_notes, QWidget *_parent)
|
||||
: QDialog(_parent), userName(_userName)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
auto *updateButton = new QPushButton(tr("Update Notes"));
|
||||
updateButton->setEnabled(false);
|
||||
connect(updateButton, &QPushButton::clicked, this, &AdminNotesDialog::accept);
|
||||
|
||||
notes = new QPlainTextEdit(_notes);
|
||||
notes->setMinimumWidth(500);
|
||||
connect(notes, &QPlainTextEdit::textChanged, this, [=]() { updateButton->setEnabled(true); });
|
||||
|
||||
auto *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(notes);
|
||||
vbox->addWidget(updateButton);
|
||||
|
||||
setLayout(vbox);
|
||||
setWindowTitle(tr("Admin Notes for %1").arg(_userName));
|
||||
}
|
||||
|
||||
QString AdminNotesDialog::getNotes() const
|
||||
{
|
||||
return notes->toPlainText();
|
||||
}
|
||||
|
||||
UserListItemDelegate::UserListItemDelegate(QObject *const parent) : QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <QDialog>
|
||||
#include <QGroupBox>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QTextEdit>
|
||||
#include <QTreeWidgetItem>
|
||||
|
||||
class QTreeWidget;
|
||||
|
|
@ -69,6 +70,23 @@ public:
|
|||
void addWarningOption(const QString warning);
|
||||
};
|
||||
|
||||
class AdminNotesDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QString userName;
|
||||
QPlainTextEdit *notes;
|
||||
|
||||
public:
|
||||
explicit AdminNotesDialog(const QString &_userName, const QString &_notes, QWidget *_parent = nullptr);
|
||||
QString getName() const
|
||||
{
|
||||
return userName;
|
||||
}
|
||||
QString getNotes() const;
|
||||
};
|
||||
|
||||
class UserListItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue