Skip to content

Commit

Permalink
updating role every time we open a project + visibility condition on …
Browse files Browse the repository at this point in the history
…editing buttons
  • Loading branch information
VitorVieiraZ committed Nov 28, 2024
1 parent 5da5eca commit 7a01cc6
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 15 deletions.
21 changes: 12 additions & 9 deletions app/activeproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -567,6 +569,7 @@ bool ActiveProject::updateProjectMetadata()
QNetworkReply *reply = mMerginApi->getProjectInfo( projectFullName() );
if ( !reply )
{
restoreCachedRole();
return false;
}

Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions app/activeproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions app/qml/form/MMFormPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Page {

footer: MMComponents.MMToolbar {

visible: !root.layerIsReadOnly
visible: !root.layerIsReadOnly && __activeProject.projectRole !== "reader"

ObjectModel {
id: readStateButtons
Expand Down Expand Up @@ -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 )
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/qml/form/MMPreviewDrawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions app/qml/form/components/MMFeaturesListPageDrawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Drawer {
}

text: qsTr( "Add feature" )
visible: __activeProject.projectRole !== "reader"

onClicked: root.buttonClicked()
}
Expand Down
2 changes: 1 addition & 1 deletion app/qml/layers/MMFeaturesListPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 2 additions & 0 deletions app/qml/project/MMProjectController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 0 additions & 1 deletion core/merginapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
2 changes: 1 addition & 1 deletion core/merginprojectmetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
{
Expand Down

1 comment on commit 7a01cc6

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS - version 24.11.696411 just submitted!

Please sign in to comment.