Skip to content

Commit

Permalink
Cloud projects where a given user role isn't originating from 'public…
Browse files Browse the repository at this point in the history
…' should be in My Projects tab
  • Loading branch information
nirvn committed Feb 24, 2024
1 parent 78d6564 commit 53ef63e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/core/qfieldcloudprojectsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ void QFieldCloudProjectsModel::projectRefreshData( const QString &projectId, con
project->owner = projectData.value( "owner" ).toString();
project->description = projectData.value( "description" ).toString();
project->userRole = projectData.value( "user_role" ).toString();
project->userRoleOrigin = projectData.value( "user_role_origin" ).toString();
project->isPrivate = projectData.value( "is_public" ).isUndefined() ? projectData.value( "private" ).toBool() : !projectData.value( "is_public" ).toBool( false );
project->canRepackage = projectData.value( "can_repackage" ).toBool();
project->needsRepackaging = projectData.value( "needs_repackaging" ).toBool();
Expand All @@ -543,6 +544,7 @@ void QFieldCloudProjectsModel::projectRefreshData( const QString &projectId, con
QFieldCloudUtils::setProjectSetting( project->id, QStringLiteral( "owner" ), project->owner );
QFieldCloudUtils::setProjectSetting( project->id, QStringLiteral( "description" ), project->description );
QFieldCloudUtils::setProjectSetting( project->id, QStringLiteral( "userRole" ), project->userRole );
QFieldCloudUtils::setProjectSetting( project->id, QStringLiteral( "userRoleOrigin" ), project->userRoleOrigin );
QFieldCloudUtils::setProjectSetting( project->id, QStringLiteral( "isPrivate" ), project->isPrivate );
QFieldCloudUtils::setProjectSetting( project->id, QStringLiteral( "canRepackage" ), project->canRepackage );
QFieldCloudUtils::setProjectSetting( project->id, QStringLiteral( "needsRepackaging" ), project->needsRepackaging );
Expand Down Expand Up @@ -1927,6 +1929,7 @@ QHash<int, QByteArray> QFieldCloudProjectsModel::roleNames() const
roles[LastLocalExportedAtRole] = "LastLocalExportedAt";
roles[LastLocalPushDeltasRole] = "LastLocalPushDeltas";
roles[UserRoleRole] = "UserRole";
roles[UserRoleOriginRole] = "UserRoleOrigin";
roles[DeltaListRole] = "DeltaList";

return roles;
Expand Down Expand Up @@ -1969,6 +1972,7 @@ void QFieldCloudProjectsModel::reload( const QJsonArray &remoteProjects )
projectDetails.value( "name" ).toString(),
projectDetails.value( "description" ).toString(),
projectDetails.value( "user_role" ).toString(),
projectDetails.value( "user_role_origin" ).toString(),
RemoteCheckout,
ProjectStatus::Idle,
QDateTime::fromString( projectDetails.value( "data_last_updated_at" ).toString(), Qt::ISODate ),
Expand All @@ -1979,6 +1983,7 @@ void QFieldCloudProjectsModel::reload( const QJsonArray &remoteProjects )
QFieldCloudUtils::setProjectSetting( cloudProject->id, QStringLiteral( "name" ), cloudProject->name );
QFieldCloudUtils::setProjectSetting( cloudProject->id, QStringLiteral( "description" ), cloudProject->description );
QFieldCloudUtils::setProjectSetting( cloudProject->id, QStringLiteral( "userRole" ), cloudProject->userRole );
QFieldCloudUtils::setProjectSetting( cloudProject->id, QStringLiteral( "userRoleOrigin" ), cloudProject->userRoleOrigin );
QFieldCloudUtils::setProjectSetting( cloudProject->id, QStringLiteral( "canRepackage" ), cloudProject->canRepackage );
QFieldCloudUtils::setProjectSetting( cloudProject->id, QStringLiteral( "needsRepackaging" ), cloudProject->needsRepackaging );

Expand Down Expand Up @@ -2027,8 +2032,9 @@ void QFieldCloudProjectsModel::reload( const QJsonArray &remoteProjects )
const QString description = QFieldCloudUtils::projectSetting( projectId, QStringLiteral( "description" ) ).toString();
const QString updatedAt = QFieldCloudUtils::projectSetting( projectId, QStringLiteral( "updatedAt" ) ).toString();
const QString userRole = QFieldCloudUtils::projectSetting( projectId, QStringLiteral( "userRole" ) ).toString();
const QString userRoleOrigin = QFieldCloudUtils::projectSetting( projectId, QStringLiteral( "userRoleOrigin" ) ).toString();

CloudProject *cloudProject = new CloudProject( projectId, true, owner, name, description, userRole, LocalCheckout, ProjectStatus::Idle, QDateTime(), false, false );
CloudProject *cloudProject = new CloudProject( projectId, true, owner, name, description, userRole, userRoleOrigin, LocalCheckout, ProjectStatus::Idle, QDateTime(), false, false );

cloudProject->localPath = QFieldCloudUtils::localProjectFilePath( username, cloudProject->id );
QDir localPath( QStringLiteral( "%1/%2/%3" ).arg( QFieldCloudUtils::localCloudDirectory(), username, cloudProject->id ) );
Expand Down Expand Up @@ -2115,6 +2121,8 @@ QVariant QFieldCloudProjectsModel::data( const QModelIndex &index, int role ) co
return mProjects.at( index.row() )->lastLocalPushDeltas;
case UserRoleRole:
return mProjects.at( index.row() )->userRole;
case UserRoleOriginRole:
return mProjects.at( index.row() )->userRoleOrigin;
case DeltaListRole:
return QVariant::fromValue<DeltaListModel *>( mProjects.at( index.row() )->deltaListModel );
}
Expand Down Expand Up @@ -2309,10 +2317,11 @@ bool QFieldCloudProjectsFilterModel::filterAcceptsRow( int source_row, const QMo
{
case PrivateProjects:
// the list will include public "community" projects that are present locally so they can appear in the "My projects" list
ok = mSourceModel->data( mSourceModel->index( source_row, 0, source_parent ), QFieldCloudProjectsModel::PrivateRole ).toBool() || !mSourceModel->data( mSourceModel->index( source_row, 0, source_parent ), QFieldCloudProjectsModel::LocalPathRole ).toString().isEmpty();
ok = mSourceModel->data( mSourceModel->index( source_row, 0, source_parent ), QFieldCloudProjectsModel::UserRoleOriginRole ).toString() != QStringLiteral( "public" )
|| !mSourceModel->data( mSourceModel->index( source_row, 0, source_parent ), QFieldCloudProjectsModel::LocalPathRole ).toString().isEmpty();
break;
case PublicProjects:
ok = !mSourceModel->data( mSourceModel->index( source_row, 0, source_parent ), QFieldCloudProjectsModel::PrivateRole ).toBool();
ok = mSourceModel->data( mSourceModel->index( source_row, 0, source_parent ), QFieldCloudProjectsModel::UserRoleOriginRole ).toString() == QStringLiteral( "public" );
break;
}
return ok;
Expand Down
4 changes: 4 additions & 0 deletions src/core/qfieldcloudprojectsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class QFieldCloudProjectsModel : public QAbstractListModel
LastLocalExportedAtRole,
LastLocalPushDeltasRole,
UserRoleRole,
UserRoleOriginRole,
DeltaListRole,
};

Expand Down Expand Up @@ -356,6 +357,7 @@ class QFieldCloudProjectsModel : public QAbstractListModel
const QString &name,
const QString &description,
const QString &userRole,
const QString &userRoleOrigin,
const ProjectCheckouts &checkout,
const ProjectStatus &status,
const QDateTime &dataLastUpdatedAt,
Expand All @@ -367,6 +369,7 @@ class QFieldCloudProjectsModel : public QAbstractListModel
, name( name )
, description( description )
, userRole( userRole )
, userRoleOrigin( userRoleOrigin )
, checkout( checkout )
, status( status )
, dataLastUpdatedAt( dataLastUpdatedAt )
Expand All @@ -383,6 +386,7 @@ class QFieldCloudProjectsModel : public QAbstractListModel
QString name;
QString description;
QString userRole;
QString userRoleOrigin;
ProjectErrorStatus errorStatus = ProjectErrorStatus::NoErrorStatus;
ProjectCheckouts checkout;
ProjectStatus status;
Expand Down

1 comment on commit 53ef63e

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please sign in to comment.