diff --git a/app/activeproject.cpp b/app/activeproject.cpp index 39d855cb3..d51e64174 100644 --- a/app/activeproject.cpp +++ b/app/activeproject.cpp @@ -97,12 +97,14 @@ QString ActiveProject::projectFullName() const bool ActiveProject::load( const QString &filePath ) { - updateProjectMetadata(); return forceLoad( filePath, false ); } bool ActiveProject::forceLoad( const QString &filePath, bool force ) { + // update user's role each time a project is opened, following #3174 + updateProjectMetadata(); + CoreUtils::log( QStringLiteral( "Project loading" ), filePath + " " + ( force ? "true" : "false" ) ); // clear autosync @@ -567,6 +569,7 @@ bool ActiveProject::updateProjectMetadata() QNetworkReply *reply = mMerginApi->getProjectInfo( projectFullName() ); if ( !reply ) { + restoreCachedRole(); return false; } @@ -589,24 +592,24 @@ void ActiveProject::updateProjectMetadataReplyFinished() QByteArray data = r->readAll(); MerginProjectMetadata serverProject = MerginProjectMetadata::fromJson( data ); - QString role = serverProject.role; setProjectRole( role ); } else { - QString serverMsg = mMerginApi->extractServerErrorMsg( r->readAll() ); - - QString projectDir = mQgsProject->absolutePath(); - MerginProjectMetadata cachedProjectMetadata = MerginProjectMetadata::fromCachedJson( mLocalProject.projectDir + "/" + mMerginApi->sMetadataFile ); - - QString role = cachedProjectMetadata.role; - setProjectRole( role ); + restoreCachedRole(); } r->deleteLater(); } +void ActiveProject::restoreCachedRole() +{ + MerginProjectMetadata cachedProjectMetadata = MerginProjectMetadata::fromCachedJson( mLocalProject.projectDir + "/" + mMerginApi->sMetadataFile ); + QString role = cachedProjectMetadata.role; + setProjectRole( role ); +} + QString ActiveProject::projectRole() const { return mProjectRole; diff --git a/app/activeproject.h b/app/activeproject.h index 54b2de4e5..bec9a8b4f 100644 --- a/app/activeproject.h +++ b/app/activeproject.h @@ -125,8 +125,14 @@ class ActiveProject: public QObject * Returns role/permission level of current user for this project */ Q_INVOKABLE QString projectRole() const; + void setProjectRole( const QString &role ); + /** + * Restores cached project role in metadata + */ + void restoreCachedRole(); + /** * Creates a network request to fetch latest project information and define user role in this project */ diff --git a/app/qml/form/MMFormPage.qml b/app/qml/form/MMFormPage.qml index f12a9647f..1168a06d0 100644 --- a/app/qml/form/MMFormPage.qml +++ b/app/qml/form/MMFormPage.qml @@ -201,7 +201,7 @@ Page { footer: MMComponents.MMToolbar { - visible: !root.layerIsReadOnly + visible: !root.layerIsReadOnly && __activeProject.projectRole !== "reader" ObjectModel { id: readStateButtons @@ -231,7 +231,7 @@ Page { id: editGeometry text: qsTr( "Edit geometry" ) iconSource: __style.editIcon - visible: root.layerIsSpatial + visible: root.layerIsSpatial && __activeProject.projectRole !== "reader" onClicked: root.editGeometryRequested( root.controller.featureLayerPair ) } } diff --git a/app/qml/form/MMPreviewDrawer.qml b/app/qml/form/MMPreviewDrawer.qml index ca6753fc0..328d55ebb 100644 --- a/app/qml/form/MMPreviewDrawer.qml +++ b/app/qml/form/MMPreviewDrawer.qml @@ -295,7 +295,7 @@ Item { property bool isHTMLType: root.controller.type === MM.AttributePreviewController.HTML property bool isEmptyType: root.controller.type === MM.AttributePreviewController.Empty - property bool showEditButton: !root.layerIsReadOnly + property bool showEditButton: !root.layerIsReadOnly && __activeProject.projectRole !== "reader" property bool showStakeoutButton: __inputUtils.isPointLayerFeature( controller.featureLayerPair ) property bool showButtons: showEditButton || showStakeoutButton diff --git a/app/qml/form/components/MMFeaturesListPageDrawer.qml b/app/qml/form/components/MMFeaturesListPageDrawer.qml index c6f3a266a..ce9c22933 100644 --- a/app/qml/form/components/MMFeaturesListPageDrawer.qml +++ b/app/qml/form/components/MMFeaturesListPageDrawer.qml @@ -103,6 +103,7 @@ Drawer { } text: qsTr( "Add feature" ) + visible: __activeProject.projectRole !== "reader" onClicked: root.buttonClicked() } diff --git a/app/qml/layers/MMFeaturesListPage.qml b/app/qml/layers/MMFeaturesListPage.qml index 04b8bb256..5bf9c3f9f 100644 --- a/app/qml/layers/MMFeaturesListPage.qml +++ b/app/qml/layers/MMFeaturesListPage.qml @@ -89,7 +89,7 @@ MMComponents.MMPage { anchors.bottom: parent.bottom anchors.bottomMargin: root.hasToolbar ? __style.margin20 : ( __style.safeAreaBottom + __style.margin8 ) - visible: __inputUtils.isNoGeometryLayer( root.selectedLayer ) && !root.layerIsReadOnly + visible: __inputUtils.isNoGeometryLayer( root.selectedLayer ) && !root.layerIsReadOnly && __activeProject.projectRole !== "reader" text: qsTr("Add feature") diff --git a/app/qml/project/MMProjectController.qml b/app/qml/project/MMProjectController.qml index 04f52008d..47d34033d 100644 --- a/app/qml/project/MMProjectController.qml +++ b/app/qml/project/MMProjectController.qml @@ -50,6 +50,8 @@ Item { { // just hide the panel - project already loaded hidePanel() + // update user's role in project ( in case user has changed ) + __activeProject.updateProjectMetadata() } else { diff --git a/core/merginapi.cpp b/core/merginapi.cpp index c2f40bd23..ab5e4a618 100644 --- a/core/merginapi.cpp +++ b/core/merginapi.cpp @@ -720,7 +720,6 @@ bool MerginApi::pullProject( const QString &projectNamespace, const QString &pro CoreUtils::log( "pull " + projectFullName, "### Starting ###" ); - qDebug() << "HERE projectNamespace AND projectName : " << projectNamespace << " " << projectName; QNetworkReply *reply = getProjectInfo( projectFullName, withAuth ); if ( reply ) { diff --git a/core/merginprojectmetadata.cpp b/core/merginprojectmetadata.cpp index 79d8f93db..2943cfd9f 100644 --- a/core/merginprojectmetadata.cpp +++ b/core/merginprojectmetadata.cpp @@ -100,7 +100,7 @@ MerginProjectMetadata MerginProjectMetadata::fromJson( const QByteArray &data ) project.name = docObj.value( QStringLiteral( "name" ) ).toString(); project.projectNamespace = docObj.value( QStringLiteral( "namespace" ) ).toString(); project.role = docObj.value( QStringLiteral( "role" ) ).toString(); - qDebug() << "MerginProjectMetadata MerginProjectMetadata::fromJson( const QByteArray &data ) called, getting role: " << project.role; + QJsonValue access = docObj.value( QStringLiteral( "access" ) ); if ( access.isObject() ) {