diff --git a/app/inpututils.cpp b/app/inpututils.cpp index 218c024e1..9f6328953 100644 --- a/app/inpututils.cpp +++ b/app/inpututils.cpp @@ -2222,3 +2222,14 @@ double InputUtils::pixelDistanceBetween( const QPointF &p1, const QPointF &p2 ) { return std::hypot( p1.x() - p2.x(), p1.y() - p2.y() ); } + +bool InputUtils::userHasEditableRole( QgsProject *project ) +{ + const QString &projectDir = project->absolutePath(); + QString metadataFilePath = projectDir + "/" + MerginApi::sMetadataFile; + MerginProjectMetadata metadata = MerginProjectMetadata::fromCachedJson( metadataFilePath ); + QString role = metadata.role; + + bool hasEditableRole = role != "reader" && role != "guest"; + return hasEditableRole; +} diff --git a/app/inpututils.h b/app/inpututils.h index 83be81f39..2bfd4066c 100644 --- a/app/inpututils.h +++ b/app/inpututils.h @@ -589,6 +589,11 @@ class InputUtils: public QObject */ static double pixelDistanceBetween( const QPointF &p1, const QPointF &p2 ); + /** + * Checks if the user can edit the project + */ + Q_INVOKABLE static bool userHasEditableRole( QgsProject *project ); + public slots: void onQgsLogMessageReceived( const QString &message, const QString &tag, Qgis::MessageLevel level ); diff --git a/app/qml/main.qml b/app/qml/main.qml index d6b7ea116..0a662b077 100644 --- a/app/qml/main.qml +++ b/app/qml/main.qml @@ -276,6 +276,7 @@ ApplicationWindow { MMToolbarButton { text: qsTr("Add") iconSource: __style.addIcon + visible: __inputUtils.userHasEditableRole( __activeProject.qgsProject ) onClicked: { if ( __recordingLayersModel.rowCount() > 0 ) { stateManager.state = "map" diff --git a/core/merginprojectmetadata.cpp b/core/merginprojectmetadata.cpp index 9609087fa..2943cfd9f 100644 --- a/core/merginprojectmetadata.cpp +++ b/core/merginprojectmetadata.cpp @@ -99,6 +99,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(); QJsonValue access = docObj.value( QStringLiteral( "access" ) ); if ( access.isObject() ) diff --git a/core/merginprojectmetadata.h b/core/merginprojectmetadata.h index b56edf89d..90383ad23 100644 --- a/core/merginprojectmetadata.h +++ b/core/merginprojectmetadata.h @@ -59,6 +59,7 @@ struct MerginProjectMetadata { QString name; QString projectNamespace; + QString role; QList writersnames; int version = -1; QList files;