Skip to content

Commit 3372a92

Browse files
authoredAug 24, 2020
Merge pull request #38240 from rldhont/server-dont-load-layouts
New QGIS Server setting environement to disable GetPrint and do not load layouts
2 parents e433ada + 98741cb commit 3372a92

File tree

8 files changed

+79
-7
lines changed

8 files changed

+79
-7
lines changed
 

‎python/server/auto_generated/qgsserversettings.sip.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ Returns ``True`` if the reading flag trust layer metadata is activated.
193193
The default value is ``False``, this value can be changed by setting the environment
194194
variable QGIS_SERVER_TRUST_LAYER_METADATA.
195195

196+
.. versionadded:: 3.16
197+
%End
198+
199+
bool getPrintDisabled() const;
200+
%Docstring
201+
Returns ``True`` if WMS GetPrint request is disabled and the project's
202+
reading flag DONT_LOAD_LAYOUTS is activated.
203+
204+
The default value is ``False``, this value can be changed by setting the environment
205+
variable QGIS_SERVER_DISABLE_GETPRINT.
206+
196207
.. versionadded:: 3.16
197208
%End
198209

‎src/server/qgsconfigcache.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,18 @@ const QgsProject *QgsConfigCache::project( const QString &path, QgsServerSetting
4949
prj->setBadLayerHandler( badLayerHandler );
5050

5151
QgsProject::ReadFlags readFlags = QgsProject::ReadFlag();
52-
if ( ! settings || ! settings->trustLayerMetadata() )
52+
if ( settings )
5353
{
54-
readFlags |= QgsProject::ReadFlag::FlagTrustLayerMetadata;
54+
// Activate trust layer metadata flag
55+
if ( settings->trustLayerMetadata() )
56+
{
57+
readFlags |= QgsProject::ReadFlag::FlagTrustLayerMetadata;
58+
}
59+
// Activate don't load layouts flag
60+
if ( settings->getPrintDisabled() )
61+
{
62+
readFlags |= QgsProject::ReadFlag::FlagDontLoadLayouts;
63+
}
5564
}
5665

5766
if ( prj->read( path, readFlags ) )

‎src/server/qgsserversettings.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ void QgsServerSettings::initSettings()
174174
};
175175
mSettings[ sTrustLayerMetadata.envVar ] = sTrustLayerMetadata;
176176

177+
// don't load layouts
178+
const Setting sDontLoadLayouts = { QgsServerSettingsEnv::QGIS_SERVER_DISABLE_GETPRINT,
179+
QgsServerSettingsEnv::DEFAULT_VALUE,
180+
QStringLiteral( "Don't load layouts" ),
181+
QString(),
182+
QVariant::Bool,
183+
QVariant( false ),
184+
QVariant()
185+
};
186+
mSettings[ sDontLoadLayouts.envVar ] = sDontLoadLayouts;
187+
177188
// show group separator
178189
const Setting sShowGroupSeparator = { QgsServerSettingsEnv::QGIS_SERVER_SHOW_GROUP_SEPARATOR,
179190
QgsServerSettingsEnv::DEFAULT_VALUE,
@@ -450,3 +461,8 @@ bool QgsServerSettings::trustLayerMetadata() const
450461
{
451462
return value( QgsServerSettingsEnv::QGIS_SERVER_TRUST_LAYER_METADATA ).toBool();
452463
}
464+
465+
bool QgsServerSettings::getPrintDisabled() const
466+
{
467+
return value( QgsServerSettingsEnv::QGIS_SERVER_DISABLE_GETPRINT ).toBool();
468+
}

‎src/server/qgsserversettings.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class SERVER_EXPORT QgsServerSettingsEnv : public QObject
6868
QGIS_SERVER_WMS_MAX_WIDTH, //!< Maximum width for a WMS request. The most conservative between this and the project one is used (since QGIS 3.6.2)
6969
QGIS_SERVER_API_RESOURCES_DIRECTORY, //!< Base directory where HTML templates and static assets (e.g. images, js and css files) are searched for (since QGIS 3.10).
7070
QGIS_SERVER_API_WFS3_MAX_LIMIT, //!< Maximum value for "limit" in a features request, defaults to 10000 (since QGIS 3.10).
71-
QGIS_SERVER_TRUST_LAYER_METADATA //!< Trust layer metadata (since QGIS 3.16).
71+
QGIS_SERVER_TRUST_LAYER_METADATA, //!< Trust layer metadata. Improves project read time. (since QGIS 3.16).
72+
QGIS_SERVER_DISABLE_GETPRINT //!< Disabled WMS GetPrint request and don't load layouts. Improves project read time. (since QGIS 3.16).
7273
};
7374
Q_ENUM( EnvVar )
7475
};
@@ -245,6 +246,17 @@ class SERVER_EXPORT QgsServerSettings
245246
*/
246247
bool trustLayerMetadata() const;
247248

