Skip to content

Commit

Permalink
Fixed dock permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
juangburgos committed Apr 29, 2021
1 parent bcef299 commit e1ac862
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion libs/QUaAccessControl.git
41 changes: 27 additions & 14 deletions src/docks/quamodbusdockwidgets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class QUaModbusDockWidgets : public QObject

// helpers
QUaAcDocking * getDockManager() const;
void showDock(const QString& strDockName);

const static QString m_strMenuPath;
const static QString m_strModbusTree;
Expand Down Expand Up @@ -141,8 +142,7 @@ inline void QUaModbusDockWidgets<T>::closeConfig()
template<class T>
inline void QUaModbusDockWidgets<T>::showDefaultWidgets()
{
this->getDockManager()->setIsDockVisible(QUaModbusDockWidgets<T>::m_strModbusTree, true);
this->getDockManager()->setIsDockActive (QUaModbusDockWidgets<T>::m_strModbusTree, true);
this->showDock(QUaModbusDockWidgets<T>::m_strModbusTree);
auto dockModbusTree = this->getDockManager()->dock(QUaModbusDockWidgets<T>::m_strModbusTree);
auto manager = dockModbusTree->dockManager();
manager->addDockWidgetTab(QAd::LeftDockWidgetArea, dockModbusTree);
Expand Down Expand Up @@ -352,40 +352,34 @@ inline void QUaModbusDockWidgets<T>::setupModbusTreeWidget()
QObject::connect(m_modbusTreeWidget, &QUaModbusClientTree::clientDoubleClicked, this,
[this](QUaModbusClient * client) {
Q_UNUSED(client);
this->getDockManager()->setIsDockVisible(QUaModbusDockWidgets<T>::m_strModbusClients, true);
this->getDockManager()->setIsDockActive (QUaModbusDockWidgets<T>::m_strModbusClients, true);
this->showDock(QUaModbusDockWidgets<T>::m_strModbusClients);
});
QObject::connect(m_modbusTreeWidget, &QUaModbusClientTree::editClientClicked, this,
[this](QUaModbusClient * client) {
Q_UNUSED(client);
this->getDockManager()->setIsDockVisible(QUaModbusDockWidgets<T>::m_strModbusClients, true);
this->getDockManager()->setIsDockActive (QUaModbusDockWidgets<T>::m_strModbusClients, true);
this->showDock(QUaModbusDockWidgets<T>::m_strModbusClients);
});
// open client block widget when double clicked
QObject::connect(m_modbusTreeWidget, &QUaModbusClientTree::blockDoubleClicked, this,
[this](QUaModbusDataBlock * block) {
Q_UNUSED(block);
this->getDockManager()->setIsDockVisible(QUaModbusDockWidgets<T>::m_strModbusBlocks, true);
this->getDockManager()->setIsDockActive (QUaModbusDockWidgets<T>::m_strModbusBlocks, true);
this->showDock(QUaModbusDockWidgets<T>::m_strModbusBlocks);
});
QObject::connect(m_modbusTreeWidget, &QUaModbusClientTree::editBlockClicked, this,
[this](QUaModbusDataBlock * block) {
Q_UNUSED(block);
this->getDockManager()->setIsDockVisible(QUaModbusDockWidgets<T>::m_strModbusBlocks, true);
this->getDockManager()->setIsDockActive (QUaModbusDockWidgets<T>::m_strModbusBlocks, true);
this->showDock(QUaModbusDockWidgets<T>::m_strModbusBlocks);
});
// open client edit widget when double clicked
QObject::connect(m_modbusTreeWidget, &QUaModbusClientTree::valueDoubleClicked, this,
[this](QUaModbusValue * value) {
Q_UNUSED(value);
this->getDockManager()->setIsDockVisible(QUaModbusDockWidgets<T>::m_strModbusValues, true);
this->getDockManager()->setIsDockActive (QUaModbusDockWidgets<T>::m_strModbusValues, true);
this->showDock(QUaModbusDockWidgets<T>::m_strModbusValues);
});
QObject::connect(m_modbusTreeWidget, &QUaModbusClientTree::editValueClicked, this,
[this](QUaModbusValue * value) {
Q_UNUSED(value);
this->getDockManager()->setIsDockVisible(QUaModbusDockWidgets<T>::m_strModbusValues, true);
this->getDockManager()->setIsDockActive (QUaModbusDockWidgets<T>::m_strModbusValues, true);
this->showDock(QUaModbusDockWidgets<T>::m_strModbusValues);
});
// clear widgets before clearing clients
QObject::connect(m_modbusTreeWidget, &QUaModbusClientTree::aboutToClear, m_thiz,
Expand Down Expand Up @@ -432,4 +426,23 @@ inline QUaAcDocking * QUaModbusDockWidgets<T>::getDockManager() const
return m_thiz->getDockManager();
}

template<class T>
inline void QUaModbusDockWidgets<T>::showDock(const QString& strDockName)
{
auto manager = this->getDockManager();
auto perms = manager->dockPermissions(strDockName);
if (perms && !perms->canUserRead(m_thiz->loggedUser()))
{
QMessageBox::critical(
m_thiz,
tr("Permissions Error"),
tr("You are not allowed to perform this action.\n\nPlease contact an administrator."),
QMessageBox::StandardButton::Ok
);
return;
}
manager->setIsDockVisible(strDockName, true);
manager->setIsDockActive(strDockName, true);
}

#endif // QUAMODBUSDOCKWIDGETS_H

0 comments on commit e1ac862

Please sign in to comment.