Skip to content

Commit

Permalink
Merge pull request #3745 from mhugent/server_datasources
Browse files Browse the repository at this point in the history
WMS server: add user setting if custom datasources are allowed in wms…
  • Loading branch information
mhugent committed Nov 10, 2016
2 parents 73b283c + 88587fd commit 1cd1158
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 26 deletions.
2 changes: 2 additions & 0 deletions python/server/qgswmsconfigparser.sip
Expand Up @@ -123,6 +123,8 @@ class QgsWmsConfigParser

virtual bool useLayerIds() const = 0;

virtual bool allowRequestDefinedDatasources() const;

private:

QgsWmsConfigParser();
Expand Down
2 changes: 2 additions & 0 deletions python/server/qgswmsprojectparser.sip
Expand Up @@ -111,6 +111,8 @@ class QgsWmsProjectParser : public QgsWmsConfigParser

bool useLayerIds() const /*override*/ ;

bool allowRequestDefinedDatasources() const;

private:

/** Returns an ID-list of layers which are not queryable (comes from <properties> -> <Identify> -> <disabledLayers in the project file*/
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -527,6 +527,9 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
bool addWktGeometry = QgsProject::instance()->readBoolEntry( QStringLiteral( "WMSAddWktGeometry" ), QStringLiteral( "/" ) );
mAddWktGeometryCheckBox->setChecked( addWktGeometry );

bool requestDefinedSources = QgsProject::instance()->readBoolEntry( "WMSRequestDefinedDataSources", "/", false );
mAllowRequestDefinedDataSourcesBox->setChecked( requestDefinedSources );

bool segmentizeFeatureInfoGeometry = QgsProject::instance()->readBoolEntry( QStringLiteral( "WMSSegmentizeFeatureInfoGeometry" ), QStringLiteral( "/" ) );
mSegmentizeFeatureInfoGeometryCheckBox->setChecked( segmentizeFeatureInfoGeometry );

Expand Down Expand Up @@ -1077,6 +1080,7 @@ void QgsProjectProperties::apply()
}

QgsProject::instance()->writeEntry( QStringLiteral( "WMSAddWktGeometry" ), QStringLiteral( "/" ), mAddWktGeometryCheckBox->isChecked() );
QgsProject::instance()->writeEntry( "WMSRequestDefinedDataSources", "/", mAllowRequestDefinedDataSourcesBox->isChecked() );
QgsProject::instance()->writeEntry( QStringLiteral( "WMSSegmentizeFeatureInfoGeometry" ), QStringLiteral( "/" ), mSegmentizeFeatureInfoGeometryCheckBox->isChecked() );
QgsProject::instance()->writeEntry( QStringLiteral( "WMSUseLayerIDs" ), QStringLiteral( "/" ), mWmsUseLayerIDs->isChecked() );

Expand Down
21 changes: 21 additions & 0 deletions src/server/qgssldconfigparser.cpp
Expand Up @@ -20,6 +20,7 @@
#include "qgsconfigparserutils.h"
#include "qgslogger.h"
#include "qgsmapserviceexception.h"
#include "qgsmessagelog.h"
#include "qgsrasterlayer.h"
#include "qgsrenderer.h"
#include "qgssinglesymbolrenderer.h"
Expand Down Expand Up @@ -1204,6 +1205,17 @@ QDomElement QgsSLDConfigParser::findUserLayerElement( const QString& layerName )

QgsMapLayer* QgsSLDConfigParser::mapLayerFromUserLayer( const QDomElement& userLayerElem, const QString& layerName, bool allowCaching ) const
{
if ( !mFallbackParser )
{
return 0;
}

if ( !mFallbackParser->allowRequestDefinedDatasources() )
{
QgsMessageLog::logMessage( "The project configuration does not allow datasources defined in the request", "Server", QgsMessageLog::CRITICAL );
return 0;
}

QgsDebugMsg( "Entering." );
QgsMSLayerBuilder* layerBuilder = nullptr;
QDomElement builderRootElement;
Expand Down Expand Up @@ -1358,6 +1370,15 @@ void QgsSLDConfigParser::setCrsForLayer( const QDomElement& layerElem, QgsMapLay
}
}

bool QgsSLDConfigParser::allowRequestDefinedDatasources() const
{
if ( mFallbackParser )
{
return mFallbackParser->allowRequestDefinedDatasources();
}
return false;
}




Expand Down
2 changes: 2 additions & 0 deletions src/server/qgssldconfigparser.h
Expand Up @@ -133,6 +133,8 @@ class QgsSLDConfigParser : public QgsWmsConfigParser

void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const override;

bool allowRequestDefinedDatasources() const override;

private:

//! SLD as dom document
Expand Down
2 changes: 2 additions & 0 deletions src/server/qgswmsconfigparser.h
Expand Up @@ -139,6 +139,8 @@ class SERVER_EXPORT QgsWmsConfigParser

virtual bool useLayerIds() const = 0;

virtual bool allowRequestDefinedDatasources() const { return false; }

//! Adds highlight layers to the layer registry and to the layer set. Returns the ids of the newly created layers (for later removal)
static QStringList addHighlightLayers( const QMap<QString, QString>& parameterMap, QStringList& layerSet, const QString& parameterPrefix = QString() );
static void removeHighlightLayers( const QStringList& layerIds );
Expand Down
21 changes: 21 additions & 0 deletions src/server/qgswmsprojectparser.cpp
Expand Up @@ -2488,3 +2488,24 @@ QString QgsWmsProjectParser::getCapaServiceUrl( QDomDocument& doc ) const

return url;
}

bool QgsWmsProjectParser::allowRequestDefinedDatasources() const
{
if ( !mProjectParser->xmlDocument() )
{
return false;
}

QDomElement propertiesElem = mProjectParser->propertiesElem();
if ( propertiesElem.isNull() )
{
return false;
}
QDomElement dsElem = propertiesElem.firstChildElement( "WMSRequestDefinedDataSources" );
if ( dsElem.isNull() )
{
return false;
}

return ( dsElem.text().compare( "true", Qt::CaseInsensitive ) == 0 );
}
2 changes: 2 additions & 0 deletions src/server/qgswmsprojectparser.h
Expand Up @@ -127,6 +127,8 @@ class SERVER_EXPORT QgsWmsProjectParser : public QgsWmsConfigParser

bool useLayerIds() const override { return mProjectParser->useLayerIds(); }

bool allowRequestDefinedDatasources() const override;

private:
QgsServerProjectParser* mProjectParser;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
Expand Down
5 changes: 5 additions & 0 deletions src/server/qgswmsserver.cpp
Expand Up @@ -1894,6 +1894,11 @@ QImage* QgsWmsServer::initializeRendering( QStringList& layersList, QStringList&
QString gml = mParameters.value( QStringLiteral( "GML" ) );
if ( !gml.isEmpty() )
{
if ( !mConfigParser->allowRequestDefinedDatasources() )
{
QgsMessageLog::logMessage( "The project configuration does not allow datasources defined in the request", "Server", QgsMessageLog::CRITICAL );
return 0;
}
QDomDocument* gmlDoc = new QDomDocument();
if ( gmlDoc->setContent( gml, true ) )
{
Expand Down
59 changes: 33 additions & 26 deletions src/ui/qgsprojectpropertiesbase.ui
Expand Up @@ -1238,7 +1238,7 @@
</widget>
</item>
<item row="0" column="0" rowspan="8">
<widget class="QgsColorSchemeList" name="mTreeProjectColors" native="true"/>
<widget class="QgsColorSchemeList" name="mTreeProjectColors"/>
</item>
<item row="4" column="1">
<widget class="QToolButton" name="mButtonImportColors">
Expand Down Expand Up @@ -1294,9 +1294,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-961</y>
<y>-912</y>
<width>674</width>
<height>2470</height>
<height>2497</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
Expand Down Expand Up @@ -1845,7 +1845,7 @@
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<item row="12" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLabel" name="mWMSImageQualityLabel">
Expand Down Expand Up @@ -1879,7 +1879,7 @@
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<item row="11" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="1">
<widget class="QLabel" name="mMaxWidthLabel">
Expand Down Expand Up @@ -1926,7 +1926,7 @@
</item>
</layout>
</item>
<item row="8" column="0" colspan="2">
<item row="9" column="0" colspan="2">
<layout class="QHBoxLayout" name="grpWMSPrecision">
<item>
<widget class="QLabel" name="label_5">
Expand All @@ -1950,7 +1950,7 @@
</item>
</layout>
</item>
<item row="9" column="0" colspan="2">
<item row="10" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="mWMSUrlLabel">
Expand Down Expand Up @@ -2096,13 +2096,20 @@
</layout>
</widget>
</item>
<item row="7" column="0">
<item row="8" column="0">
<widget class="QCheckBox" name="mSegmentizeFeatureInfoGeometryCheckBox">
<property name="text">
<string>Segmentize feature info geometry</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="mAllowRequestDefinedDataSourcesBox">
<property name="text">
<string>Allow defining datasources in server requests</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -2359,8 +2366,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>694</width>
<height>779</height>
<width>141</width>
<height>54</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
Expand Down Expand Up @@ -2486,39 +2493,39 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<class>QgsProjectionSelector</class>
<extends>QWidget</extends>
<header>qgsprojectionselector.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorSchemeList</class>
<class>QgsCodeEditorPython</class>
<extends>QWidget</extends>
<header location="global">qgscolorschemelist.h</header>
<header>qgscodeeditorpython.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsVariableEditorWidget</class>
<extends>QWidget</extends>
<header location="global">qgsvariableeditorwidget.h</header>
<class>QgsColorSchemeList</class>
<extends>QTreeView</extends>
<header>qgscolorschemelist.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsCodeEditorPython</class>
<extends>QWidget</extends>
<header>qgscodeeditorpython.h</header>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsProjectionSelector</class>
<class>QgsVariableEditorWidget</class>
<extends>QWidget</extends>
<header>qgsprojectionselector.h</header>
<header location="global">qgsvariableeditorwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
Expand Down

0 comments on commit 1cd1158

Please sign in to comment.