249+
/**
250+
* Returns TRUE if WMS GetPrint request is disabled and the project's
251+
* reading flag DONT_LOAD_LAYOUTS is activated.
252+
*
253+
* The default value is FALSE, this value can be changed by setting the environment
254+
* variable QGIS_SERVER_DISABLE_GETPRINT.
255+
*
256+
* \since QGIS 3.16
257+
*/
258+
bool getPrintDisabled() const;
259+
248260
private:
249261
void initSettings();
250262
QVariant value( QgsServerSettingsEnv::EnvVar envVar ) const;

‎src/server/services/wms/qgswms.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ namespace QgsWms
143143
}
144144
else if ( QSTR_COMPARE( req, "GetPrint" ) )
145145
{
146+
if ( mServerIface->serverSettings() && mServerIface->serverSettings()->getPrintDisabled() )
147+
{
148+
// GetPrint has been disabled
149+
QgsDebugMsg( QStringLiteral( "WMS GetPrint request called, but it has been disabled." ) );
150+
throw QgsServiceException( QgsServiceException::OGC_OperationNotSupported,
151+
QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
152+
}
146153
writeGetPrint( mServerIface, project, version, request, response );
147154
}
148155
else

‎src/server/services/wms/qgswmsgetcapabilities.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ namespace QgsWms
230230
wmsCapabilitiesElement.appendChild( getServiceElement( doc, project, version, request ) );
231231

232232
//wms:Capability element
233-
QDomElement capabilityElement = getCapabilityElement( doc, project, version, request, projectSettings );
233+
QDomElement capabilityElement = getCapabilityElement( doc, project, version, request, projectSettings, serverIface );
234234
wmsCapabilitiesElement.appendChild( capabilityElement );
235235

236236
if ( projectSettings )
@@ -431,7 +431,7 @@ namespace QgsWms
431431

432432
QDomElement getCapabilityElement( QDomDocument &doc, const QgsProject *project,
433433
const QString &version, const QgsServerRequest &request,
434-
bool projectSettings )
434+
bool projectSettings, QgsServerInterface *serverIface )
435435
{
436436
QgsServerRequest::Parameters parameters = request.parameters();
437437

@@ -534,7 +534,8 @@ namespace QgsWms
534534
elem.appendChild( dcpTypeElem.cloneNode().toElement() ); //this is the same as for 'GetCapabilities'
535535
requestElem.appendChild( elem );
536536

537-
if ( projectSettings ) //remove composer templates from GetCapabilities in the long term
537+
if ( ( !serverIface->serverSettings() || !serverIface->serverSettings()->getPrintDisabled() ) &&
538+
projectSettings ) //remove composer templates from GetCapabilities in the long term
538539
{
539540
//wms:GetPrint
540541
elem = doc.createElement( QStringLiteral( "GetPrint" ) /*wms:GetPrint*/ );

‎src/server/services/wms/qgswmsgetcapabilities.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ namespace QgsWms
5555
* Create Capability element for get capabilities document
5656
*/
5757
QDomElement getCapabilityElement( QDomDocument &doc, const QgsProject *project, const QString &version,
58-
const QgsServerRequest &request, bool projectSettings );
58+
const QgsServerRequest &request, bool projectSettings,
59+
QgsServerInterface *serverIface );
5960

6061
/**
6162
* Create Service element for get capabilities document

‎tests/src/python/test_qgsserver_settings.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,21 @@ def test_env_trust_layer_metadata(self):
146146
self.assertFalse(self.settings.trustLayerMetadata())
147147
os.environ.pop(env)
148148

149+
def test_env_dont_load_layouts(self):
150+
env = "QGIS_SERVER_DISABLE_GETPRINT"
151+
152+
self.assertFalse(self.settings.getPrintDisabled())
153+
154+
os.environ[env] = "1"
155+
self.settings.load()
156+
self.assertTrue(self.settings.getPrintDisabled())
157+
os.environ.pop(env)
158+
159+
os.environ[env] = "0"
160+
self.settings.load()
161+
self.assertFalse(self.settings.getPrintDisabled())
162+
os.environ.pop(env)
163+
149164
def test_priority(self):
150165
env = "QGIS_OPTIONS_PATH"
151166
dpath = "conf0"

0 commit comments

Comments
 (0)
Please sign in to comment.