Skip to content
Permalink
Browse files

Merge pull request #33759 from rldhont/backport-33668-to-release-3_10

[Server] Throw exception if bad layers are not restricted
  • Loading branch information
rldhont committed Jan 14, 2020
2 parents 465e9e8 + a978e35 commit 85c7f92ddc5ab88f99073e3ded3d779530f11582
@@ -39,6 +39,13 @@ handleBadLayers
badLayers

:return: ids of bad layers
%End

QMap<QString, QString> badLayerNames() const;
%Docstring
Returns names of bad layers with ids.

.. versionadded:: 3.12
%End

};
@@ -19,6 +19,7 @@
#include "qgsmessagelog.h"
#include "qgsserverexception.h"
#include "qgsstorebadlayerinfo.h"
#include "qgsserverprojectutils.h"

#include <QFile>

@@ -48,9 +49,29 @@ const QgsProject *QgsConfigCache::project( const QString &path )
{
if ( !badLayerHandler->badLayers().isEmpty() )
{
QString errorMsg = QStringLiteral( "Layer(s) %1 not valid" ).arg( badLayerHandler->badLayers().join( ',' ) );
QgsMessageLog::logMessage( errorMsg, QStringLiteral( "Server" ), Qgis::Critical );
throw QgsServerException( QStringLiteral( "Layer(s) not valid" ) );
// if bad layers are not restricted layers so service failed
QStringList unrestrictedBadLayers;
// test bad layers through restrictedlayers
const QStringList badLayerIds = badLayerHandler->badLayers();
const QMap<QString, QString> badLayerNames = badLayerHandler->badLayerNames();
const QStringList resctrictedLayers = QgsServerProjectUtils::wmsRestrictedLayers( *prj );
for ( const QString &badLayerId : badLayerIds )
{
// if this bad layer is in restricted layers
// it doesn't need to be added to unrestricted bad layers
if ( badLayerNames.contains( badLayerId ) &&
resctrictedLayers.contains( badLayerNames.value( badLayerId ) ) )
{
continue;
}
unrestrictedBadLayers.append( badLayerId );
}
if ( !unrestrictedBadLayers.isEmpty() )
{
const QString errorMsg = QStringLiteral( "Layer(s) %1 not valid" ).arg( unrestrictedBadLayers.join( ',' ) );
QgsMessageLog::logMessage( errorMsg, QStringLiteral( "Server" ), Qgis::Critical );
throw QgsServerException( QStringLiteral( "Layer(s) not valid" ) );
}
}
mProjectCache.insert( path, prj.release() );
mFileSystemWatcher.addPath( path );
@@ -120,4 +141,3 @@ void QgsConfigCache::removeEntry( const QString &path )
{
removeChangedEntry( path );
}

@@ -29,7 +29,13 @@ void QgsStoreBadLayerInfo::handleBadLayers( const QList<QDomNode> &layers )
QDomElement idElem = it->firstChildElement( "id" );
if ( !idElem.isNull() )
{
mBadLayerIds.append( idElem.text() );
const QString badLayerId = idElem.text();
mBadLayerIds.append( badLayerId );
const QDomElement nameElem = it->firstChildElement( "layername" );
if ( !nameElem.isNull() )
{
mBadLayerNames.insert( badLayerId, nameElem.text() );
}
}
}
}
@@ -21,6 +21,7 @@
#include "qgsprojectbadlayerhandler.h"
#include "qgis_server.h"
#include <QStringList>
#include <QMap>

/**
* \ingroup server
@@ -48,8 +49,15 @@ class SERVER_EXPORT QgsStoreBadLayerInfo: public QgsProjectBadLayerHandler
*/
QStringList badLayers() const { return mBadLayerIds; }

/**
* Returns names of bad layers with ids.
* \since QGIS 3.12
*/
QMap<QString, QString> badLayerNames() const { return mBadLayerNames; }

private:
QStringList mBadLayerIds;
QMap<QString, QString> mBadLayerNames;
};

#endif // QGSSTOREBADLAYERINFO_H

0 comments on commit 85c7f92

Please sign in to comment.
You can’t perform that action at this time.