mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[Server/Client/Protocol] Let moderators clear banner cards (#7546)
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
b4e24f958a
commit
93309e01a2
12 changed files with 366 additions and 14 deletions
|
|
@ -18,6 +18,7 @@
|
|||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QList>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QSharedPointer>
|
||||
#include <QTableView>
|
||||
|
|
@ -29,7 +30,9 @@
|
|||
#include <libcockatrice/network/client/abstract/abstract_client.h>
|
||||
#include <libcockatrice/protocol/pb/moderator_commands.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_card_art_rule_entry.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_clear_blacklisted_banners.pb.h>
|
||||
#include <libcockatrice/protocol/pending_command.h>
|
||||
#include <libcockatrice/utility/qt_utils.h>
|
||||
#include <string>
|
||||
|
||||
class QObject;
|
||||
|
|
@ -172,6 +175,7 @@ void TabCardArtRules::setupUi()
|
|||
addBtn = new QPushButton;
|
||||
removeBtn = new QPushButton;
|
||||
refreshBtn = new QPushButton;
|
||||
clearBannedArtBtn = new QPushButton;
|
||||
|
||||
modeBox->addItems({"ALLOW", "DENY"});
|
||||
|
||||
|
|
@ -188,10 +192,14 @@ void TabCardArtRules::setupUi()
|
|||
form->addRow(tr("Mode:"), modeBox);
|
||||
form->addRow(tr("Reason:"), reasonEdit);
|
||||
|
||||
// The bulk clear acts on every user, so keep it visibly apart from the
|
||||
// rules this tab edits.
|
||||
auto *buttons = new QHBoxLayout;
|
||||
buttons->addWidget(addBtn);
|
||||
buttons->addWidget(removeBtn);
|
||||
buttons->addWidget(refreshBtn);
|
||||
buttons->addStretch();
|
||||
buttons->addWidget(clearBannedArtBtn);
|
||||
|
||||
auto *layout = new QVBoxLayout;
|
||||
layout->addLayout(form);
|
||||
|
|
@ -207,6 +215,8 @@ void TabCardArtRules::setupUi()
|
|||
|
||||
connect(refreshBtn, &QPushButton::clicked, this, &TabCardArtRules::refresh);
|
||||
|
||||
connect(clearBannedArtBtn, &QPushButton::clicked, this, &TabCardArtRules::clearBlacklistedBanners);
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
|
|
@ -263,6 +273,7 @@ void TabCardArtRules::retranslateUi()
|
|||
addBtn->setText(tr("Add rule"));
|
||||
removeBtn->setText(tr("Remove rule"));
|
||||
refreshBtn->setText(tr("Refresh"));
|
||||
clearBannedArtBtn->setText(tr("Clear blacklisted banners"));
|
||||
}
|
||||
|
||||
void TabCardArtRules::refresh()
|
||||
|
|
@ -299,4 +310,47 @@ void TabCardArtRules::removeSelected()
|
|||
client->sendCommand(client->prepareModeratorCommand(cmd));
|
||||
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void TabCardArtRules::clearBlacklistedBanners()
|
||||
{
|
||||
if (!QtUtils::confirm(this, tr("Clear blacklisted banners"),
|
||||
tr("Remove the banner card from every user whose current banner matches a DENY rule?\n\n"
|
||||
"Users who are online keep showing their banner until they log in again."),
|
||||
QMessageBox::No)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Command_ClearBlacklistedBanners cmd;
|
||||
PendingCommand *pend = client->prepareModeratorCommand(cmd);
|
||||
connect(pend, &PendingCommand::finished, this, &TabCardArtRules::clearBlacklistedBannersResponse);
|
||||
client->sendCommand(pend);
|
||||
}
|
||||
|
||||
void TabCardArtRules::clearBlacklistedBannersResponse(const Response &r)
|
||||
{
|
||||
switch (r.response_code()) {
|
||||
case Response::RespOk:
|
||||
break;
|
||||
case Response::RespFunctionNotAllowed:
|
||||
QMessageBox::warning(this, tr("Not supported"),
|
||||
tr("This server does not support clearing blacklisted banners. It may be running an "
|
||||
"older version."));
|
||||
return;
|
||||
case Response::RespInternalError:
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("The server could not clear blacklisted banners because of a database error."));
|
||||
return;
|
||||
default:
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("The server rejected the request: %1")
|
||||
.arg(QString::fromStdString(Response_ResponseCode_Name(r.response_code()))));
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &resp = r.GetExtension(Response_ClearBlacklistedBanners::ext);
|
||||
QMessageBox::information(this, tr("Banners cleared"),
|
||||
tr("%n banner card(s) cleared.\n\n"
|
||||
"Users who are online keep showing their banner until they log in again.",
|
||||
"number of banners cleared", resp.cleared_count()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,6 +78,8 @@ private slots:
|
|||
void addRule();
|
||||
void removeSelected();
|
||||
void refresh();
|
||||
void clearBlacklistedBanners();
|
||||
void clearBlacklistedBannersResponse(const Response &r);
|
||||
|
||||
private:
|
||||
AbstractClient *client;
|
||||
|
|
@ -97,6 +99,7 @@ private:
|
|||
QPushButton *addBtn;
|
||||
QPushButton *removeBtn;
|
||||
QPushButton *refreshBtn;
|
||||
QPushButton *clearBannedArtBtn;
|
||||
|
||||
QTableView *table;
|
||||
CardArtRulesModel *tableModel;
|
||||
|
|
|
|||
|
|
@ -30,12 +30,14 @@
|
|||
#include <libcockatrice/protocol/pb/moderator_commands.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_moderator_last_logins.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_remove_user_avatar.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_remove_user_banner.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_report_user_info.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_reset_user_password.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_user_alts.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_user_sessions.pb.h>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
|
||||
#include <libcockatrice/protocol/pending_command.h>
|
||||
#include <libcockatrice/utility/qt_utils.h>
|
||||
#include <qnamespace.h>
|
||||
#include <string>
|
||||
|
||||
|
|
@ -85,12 +87,16 @@ TabModeration::TabModeration(TabSupervisor *_tabSupervisor, AbstractClient *_cli
|
|||
removeAvatarButton = new QPushButton;
|
||||
connect(removeAvatarButton, &QPushButton::clicked, this, &TabModeration::removeAvatar);
|
||||
|
||||
removeBannerButton = new QPushButton;
|
||||
connect(removeBannerButton, &QPushButton::clicked, this, &TabModeration::removeBanner);
|
||||
|
||||
auto *topBar = new QHBoxLayout;
|
||||
topBar->addWidget(searchEdit);
|
||||
topBar->addWidget(investigateButton);
|
||||
topBar->addStretch();
|
||||
topBar->addWidget(resetPasswordButton);
|
||||
topBar->addWidget(removeAvatarButton);
|
||||
topBar->addWidget(removeBannerButton);
|
||||
|
||||
userInfoGroup = new QGroupBox;
|
||||
userInfoNameLabel = new QLabel;
|
||||
|
|
@ -186,6 +192,7 @@ void TabModeration::retranslateUi()
|
|||
investigateButton->setText(tr("Investigate"));
|
||||
resetPasswordButton->setText(tr("Reset Password"));
|
||||
removeAvatarButton->setText(tr("Remove Avatar"));
|
||||
removeBannerButton->setText(tr("Remove Banner"));
|
||||
refreshStaffButton->setText(tr("Refresh"));
|
||||
|
||||
userInfoGroup->setTitle(tr("User Info"));
|
||||
|
|
@ -227,6 +234,7 @@ void TabModeration::clearUserData()
|
|||
sessionsTable->setRowCount(0);
|
||||
resetPasswordButton->setEnabled(false);
|
||||
removeAvatarButton->setEnabled(false);
|
||||
removeBannerButton->setEnabled(false);
|
||||
}
|
||||
|
||||
void TabModeration::investigate(const QString &userName)
|
||||
|
|
@ -247,6 +255,7 @@ void TabModeration::investigateUser()
|
|||
currentUser = userName;
|
||||
resetPasswordButton->setEnabled(true);
|
||||
removeAvatarButton->setEnabled(true);
|
||||
removeBannerButton->setEnabled(true);
|
||||
altsTable->setRowCount(0);
|
||||
sessionsTable->setRowCount(0);
|
||||
requestUserInfo(userName);
|
||||
|
|
@ -414,13 +423,11 @@ void TabModeration::resetPassword()
|
|||
return;
|
||||
}
|
||||
|
||||
QMessageBox::StandardButton choice =
|
||||
QMessageBox::warning(this, tr("Reset Password"),
|
||||
tr("Reset the password of %1? A temporary password will be generated and shown to you. "
|
||||
"The user must change it on their first login.")
|
||||
.arg(currentUser),
|
||||
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel);
|
||||
if (choice != QMessageBox::Ok) {
|
||||
if (!QtUtils::confirm(this, tr("Reset Password"),
|
||||
tr("Reset the password of %1? A temporary password will be generated and shown to you. "
|
||||
"The user must change it on their first login.")
|
||||
.arg(currentUser),
|
||||
QMessageBox::No)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -451,11 +458,9 @@ void TabModeration::removeAvatar()
|
|||
return;
|
||||
}
|
||||
|
||||
QMessageBox::StandardButton choice =
|
||||
QMessageBox::warning(this, tr("Remove Avatar"),
|
||||
tr("Remove the avatar of %1? The user will have to upload a new one.").arg(currentUser),
|
||||
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel);
|
||||
if (choice != QMessageBox::Ok) {
|
||||
if (!QtUtils::confirm(this, tr("Remove Avatar"),
|
||||
tr("Remove the avatar of %1? The user will have to upload a new one.").arg(currentUser),
|
||||
QMessageBox::No)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -477,3 +482,67 @@ void TabModeration::removeAvatarResponse(const Response &response)
|
|||
QMessageBox::information(this, tr("Avatar removed"),
|
||||
tr("The avatar of %1 has been removed.").arg(QString::fromStdString(resp.user_name())));
|
||||
}
|
||||
|
||||
void TabModeration::removeBanner()
|
||||
{
|
||||
if (currentUser.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!QtUtils::confirm(this, tr("Remove Banner"),
|
||||
tr("Remove the banner card of %1? The user will have to choose a new one.\n\n"
|
||||
"Other players stop seeing the banner the next time %1 logs in.")
|
||||
.arg(currentUser),
|
||||
QMessageBox::No)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Command_RemoveUserBanner cmd;
|
||||
cmd.set_user_name(currentUser.toStdString());
|
||||
PendingCommand *pend = client->prepareModeratorCommand(cmd);
|
||||
connect(pend, &PendingCommand::finished, this, &TabModeration::removeBannerResponse);
|
||||
client->sendCommand(pend);
|
||||
}
|
||||
|
||||
void TabModeration::removeBannerResponse(const Response &response)
|
||||
{
|
||||
const QString target = currentUser.isEmpty() ? tr("this user") : currentUser;
|
||||
|
||||
switch (response.response_code()) {
|
||||
case Response::RespOk:
|
||||
break;
|
||||
case Response::RespNameNotFound:
|
||||
QMessageBox::warning(this, tr("User not found"),
|
||||
tr("The server does not know a user named %1.").arg(target));
|
||||
return;
|
||||
case Response::RespFunctionNotAllowed:
|
||||
QMessageBox::warning(this, tr("Not supported"),
|
||||
tr("This server does not support removing banner cards. It may be running an older "
|
||||
"version."));
|
||||
return;
|
||||
case Response::RespInternalError:
|
||||
QMessageBox::critical(
|
||||
this, tr("Error"),
|
||||
tr("The server could not clear the banner card of %1 because of a database error.").arg(target));
|
||||
return;
|
||||
default:
|
||||
QMessageBox::critical(
|
||||
this, tr("Error"),
|
||||
tr("The server rejected the request for %1: %2")
|
||||
.arg(target, QString::fromStdString(Response_ResponseCode_Name(response.response_code()))));
|
||||
return;
|
||||
}
|
||||
|
||||
const Response_RemoveUserBanner &resp = response.GetExtension(Response_RemoveUserBanner::ext);
|
||||
const QString removedUser = resp.user_name().empty() ? target : QString::fromStdString(resp.user_name());
|
||||
if (!resp.had_banner()) {
|
||||
QMessageBox::information(this, tr("No banner set"),
|
||||
tr("%1 has no banner card set, so there was nothing to remove.").arg(removedUser));
|
||||
return;
|
||||
}
|
||||
|
||||
QMessageBox::information(this, tr("Banner removed"),
|
||||
tr("The banner card of %1 has been removed.\n\n"
|
||||
"Other players stop seeing it the next time %1 logs in.")
|
||||
.arg(removedUser));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class TabSupervisor;
|
|||
/**
|
||||
* Staff investigation tool. Lets moderators look up a user's account data,
|
||||
* alternate accounts, login sessions, and staff login activity, and offers
|
||||
* the password-reset and remove-avatar actions.
|
||||
* the password-reset, remove-avatar, and remove-banner actions.
|
||||
*/
|
||||
class TabModeration : public Tab
|
||||
{
|
||||
|
|
@ -44,6 +44,8 @@ private slots:
|
|||
void resetPasswordResponse(const Response &response);
|
||||
void removeAvatar();
|
||||
void removeAvatarResponse(const Response &response);
|
||||
void removeBanner();
|
||||
void removeBannerResponse(const Response &response);
|
||||
|
||||
private:
|
||||
void requestUserInfo(const QString &userName);
|
||||
|
|
@ -60,6 +62,7 @@ private:
|
|||
QPushButton *investigateButton;
|
||||
QPushButton *resetPasswordButton;
|
||||
QPushButton *removeAvatarButton;
|
||||
QPushButton *removeBannerButton;
|
||||
|
||||
QGroupBox *userInfoGroup;
|
||||
QLabel *userInfoNameLabel;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue