Skip to content

Commit

Permalink
Change to QGIS_SERVER_DISABLE_GETPRINT
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Aug 17, 2020
1 parent c1a9d94 commit 98741cb
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 20 deletions.
7 changes: 4 additions & 3 deletions python/server/auto_generated/qgsserversettings.sip.in
Expand Up @@ -196,12 +196,13 @@ variable QGIS_SERVER_TRUST_LAYER_METADATA.
.. versionadded:: 3.16
%End

bool dontLoadLayouts() const;
bool getPrintDisabled() const;
%Docstring
Returns ``True`` if the reading flag don't load layouts is activated.
Returns ``True`` if WMS GetPrint request is disabled and the project's
reading flag DONT_LOAD_LAYOUTS is activated.

The default value is ``False``, this value can be changed by setting the environment
variable QGIS_SERVER_DONT_LOAD_LAYOUTS.
variable QGIS_SERVER_DISABLE_GETPRINT.

.. versionadded:: 3.16
%End
Expand Down
2 changes: 1 addition & 1 deletion src/server/qgsconfigcache.cpp
Expand Up @@ -57,7 +57,7 @@ const QgsProject *QgsConfigCache::project( const QString &path, QgsServerSetting
readFlags |= QgsProject::ReadFlag::FlagTrustLayerMetadata;
}
// Activate don't load layouts flag
else if ( settings->dontLoadLayouts() )
if ( settings->getPrintDisabled() )
{
readFlags |= QgsProject::ReadFlag::FlagDontLoadLayouts;
}
Expand Down
6 changes: 3 additions & 3 deletions src/server/qgsserversettings.cpp
Expand Up @@ -175,7 +175,7 @@ void QgsServerSettings::initSettings()
mSettings[ sTrustLayerMetadata.envVar ] = sTrustLayerMetadata;

// don't load layouts
const Setting sDontLoadLayouts = { QgsServerSettingsEnv::QGIS_SERVER_DONT_LOAD_LAYOUTS,
const Setting sDontLoadLayouts = { QgsServerSettingsEnv::QGIS_SERVER_DISABLE_GETPRINT,
QgsServerSettingsEnv::DEFAULT_VALUE,
QStringLiteral( "Don't load layouts" ),
QString(),
Expand Down Expand Up @@ -462,7 +462,7 @@ bool QgsServerSettings::trustLayerMetadata() const
return value( QgsServerSettingsEnv::QGIS_SERVER_TRUST_LAYER_METADATA ).toBool();
}

bool QgsServerSettings::dontLoadLayouts() const
bool QgsServerSettings::getPrintDisabled() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_DONT_LOAD_LAYOUTS ).toBool();
return value( QgsServerSettingsEnv::QGIS_SERVER_DISABLE_GETPRINT ).toBool();
}
11 changes: 6 additions & 5 deletions src/server/qgsserversettings.h
Expand Up @@ -68,8 +68,8 @@ class SERVER_EXPORT QgsServerSettingsEnv : public QObject
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)
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).
QGIS_SERVER_API_WFS3_MAX_LIMIT, //!< Maximum value for "limit" in a features request, defaults to 10000 (since QGIS 3.10).
QGIS_SERVER_TRUST_LAYER_METADATA, //!< Trust layer metadata (since QGIS 3.16).
QGIS_SERVER_DONT_LOAD_LAYOUTS //!< Don't load layouts, this deactivated GetPrint capabilities (since QGIS 3.16).
QGIS_SERVER_TRUST_LAYER_METADATA, //!< Trust layer metadata. Improves project read time. (since QGIS 3.16).
QGIS_SERVER_DISABLE_GETPRINT //!< Disabled WMS GetPrint request and don't load layouts. Improves project read time. (since QGIS 3.16).
};
Q_ENUM( EnvVar )
};
Expand Down Expand Up @@ -247,14 +247,15 @@ class SERVER_EXPORT QgsServerSettings
bool trustLayerMetadata() const;

/**
* Returns TRUE if the reading flag don't load layouts is activated.
* Returns TRUE if WMS GetPrint request is disabled and the project's
* reading flag DONT_LOAD_LAYOUTS is activated.
*
* The default value is FALSE, this value can be changed by setting the environment
* variable QGIS_SERVER_DONT_LOAD_LAYOUTS.
* variable QGIS_SERVER_DISABLE_GETPRINT.
*
* \since QGIS 3.16
*/
bool dontLoadLayouts() const;
bool getPrintDisabled() const;

private:
void initSettings();
Expand Down
7 changes: 7 additions & 0 deletions src/server/services/wms/qgswms.cpp
Expand Up @@ -143,6 +143,13 @@ namespace QgsWms
}
else if ( QSTR_COMPARE( req, "GetPrint" ) )
{
if ( mServerIface->serverSettings() && mServerIface->serverSettings()->getPrintDisabled() )
{
// GetPrint has been disabled
QgsDebugMsg( QStringLiteral( "WMS GetPrint request called, but it has been disabled." ) );
throw QgsServiceException( QgsServiceException::OGC_OperationNotSupported,
QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
}
writeGetPrint( mServerIface, project, version, request, response );
}
else
Expand Down
7 changes: 4 additions & 3 deletions src/server/services/wms/qgswmsgetcapabilities.cpp
Expand Up @@ -230,7 +230,7 @@ namespace QgsWms
wmsCapabilitiesElement.appendChild( getServiceElement( doc, project, version, request ) );

//wms:Capability element
QDomElement capabilityElement = getCapabilityElement( doc, project, version, request, projectSettings );
QDomElement capabilityElement = getCapabilityElement( doc, project, version, request, projectSettings, serverIface );
wmsCapabilitiesElement.appendChild( capabilityElement );

if ( projectSettings )
Expand Down Expand Up @@ -431,7 +431,7 @@ namespace QgsWms

QDomElement getCapabilityElement( QDomDocument &doc, const QgsProject *project,
const QString &version, const QgsServerRequest &request,
bool projectSettings )
bool projectSettings, QgsServerInterface *serverIface )
{
QgsServerRequest::Parameters parameters = request.parameters();

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

if ( projectSettings ) //remove composer templates from GetCapabilities in the long term
if ( ( !serverIface->serverSettings() || !serverIface->serverSettings()->getPrintDisabled() ) &&
projectSettings ) //remove composer templates from GetCapabilities in the long term
{
//wms:GetPrint
elem = doc.createElement( QStringLiteral( "GetPrint" ) /*wms:GetPrint*/ );
Expand Down
3 changes: 2 additions & 1 deletion src/server/services/wms/qgswmsgetcapabilities.h
Expand Up @@ -55,7 +55,8 @@ namespace QgsWms
* Create Capability element for get capabilities document
*/
QDomElement getCapabilityElement( QDomDocument &doc, const QgsProject *project, const QString &version,
const QgsServerRequest &request, bool projectSettings );
const QgsServerRequest &request, bool projectSettings,
QgsServerInterface *serverIface );

/**
* Create Service element for get capabilities document
Expand Down
8 changes: 4 additions & 4 deletions tests/src/python/test_qgsserver_settings.py
Expand Up @@ -147,18 +147,18 @@ def test_env_trust_layer_metadata(self):
os.environ.pop(env)

def test_env_dont_load_layouts(self):
env = "QGIS_SERVER_DONT_LOAD_LAYOUTS"
env = "QGIS_SERVER_DISABLE_GETPRINT"

self.assertFalse(self.settings.dontLoadLayouts())
self.assertFalse(self.settings.getPrintDisabled())

os.environ[env] = "1"
self.settings.load()
self.assertTrue(self.settings.dontLoadLayouts())
self.assertTrue(self.settings.getPrintDisabled())
os.environ.pop(env)

os.environ[env] = "0"
self.settings.load()
self.assertFalse(self.settings.dontLoadLayouts())
self.assertFalse(self.settings.getPrintDisabled())
os.environ.pop(env)

def test_priority(self):
Expand Down

0 comments on commit 98741cb

Please sign in to comment.