diff --git a/src/blackgui/components/dbstashcomponent.cpp b/src/blackgui/components/dbstashcomponent.cpp index 72b3f6941..b3410303c 100644 --- a/src/blackgui/components/dbstashcomponent.cpp +++ b/src/blackgui/components/dbstashcomponent.cpp @@ -79,6 +79,7 @@ namespace BlackGui this->enableButtonRow(); connect(sApp->getWebDataServices()->getDatabaseWriter(), &CDatabaseWriter::publishedModels, this, &CDbStashComponent::ps_publishedModelsResponse); + this->ps_userChanged(); } CDbStashComponent::~CDbStashComponent() @@ -364,9 +365,9 @@ namespace BlackGui ui->pb_AirlineIcao->setEnabled(e); ui->pb_Distributor->setEnabled(e); ui->pb_Livery->setEnabled(e); - ui->pb_Publish->setEnabled(e); ui->pb_Unstash->setEnabled(e); ui->pb_Validate->setEnabled(e); + this->ps_userChanged(); } const CLogCategoryList &CDbStashComponent::validationCategories() const @@ -398,6 +399,11 @@ namespace BlackGui return ownModel; } + CAuthenticatedUser CDbStashComponent::getSwiftDbUser() const + { + return this->m_swiftDbUser.get(); + } + CAircraftModel CDbStashComponent::consolidateModel(const CAircraftModel &model) const { CAircraftModel stashModel(model); @@ -451,6 +457,29 @@ namespace BlackGui this->enableButtonRow(); } + void CDbStashComponent::ps_userChanged() + { + const CAuthenticatedUser user(this->getSwiftDbUser()); + if (!user.isAuthenticated()) + { + ui->pb_Publish->setText("Publish (login)"); + ui->pb_Publish->setToolTip("Login first"); + ui->pb_Publish->setEnabled(false); + } + else if (user.canDirectlyWriteModels()) + { + ui->pb_Publish->setText("Publish (admin)"); + ui->pb_Publish->setToolTip("Models directly released"); + ui->pb_Publish->setEnabled(true); + } + else + { + ui->pb_Publish->setText("Publish (user)"); + ui->pb_Publish->setToolTip("Models published as change request"); + ui->pb_Publish->setEnabled(true); + } + } + bool CDbStashComponent::showMessages(const CStatusMessageList &msgs, bool onlyErrors, int timeoutMs) { if (msgs.isEmpty()) { return false; } diff --git a/src/blackgui/components/dbstashcomponent.h b/src/blackgui/components/dbstashcomponent.h index 195902fb0..acd9e0739 100644 --- a/src/blackgui/components/dbstashcomponent.h +++ b/src/blackgui/components/dbstashcomponent.h @@ -15,8 +15,10 @@ #include "blackgui/blackguiexport.h" #include "blackgui/components/dbmappingcomponentaware.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" +#include "blackcore/data/authenticateduser.h" #include "blackmisc/aviation/airlineicaocode.h" #include "blackmisc/propertyindexvariantmap.h" +#include "blackmisc/network/authenticateduser.h" #include "blackmisc/simulation/aircraftmodel.h" #include "blackmisc/simulation/aircraftmodellist.h" #include "blackmisc/simulation/distributor.h" @@ -160,8 +162,12 @@ namespace BlackGui //! Row count changed void ps_onRowCountChanged(int number, bool filter); + //! User has been changed + void ps_userChanged(); + private: QScopedPointer ui; + BlackMisc::CDataReadOnly m_swiftDbUser {this, &CDbStashComponent::ps_userChanged}; //!< authenticated user //! Display messages bool showMessages(const BlackMisc::CStatusMessageList &msgs, bool onlyErrors = false, int timeoutMs = -1); @@ -192,6 +198,9 @@ namespace BlackGui //! Consolidate with own models (if available). This updates mostly with model description, path etc. BlackMisc::Simulation::CAircraftModel consolidateWithOwnModels(const BlackMisc::Simulation::CAircraftModel &model) const; + + //! Authenticated DB user + BlackMisc::Network::CAuthenticatedUser getSwiftDbUser() const; }; } // ns } // ns diff --git a/src/blackgui/editors/form.cpp b/src/blackgui/editors/form.cpp index 31d26e5c6..499b60588 100644 --- a/src/blackgui/editors/form.cpp +++ b/src/blackgui/editors/form.cpp @@ -32,9 +32,9 @@ namespace BlackGui return CStatusMessageList(); } - const CAuthenticatedUser &CForm::getSwiftDbUser() const + CAuthenticatedUser CForm::getSwiftDbUser() const { - return this->m_swiftDbUser.getThreadLocal(); + return this->m_swiftDbUser.get(); } void CForm::ps_userChanged() diff --git a/src/blackgui/editors/form.h b/src/blackgui/editors/form.h index b5292c654..f161161ae 100644 --- a/src/blackgui/editors/form.h +++ b/src/blackgui/editors/form.h @@ -54,11 +54,11 @@ namespace BlackGui bool isReadOnly() const { return m_readOnly; } //! Authenticated DB user - const BlackMisc::Network::CAuthenticatedUser &getSwiftDbUser() const; + BlackMisc::Network::CAuthenticatedUser getSwiftDbUser() const; protected: bool m_readOnly = false; //!< read only - BlackMisc::CData m_swiftDbUser {this, &CForm::ps_userChanged}; //!< authenticated user + BlackMisc::CDataReadOnly m_swiftDbUser {this, &CForm::ps_userChanged}; //!< authenticated user protected slots: //! User has been changed