Read-Only Configuration-Database support (#1046)

This commit is contained in:
LordGrey
2020-11-01 19:47:30 +01:00
committed by GitHub
parent 85a55de28c
commit bb652ade36
35 changed files with 268 additions and 90 deletions

View File

@@ -231,7 +231,7 @@ protected:
/// @brief Save settings object. Requires ADMIN ACCESS
/// @param data The data object
///
void saveSettings(const QJsonObject &data);
bool saveSettings(const QJsonObject &data);
///
/// @brief Test if we are authorized to use the interface

View File

@@ -16,9 +16,10 @@ class AuthTable : public DBManager
public:
/// construct wrapper with auth table
AuthTable(const QString& rootPath = "", QObject* parent = nullptr)
AuthTable(const QString& rootPath = "", QObject* parent = nullptr, bool readonlyMode = false)
: DBManager(parent)
{
setReadonlyMode(readonlyMode);
if(!rootPath.isEmpty()){
// Init Hyperion database usage
setRootPath(rootPath);

View File

@@ -119,6 +119,13 @@ public:
///
bool deleteTable(const QString& table) const;
///
/// @brief Sets a table in read-only mode.
/// Updates will not written to the table
/// @param[in] readOnly True read-only, false - read/write
///
void setReadonlyMode(bool readOnly) { _readonlyMode = readOnly; };
private:
Logger* _log;
@@ -127,6 +134,8 @@ private:
/// table in database
QString _table;
bool _readonlyMode;
/// addBindValue to query given by QVariantList
void doAddBindValue(QSqlQuery& query, const QVariantList& variants) const;
};

View File

@@ -14,9 +14,11 @@ class InstanceTable : public DBManager
{
public:
InstanceTable(const QString& rootPath, QObject* parent = nullptr)
InstanceTable(const QString& rootPath, QObject* parent = nullptr, bool readonlyMode = false)
: DBManager(parent)
{
setReadonlyMode(readonlyMode);
// Init Hyperion database usage
setRootPath(rootPath);
setDatabaseName("hyperion");

View File

@@ -17,9 +17,11 @@ class MetaTable : public DBManager
public:
/// construct wrapper with plugins table and columns
MetaTable(QObject* parent = nullptr)
MetaTable(QObject* parent = nullptr, bool readonlyMode = false)
: DBManager(parent)
{
setReadonlyMode(readonlyMode);
setTable("meta");
createTable(QStringList()<<"uuid TEXT"<<"created_at TEXT");
};

View File

@@ -21,7 +21,7 @@ class AuthManager : public QObject
private:
friend class HyperionDaemon;
/// constructor is private, can be called from HyperionDaemon
AuthManager(QObject *parent = 0);
AuthManager(QObject *parent = 0, bool readonlyMode = false);
public:
struct AuthDefinition

View File

@@ -98,6 +98,8 @@ public:
///
QString getActiveDeviceType() const;
bool getReadOnlyMode() {return _readOnlyMode; };
public slots:
///
@@ -484,7 +486,7 @@ private:
/// @brief Constructs the Hyperion instance, just accessible for HyperionIManager
/// @param instance The instance index
///
Hyperion(quint8 instance);
Hyperion(quint8 instance, bool readonlyMode = false);
/// instance index
const quint8 _instIndex;
@@ -541,4 +543,6 @@ private:
/// Boblight instance
BoblightServer* _boblightServer;
bool _readOnlyMode;
};

View File

@@ -169,7 +169,7 @@ private:
/// @brief Construct the Manager
/// @param The root path of all userdata
///
HyperionIManager(const QString& rootPath, QObject* parent = nullptr);
HyperionIManager(const QString& rootPath, QObject* parent = nullptr, bool readonlyMode = false);
///
/// @brief Start all instances that are marked as enabled in db. Non blocking
@@ -193,6 +193,9 @@ private:
const QString _rootPath;
QMap<quint8, Hyperion*> _runningInstances;
QList<quint8> _startQueue;
bool _readonlyMode;
/// All pending requests
QMap<quint8, PendingRequests> _pendingRequests;
};

View File

@@ -21,7 +21,7 @@ public:
/// @params instance Instance index of HyperionInstanceManager
/// @params parent The parent hyperion instance
///
SettingsManager(quint8 instance, QObject* parent = nullptr);
SettingsManager(quint8 instance, QObject* parent = nullptr, bool readonlyMode = false);
///
/// @brief Save a complete json config
@@ -75,4 +75,6 @@ private:
/// the current config of this instance
QJsonObject _qconfig;
bool _readonlyMode;
};