Apply suggestion
* Put QSettings check in helper function * Removed stray QDebug() * Fixed wording on command message. *Update commandhelp
This commit is contained in:
parent
75472c6fad
commit
16955e9c16
@ -70,14 +70,14 @@
|
||||
"text":"Lists the permission of a given user. When called with an argument it shows the user's permission."
|
||||
},
|
||||
{
|
||||
"name":"addperm",
|
||||
"usage":"/addperm <Username> <Permission>",
|
||||
"text":"Adds permissions to a given user."
|
||||
"name":"setperm",
|
||||
"usage":"/addperm <Username> <Role>",
|
||||
"text":"Sets the role of the user.."
|
||||
},
|
||||
{
|
||||
"name":"removeperm",
|
||||
"usage":"/removeperm <Username> <Permission>",
|
||||
"text":"Removes permissions from a given user."
|
||||
"text":"Removes the role from a given user."
|
||||
},
|
||||
{
|
||||
"name":"listusers",
|
||||
|
@ -100,6 +100,8 @@ class ACLRole
|
||||
};
|
||||
Q_DECLARE_METATYPE(ACLRole::Permission)
|
||||
|
||||
class QSettings;
|
||||
|
||||
class ACLRolesHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -196,6 +198,13 @@ class ACLRolesHandler : public QObject
|
||||
*/
|
||||
bool saveFile(QString f_filename);
|
||||
|
||||
/**
|
||||
* @brief Checks if the ini file is accessible and well-formated
|
||||
* @param Pointer to the QSettings object to verify.
|
||||
* @return True if okay., false otherwise.
|
||||
*/
|
||||
bool checkPermissionsIni(QSettings *f_settings);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Shared read-only standard roles with the appropriate permissions.
|
||||
|
@ -806,16 +806,16 @@ class AOClient : public QObject
|
||||
void cmdListPerms(int argc, QStringList argv);
|
||||
|
||||
/**
|
||||
* @brief Adds permissions to a given user.
|
||||
* @brief Sets the role of the user.
|
||||
*
|
||||
* @details The first argument is the **target user**, the second is the **permission** (in string form) to add to that user.
|
||||
* @details The first argument is the **target user**, the second is the **role** (in string form) to set to that user.
|
||||
*
|
||||
* @iscommand
|
||||
*/
|
||||
void cmdSetPerms(int argc, QStringList argv);
|
||||
|
||||
/**
|
||||
* @brief Removes permissions from a given user.
|
||||
* @brief Removes the role from a given user.
|
||||
*
|
||||
* @details The first argument is the **target user**, the second is the **permission** (in string form) to remove from that user.
|
||||
*
|
||||
|
@ -177,24 +177,7 @@ bool ACLRolesHandler::loadFile(QString f_file_name)
|
||||
{
|
||||
QSettings l_settings(f_file_name, QSettings::IniFormat);
|
||||
l_settings.setIniCodec("UTF-8");
|
||||
if (l_settings.status() != QSettings::NoError) {
|
||||
switch (l_settings.status()) {
|
||||
case QSettings::AccessError:
|
||||
qWarning() << "[ACL Role Handler]"
|
||||
<< "error: failed to open file; aborting (" << f_file_name << ")";
|
||||
break;
|
||||
|
||||
case QSettings::FormatError:
|
||||
qWarning() << "[ACL Role Handler]"
|
||||
<< "error: file is malformed; aborting (" << f_file_name << ")";
|
||||
break;
|
||||
|
||||
default:
|
||||
qWarning() << "[ACL Role Handler]"
|
||||
<< "error: unknown error; aborting; aborting (" << f_file_name << ")";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!checkPermissionsIni(&l_settings)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -234,24 +217,7 @@ bool ACLRolesHandler::saveFile(QString f_file_name)
|
||||
{
|
||||
QSettings l_settings(f_file_name, QSettings::IniFormat);
|
||||
l_settings.setIniCodec("UTF-8");
|
||||
if (l_settings.status() != QSettings::NoError) {
|
||||
switch (l_settings.status()) {
|
||||
case QSettings::AccessError:
|
||||
qWarning() << "[ACL Role Handler]"
|
||||
<< "error: failed to open file; aborting (" << f_file_name << ")";
|
||||
break;
|
||||
|
||||
case QSettings::FormatError:
|
||||
qWarning() << "[ACL Role Handler]"
|
||||
<< "error: file is malformed; aborting (" << f_file_name << ")";
|
||||
break;
|
||||
|
||||
default:
|
||||
qWarning() << "[ACL Role Handler]"
|
||||
<< "error: unknown error; aborting; aborting (" << f_file_name << ")";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!checkPermissionsIni(&l_settings)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -288,3 +254,28 @@ bool ACLRolesHandler::saveFile(QString f_file_name)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ACLRolesHandler::checkPermissionsIni(QSettings *f_settings)
|
||||
{
|
||||
if (f_settings->status() != QSettings::NoError) {
|
||||
switch (f_settings->status()) {
|
||||
case QSettings::AccessError:
|
||||
qWarning() << "[ACL Role Handler]"
|
||||
<< "error: failed to open file; aborting (" << f_settings->fileName() << ")";
|
||||
break;
|
||||
|
||||
case QSettings::FormatError:
|
||||
qWarning() << "[ACL Role Handler]"
|
||||
<< "error: file is malformed; aborting (" << f_settings->fileName() << ")";
|
||||
break;
|
||||
|
||||
default:
|
||||
qWarning() << "[ACL Role Handler]"
|
||||
<< "error: unknown error; aborting; aborting (" << f_settings->fileName() << ")";
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ void AOClient::cmdSetPerms(int argc, QStringList argv)
|
||||
}
|
||||
|
||||
if (server->getDatabaseManager()->updateACL(l_target_username, l_target_acl)) {
|
||||
sendServerMessage("Successfully changed role " + l_target_acl + " to user " + l_target_username);
|
||||
sendServerMessage("Successfully applied role " + l_target_acl + " to user " + l_target_username);
|
||||
}
|
||||
else {
|
||||
sendServerMessage(l_target_username + " wasn't found!");
|
||||
|
@ -95,7 +95,6 @@ void NetworkSocket::readData()
|
||||
|
||||
for (const QString &l_single_packet : qAsConst(l_all_packets)) {
|
||||
AOPacket l_packet(l_single_packet);
|
||||
qDebug() << "Inbound Header:" << l_packet.getHeader();
|
||||
emit handlePacket(l_packet);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user