diff --git a/sources/queued/include/queued/QueuedPluginInterface.h b/sources/queued/include/queued/QueuedPluginInterface.h index afa6776..209a20d 100644 --- a/sources/queued/include/queued/QueuedPluginInterface.h +++ b/sources/queued/include/queued/QueuedPluginInterface.h @@ -54,6 +54,14 @@ public: * @remark plugin settings will be stored as "plugin.name.Key" */ virtual void init(const QVariantHash &_settings) = 0; + /** + * @brief set plugin token + * @remark this method may be safety ignored if plugin does not use methods + * require auth + * @param _token + * new token ID + */ + virtual void setToken(const QString &_token) = 0; /** * @brief method which will be called on option update * @param _key @@ -61,7 +69,8 @@ public: * @param _value * option value */ - virtual void updateSettings(const QString &_key, const QVariant &_value); + virtual void updateSettings(const QString &_key, const QVariant &_value) + = 0; }; Q_DECLARE_INTERFACE(QueuedPluginInterface, PLUGIN_INTERFACE_NAME) diff --git a/sources/queued/include/queued/QueuedPluginManager.h b/sources/queued/include/queued/QueuedPluginManager.h index 40a0abb..3945d3c 100644 --- a/sources/queued/include/queued/QueuedPluginManager.h +++ b/sources/queued/include/queued/QueuedPluginManager.h @@ -50,8 +50,10 @@ public: * @brief QueuedPluginManager class constructor * @param parent * pointer to parent item + * @param token + * plugin auth token */ - explicit QueuedPluginManager(QObject *parent); + explicit QueuedPluginManager(QObject *parent, const QString &token); /** * @brief QueuedPluginManager class destructor */ @@ -101,14 +103,18 @@ public slots: void optionChanged(const QString &_key, const QVariant &_value); private: + /** + * @brief pointer to database object + */ + QueuedPluginManagerInterface *m_interface = nullptr; /** * @brief loaded plugins */ QueuedPluginMap m_plugins; /** - * @brief pointer to database object + * @brief plugin auth token */ - QueuedPluginManagerInterface *m_interface = nullptr; + QString m_token; }; diff --git a/sources/queued/include/queued/QueuedUserManager.h b/sources/queued/include/queued/QueuedUserManager.h index 62d198b..7b0e40e 100644 --- a/sources/queued/include/queued/QueuedUserManager.h +++ b/sources/queued/include/queued/QueuedUserManager.h @@ -72,6 +72,14 @@ public: */ QueuedUser *add(const QueuedUser::QueuedUserDefinitions &_definitions, const long long _id); + /** + * @brief authorize user manually + * @remark it ignores password input and creates unlimited token + * @param _user + * user name + * @return generated token + */ + QString authorize(const QString &_user); /** * @brief authorize user * @param _user diff --git a/sources/queued/src/QueuedCore.cpp b/sources/queued/src/QueuedCore.cpp index 6b4efee..fecdf87 100644 --- a/sources/queued/src/QueuedCore.cpp +++ b/sources/queued/src/QueuedCore.cpp @@ -27,6 +27,7 @@ #include #include +#include /** @@ -786,8 +787,9 @@ void QueuedCore::initPlugins() = m_advancedSettings->get(QueuedConfig::QueuedSettings::Plugins) .toString() .split('\n'); + QString token = m_users->authorize(m_settings->admin().name); - m_plugins = new QueuedPluginManager(this); + m_plugins = new QueuedPluginManager(this, token); for (auto &plugin : pluginList) m_plugins->loadPlugin(plugin, pluginSettings(plugin)); } @@ -998,10 +1000,15 @@ bool QueuedCore::editOptionPrivate(const QString &_key, const QVariant &_value) // add to child object if (status) { m_advancedSettings->set(_key, _value); - // TODO notify plugin if required - // notify plugins - if (m_plugins) + // notify plugins if required + if (m_plugins) { + auto tryPluginOption = m_plugins->convertOptionName(_key); + if ((!tryPluginOption.first.isEmpty()) + && (!tryPluginOption.second.isEmpty())) + m_plugins->optionChanged(_key, _value); + // notify plugins emit(m_plugins->interface()->onEditOption(_key, _value)); + } } return status; @@ -1037,11 +1044,12 @@ bool QueuedCore::editPluginPrivate(const QString &_plugin, const bool _add) QueuedConfig::QueuedSettings::Plugins), pluginList.join('\n')); // notify plugins - if (_add) - if (m_plugins) + if (m_plugins) { + if (_add) emit(m_plugins->interface()->onAddPlugin(_plugin)); - else if (m_plugins) + else emit(m_plugins->interface()->onRemovePlugin(_plugin)); + } } return status; diff --git a/sources/queued/src/QueuedPluginManager.cpp b/sources/queued/src/QueuedPluginManager.cpp index 1e0c642..d069ca2 100644 --- a/sources/queued/src/QueuedPluginManager.cpp +++ b/sources/queued/src/QueuedPluginManager.cpp @@ -34,8 +34,9 @@ /** * @fn QueuedPluginManager */ -QueuedPluginManager::QueuedPluginManager(QObject *parent) +QueuedPluginManager::QueuedPluginManager(QObject *parent, const QString &token) : QObject(parent) + , m_token(token) { qCDebug(LOG_PL) << __PRETTY_FUNCTION__; @@ -121,6 +122,7 @@ bool QueuedPluginManager::loadPlugin(const QString &_name, if (item) { m_plugins[_name] = item; item->init(pluginSettings); + item->setToken(m_token); item->connect(interface()); } else { qCCritical(LOG_PL) << "Could not cast plugin" << _name; diff --git a/sources/queued/src/QueuedUserManager.cpp b/sources/queued/src/QueuedUserManager.cpp index c45d4bb..7f05436 100644 --- a/sources/queued/src/QueuedUserManager.cpp +++ b/sources/queued/src/QueuedUserManager.cpp @@ -93,6 +93,20 @@ QueuedUserManager::add(const QueuedUser::QueuedUserDefinitions &_definitions, } +/** + * @fn authorize + */ +QString QueuedUserManager::authorize(const QString &_user) +{ + qCDebug(LOG_LIB) << "Authorize user manually" << _user; + + auto time = QDateTime::currentDateTimeUtc(); + time = time.addDays(9999); + + return m_tokens->registerToken(_user, time); +} + + /** * @fn authorize */