mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
Merge pull request #38240 from rldhont/server-dont-load-layouts
New QGIS Server setting environement to disable GetPrint and do not load layouts
This commit is contained in:
commit
3372a9267d
@ -193,6 +193,17 @@ Returns ``True`` if the reading flag trust layer metadata is activated.
|
||||
The default value is ``False``, this value can be changed by setting the environment
|
||||
variable QGIS_SERVER_TRUST_LAYER_METADATA.
|
||||
|
||||
.. versionadded:: 3.16
|
||||
%End
|
||||
|
||||
bool getPrintDisabled() const;
|
||||
%Docstring
|
||||
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_DISABLE_GETPRINT.
|
||||
|
||||
.. versionadded:: 3.16
|
||||
%End
|
||||
|
||||
|
@ -49,9 +49,18 @@ const QgsProject *QgsConfigCache::project( const QString &path, QgsServerSetting
|
||||
prj->setBadLayerHandler( badLayerHandler );
|
||||
|
||||
QgsProject::ReadFlags readFlags = QgsProject::ReadFlag();
|
||||
if ( ! settings || ! settings->trustLayerMetadata() )
|
||||
if ( settings )
|
||||
{
|
||||
readFlags |= QgsProject::ReadFlag::FlagTrustLayerMetadata;
|
||||
// Activate trust layer metadata flag
|
||||
if ( settings->trustLayerMetadata() )
|
||||
{
|
||||
readFlags |= QgsProject::ReadFlag::FlagTrustLayerMetadata;
|
||||
}
|
||||
// Activate don't load layouts flag
|
||||
if ( settings->getPrintDisabled() )
|
||||
{
|
||||
readFlags |= QgsProject::ReadFlag::FlagDontLoadLayouts;
|
||||
}
|
||||
}
|
||||
|
||||
if ( prj->read( path, readFlags ) )
|
||||
|
@ -174,6 +174,17 @@ void QgsServerSettings::initSettings()
|
||||
};
|
||||
mSettings[ sTrustLayerMetadata.envVar ] = sTrustLayerMetadata;
|
||||
|
||||
// don't load layouts
|
||||
const Setting sDontLoadLayouts = { QgsServerSettingsEnv::QGIS_SERVER_DISABLE_GETPRINT,
|
||||
QgsServerSettingsEnv::DEFAULT_VALUE,
|
||||
QStringLiteral( "Don't load layouts" ),
|
||||
QString(),
|
||||
QVariant::Bool,
|
||||
QVariant( false ),
|
||||
QVariant()
|
||||
};
|
||||
mSettings[ sDontLoadLayouts.envVar ] = sDontLoadLayouts;
|
||||
|
||||
// show group separator
|
||||
const Setting sShowGroupSeparator = { QgsServerSettingsEnv::QGIS_SERVER_SHOW_GROUP_SEPARATOR,
|
||||
QgsServerSettingsEnv::DEFAULT_VALUE,
|
||||
@ -450,3 +461,8 @@ bool QgsServerSettings::trustLayerMetadata() const
|
||||
{
|
||||
return value( QgsServerSettingsEnv::QGIS_SERVER_TRUST_LAYER_METADATA ).toBool();
|
||||
}
|
||||
|
||||
bool QgsServerSettings::getPrintDisabled() const
|
||||
{
|
||||
return value( QgsServerSettingsEnv::QGIS_SERVER_DISABLE_GETPRINT ).toBool();
|
||||
}
|
||||
|
@ -68,7 +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_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 )
|
||||
};
|
||||
@ -245,6 +246,17 @@ class SERVER_EXPORT QgsServerSettings
|
||||
*/
|
||||
bool trustLayerMetadata() const;
|
||||
|
||||
/**
|
||||
* 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_DISABLE_GETPRINT.
|
||||
*
|
||||
* \since QGIS 3.16
|
||||
*/
|
||||
bool getPrintDisabled() const;
|
||||
|
||||
private:
|
||||
void initSettings();
|
||||
QVariant value( QgsServerSettingsEnv::EnvVar envVar ) const;
|
||||
|
@ -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
|
||||
|
@ -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 )
|
||||
@ -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();
|
||||
|
||||
@ -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*/ );
|
||||
|
@ -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
|
||||
|
@ -146,6 +146,21 @@ class TestQgsServerSettings(unittest.TestCase):
|
||||
self.assertFalse(self.settings.trustLayerMetadata())
|
||||
os.environ.pop(env)
|
||||
|
||||
def test_env_dont_load_layouts(self):
|
||||
env = "QGIS_SERVER_DISABLE_GETPRINT"
|
||||
|
||||
self.assertFalse(self.settings.getPrintDisabled())
|
||||
|
||||
os.environ[env] = "1"
|
||||
self.settings.load()
|
||||
self.assertTrue(self.settings.getPrintDisabled())
|
||||
os.environ.pop(env)
|
||||
|
||||
os.environ[env] = "0"
|
||||
self.settings.load()
|
||||
self.assertFalse(self.settings.getPrintDisabled())
|
||||
os.environ.pop(env)
|
||||
|
||||
def test_priority(self):
|
||||
env = "QGIS_OPTIONS_PATH"
|
||||
dpath = "conf0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user