Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving UX by hiding editing buttons for readers of a project #3682

Merged
merged 23 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
36b2f39
wip - reader and guests cant edit
VitorVieiraZ Nov 18, 2024
8ecf262
in progress
VitorVieiraZ Nov 21, 2024
b3ded65
in progress
VitorVieiraZ Nov 22, 2024
5da5eca
updating project role on opening a project from active project and ch…
VitorVieiraZ Nov 27, 2024
7a01cc6
updating role every time we open a project + visibility condition on …
VitorVieiraZ Nov 28, 2024
eabfc85
in progress
VitorVieiraZ Dec 9, 2024
6596705
ensuring user role is cached/updated each time we open a project
VitorVieiraZ Dec 10, 2024
8a92bff
cleaning code
VitorVieiraZ Dec 10, 2024
193574d
merging master to branch
VitorVieiraZ Dec 10, 2024
493bb18
Merge branch 'master' into enhancementUiUx/readerCantEdit
VitorVieiraZ Jan 10, 2025
4a6deda
post review changes
VitorVieiraZ Jan 13, 2025
e0f23b2
tests and removing truncate
VitorVieiraZ Jan 13, 2025
9cd5999
decoupling mergin api from activeProject and rebuilding connections
VitorVieiraZ Jan 15, 2025
713b347
final adjustments
VitorVieiraZ Jan 18, 2025
3b94135
Merge branch 'master' into enhancementUiUx/readerCantEdit
VitorVieiraZ Jan 18, 2025
48d244f
replaceValueInJson tests
VitorVieiraZ Jan 20, 2025
585412e
post review updates
VitorVieiraZ Jan 21, 2025
709b3fc
merging master
VitorVieiraZ Jan 21, 2025
97888cb
code layout adjustment
VitorVieiraZ Jan 21, 2025
8e4a046
small fix
VitorVieiraZ Jan 21, 2025
0b28d3b
include merginprojectmetadata in activeproject
VitorVieiraZ Jan 21, 2025
49b2a6a
updating tests
VitorVieiraZ Jan 22, 2025
721c762
fixing tests
VitorVieiraZ Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/activeproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ bool ActiveProject::forceLoad( const QString &filePath, bool force )
}

QString role = MerginProjectMetadata::fromCachedJson( CoreUtils::getProjectMetadataPath( mLocalProject.projectDir ) ).role;
qDebug() << "ROLE 1 : " << role;
setProjectRole( role );

updateMapTheme();
Expand Down
11 changes: 0 additions & 11 deletions app/activeproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,8 @@ class ActiveProject: public QObject
* Returns role/permission level of current user for this project
*/
Q_INVOKABLE QString projectRole() const;

void setProjectRole( const QString &role );

/**
* Calls Mergin API to update current project’s role
*/
void updateUserRoleInActiveProject();

/**
* Update current project’s role
*/
void onProjectRoleUpdated( const QString &projectFullName, const QString &role );

signals:
void qgsProjectChanged();
void localProjectChanged( LocalProject project );
Expand Down
34 changes: 34 additions & 0 deletions core/coreutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <QCryptographicHash>
#include <QRegularExpression>
#include <QStorageInfo>
#include <QJsonDocument>
#include <QJsonObject>

#include "qcoreapplication.h"

Expand Down Expand Up @@ -343,3 +345,35 @@ QString CoreUtils::getProjectMetadataPath( QString projectDir )

return projectDir + "/.mergin/mergin.json";
}

bool CoreUtils::replaceValueInJson( const QString &filePath, const QString &key, const QJsonValue &value )
{
QFile file( filePath );
if ( !file.open( QIODevice::ReadOnly ) )
{
return false;
}

QByteArray data = file.readAll();
file.close();

QJsonDocument doc = QJsonDocument::fromJson( data );
if ( !doc.isObject() )
{
return false;
}

QJsonObject obj = doc.object();
obj[key] = value;
doc.setObject( obj );

if ( !file.open( QIODevice::WriteOnly ) )
{
return false;
}

bool success = ( file.write( doc.toJson() ) != -1 );
file.close();

return success;
}
5 changes: 5 additions & 0 deletions core/coreutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ class CoreUtils
*/
static QString getProjectMetadataPath( QString projectDir );

/**
* Updates a value in a JSON file at the specified top-level key
*/
static bool replaceValueInJson( const QString &filePath, const QString &key, const QJsonValue &value );
tomasMizera marked this conversation as resolved.
Show resolved Hide resolved

private:
static QString sLogFile;
static int CHECKSUM_CHUNK_SIZE;
Expand Down
30 changes: 1 addition & 29 deletions core/merginapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3458,35 +3458,7 @@ bool MerginApi::updateCachedProjectRole( const QString &projectFullName, const Q
}

QString metadataPath = project.projectDir + "/" + sMetadataFile;

QFile file( metadataPath );
if ( !file.open( QIODevice::ReadOnly ) )
{
return false;
}

QByteArray data = file.readAll();
file.close();

QJsonDocument doc = QJsonDocument::fromJson( data );
if ( !doc.isObject() )
{
return false;
}

QJsonObject obj = doc.object();
obj["role"] = newRole;
doc.setObject( obj );

if ( !file.open( QIODevice::WriteOnly ) )
{
return false;
}

bool success = ( file.write( doc.toJson() ) != -1 );
file.close();

return success;
return CoreUtils::replaceValueInJson( metadataPath, "role", newRole );
}

void MerginApi::createPathIfNotExists( const QString &filePath )
Expand Down
Loading