mirror of
https://github.com/arcan1s/queued.git
synced 2025-07-16 15:19:56 +00:00
more actions, improve process manager, fix bugs with datetime in dbus response
This commit is contained in:
@ -55,6 +55,27 @@ QString QueuedctlCommon::commandsHelp()
|
||||
}
|
||||
|
||||
|
||||
QString QueuedctlCommon::hashHashToString(
|
||||
const QHash<QString, QHash<QString, QString>> &_hash)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Convert hash to string" << _hash;
|
||||
|
||||
QStringList output;
|
||||
|
||||
QStringList groups = _hash.keys();
|
||||
groups.sort();
|
||||
for (auto &group : groups) {
|
||||
output += group;
|
||||
QStringList keys = _hash[group].keys();
|
||||
keys.sort();
|
||||
for (auto &key : keys)
|
||||
output += QString("\t%1: %2").arg(key).arg(_hash[group][key]);
|
||||
}
|
||||
|
||||
return output.join('\n');
|
||||
}
|
||||
|
||||
|
||||
QString QueuedctlCommon::hashToString(const QVariantHash &_hash)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Convert hash to string" << _hash;
|
||||
@ -136,6 +157,8 @@ void QueuedctlCommon::preprocess(const QStringList &_args,
|
||||
case QueuedctlArgument::Report:
|
||||
QueuedctlUser::parserReport(_parser);
|
||||
break;
|
||||
case QueuedctlArgument::Status:
|
||||
break;
|
||||
case QueuedctlArgument::TaskAdd:
|
||||
QueuedctlTask::parserAdd(_parser);
|
||||
break;
|
||||
@ -223,7 +246,7 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::PermissionAdd: {
|
||||
auto userId = QueuedctlUser::getUserId(args.at(1));
|
||||
auto userId = QueuedCoreAdaptor::getUserId(args.at(1));
|
||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||
result.status
|
||||
= QueuedctlPermissions::addPermission(userId, args.at(2), token);
|
||||
@ -238,7 +261,7 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::PermissionRemove: {
|
||||
auto userId = QueuedctlUser::getUserId(args.at(1));
|
||||
auto userId = QueuedCoreAdaptor::getUserId(args.at(1));
|
||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||
result.status
|
||||
= QueuedctlPermissions::removePermission(userId, args.at(2), token);
|
||||
@ -284,6 +307,12 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
= hashListToString(QueuedctlUser::getReport(_parser, token));
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::Status: {
|
||||
auto status = QueuedCoreAdaptor::getStatus();
|
||||
result.status = !status.isEmpty();
|
||||
result.output = hashHashToString(status);
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::TaskAdd: {
|
||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||
auto definitions = QueuedctlTask::getDefinitions(_parser, false);
|
||||
@ -340,7 +369,7 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::UserGet: {
|
||||
auto userId = QueuedctlUser::getUserId(args.at(1));
|
||||
auto userId = QueuedCoreAdaptor::getUserId(args.at(1));
|
||||
QVariant value = QueuedctlUser::getUser(userId, args.at(2));
|
||||
result.status = value.isValid();
|
||||
result.output = args.at(2).isEmpty() ? hashToString(value.toHash())
|
||||
@ -355,7 +384,7 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::UserSet: {
|
||||
auto userId = QueuedctlUser::getUserId(args.at(1));
|
||||
auto userId = QueuedCoreAdaptor::getUserId(args.at(1));
|
||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||
auto definitions = QueuedctlUser::getDefinitions(_parser, true);
|
||||
result.status = QueuedctlUser::setUser(userId, definitions, token);
|
||||
|
@ -34,6 +34,7 @@ enum class QueuedctlArgument {
|
||||
PluginList,
|
||||
PluginRemove,
|
||||
Report,
|
||||
Status,
|
||||
TaskAdd,
|
||||
TaskGet,
|
||||
TaskList,
|
||||
@ -68,6 +69,7 @@ const QHash<QString, QueuedctlArgumentInfo> QueuedctlArguments = {
|
||||
{"plugin-remove",
|
||||
{QueuedctlArgument::PluginRemove, "Removes plugin to load.", 2}},
|
||||
{"report", {QueuedctlArgument::Report, "Shows usage report.", 1}},
|
||||
{"status", {QueuedctlArgument::Status, "Server status.", 1}},
|
||||
{"task-add", {QueuedctlArgument::TaskAdd, "Adds new task.", 2}},
|
||||
{"task-get", {QueuedctlArgument::TaskGet, "Gets task properties.", 3}},
|
||||
{"task-list", {QueuedctlArgument::TaskList, "Gets tasks list.", 1}},
|
||||
@ -82,6 +84,7 @@ const QHash<QString, QueuedctlArgumentInfo> QueuedctlArguments = {
|
||||
void checkArgs(const QStringList &_args, const int _count,
|
||||
QCommandLineParser &_parser);
|
||||
QString commandsHelp();
|
||||
QString hashHashToString(const QHash<QString, QHash<QString, QString>> &_hash);
|
||||
QString hashToString(const QVariantHash &_hash);
|
||||
QString hashListToString(const QList<QVariantHash> &_list);
|
||||
void preprocess(const QStringList &_args, QCommandLineParser &_parser);
|
||||
|
@ -29,9 +29,7 @@ bool QueuedctlPlugins::addPlugin(const QString &_plugin, const QString &_token)
|
||||
|
||||
QStringList QueuedctlPlugins::listPlugins()
|
||||
{
|
||||
return QueuedCoreAdaptor::getOption(
|
||||
QueuedAdvancedSettings::internalId(
|
||||
QueuedConfig::QueuedSettings::Plugins))
|
||||
return QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::Plugins)
|
||||
.toString()
|
||||
.split('\n');
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ QueuedctlTask::getDefinitions(const QCommandLineParser &_parser,
|
||||
definitions.user
|
||||
= _parser.value("task-user").isEmpty()
|
||||
? 0
|
||||
: QueuedctlUser::getUserId(_parser.value("task-user"));
|
||||
: QueuedCoreAdaptor::getUserId(_parser.value("task-user"));
|
||||
definitions.workingDirectory
|
||||
= QFileInfo(_parser.value("directory")).absoluteFilePath();
|
||||
// limits now
|
||||
@ -93,20 +93,20 @@ QVariant QueuedctlTask::getTask(const long long _id, const QString &_property)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Get property" << _property << "from task" << _id;
|
||||
|
||||
auto value = QueuedCoreAdaptor::getTask(_id, _property);
|
||||
if (_property.isEmpty())
|
||||
return qdbus_cast<QVariantHash>(value.value<QDBusArgument>());
|
||||
return QueuedCoreAdaptor::getTask(_id);
|
||||
else
|
||||
return value;
|
||||
return QueuedCoreAdaptor::getTask(_id, _property);
|
||||
}
|
||||
|
||||
|
||||
QList<QVariantHash> QueuedctlTask::getTasks(const QCommandLineParser &_parser,
|
||||
const QString &_token)
|
||||
{
|
||||
long long user = _parser.value("task-user").isEmpty()
|
||||
? -1
|
||||
: QueuedctlUser::getUserId(_parser.value("task-user"));
|
||||
long long user
|
||||
= _parser.value("task-user").isEmpty()
|
||||
? -1
|
||||
: QueuedCoreAdaptor::getUserId(_parser.value("task-user"));
|
||||
QDateTime stop
|
||||
= QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
||||
QDateTime start
|
||||
|
@ -111,11 +111,10 @@ QVariant QueuedctlUser::getUser(const long long _id, const QString &_property)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Get property" << _property << "from user" << _id;
|
||||
|
||||
auto value = QueuedCoreAdaptor::getUser(_id, _property);
|
||||
if (_property.isEmpty())
|
||||
return qdbus_cast<QVariantHash>(value.value<QDBusArgument>());
|
||||
return QueuedCoreAdaptor::getUser(_id);
|
||||
else
|
||||
return value;
|
||||
return QueuedCoreAdaptor::getUser(_id, _property);
|
||||
}
|
||||
|
||||
|
||||
@ -133,19 +132,6 @@ QList<QVariantHash> QueuedctlUser::getUsers(const QCommandLineParser &_parser,
|
||||
}
|
||||
|
||||
|
||||
long long QueuedctlUser::getUserId(const QString &_name)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Get user ID for" << _name;
|
||||
|
||||
bool status = false;
|
||||
long long stringToLong = _name.toLongLong(&status);
|
||||
if (status)
|
||||
return stringToLong;
|
||||
else
|
||||
return QueuedCoreAdaptor::getUserId(_name);
|
||||
}
|
||||
|
||||
|
||||
void QueuedctlUser::parserAdd(QCommandLineParser &_parser)
|
||||
{
|
||||
_parser.addPositionalArgument("name", "User name.", "<name>");
|
||||
|
@ -34,7 +34,6 @@ QString getPassword();
|
||||
QVariant getUser(const long long _id, const QString &_property);
|
||||
QList<QVariantHash> getUsers(const QCommandLineParser &_parser,
|
||||
const QString &_token);
|
||||
long long getUserId(const QString &_name);
|
||||
void parserAdd(QCommandLineParser &_parser);
|
||||
void parserGet(QCommandLineParser &_parser);
|
||||
void parserList(QCommandLineParser &_parser);
|
||||
|
Reference in New Issue
Block a user