Skip to content

Commit

Permalink
Merge pull request #9291 from dmarteau/fix-HAVE_SERVER_PYTHON_PLUGINS
Browse files Browse the repository at this point in the history
Fix build without HAVE_SERVER_PYTHON_PLUGINS
  • Loading branch information
m-kuhn committed Apr 3, 2019
2 parents 80a4fc9 + e839f27 commit e043954
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 77 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Expand Up @@ -128,10 +128,14 @@ IF(WITH_CORE)
IF(WITH_SERVER)
SET (SERVER_SKIP_ECW FALSE CACHE BOOL "Determines whether QGIS server should disable ECW (ECW in server apps requires a special license)")

SET (WITH_SERVER_PLUGINS TRUE CACHE BOOL "Determines whether QGIS server support for python plugins should be built")
SET (WITH_SERVER_PLUGINS ${WITH_BINDINGS} CACHE BOOL "Determines whether QGIS server support for python plugins should be built")
IF(WITH_SERVER_PLUGINS AND NOT WITH_BINDINGS)
MESSAGE(FATAL_ERROR "Server plugins are not supported without python bindings. Enable WITH_BINDINGS or disable WITH_SERVER_PLUGINS")
ENDIF(WITH_SERVER_PLUGINS AND NOT WITH_BINDINGS)
IF(WITH_SERVER_PLUGINS)
SET(HAVE_SERVER_PYTHON_PLUGINS TRUE)
ENDIF(WITH_SERVER_PLUGINS)

ENDIF(WITH_SERVER)

# Custom widgets
Expand Down
6 changes: 3 additions & 3 deletions src/server/qgsserverinterfaceimpl.cpp
Expand Up @@ -29,7 +29,7 @@ QgsServerInterfaceImpl::QgsServerInterfaceImpl( QgsCapabilitiesCache *capCache,
mRequestHandler = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
mAccessControls = new QgsAccessControl();
mCacheManager.reset( new QgsServerCacheManager() );
mCacheManager = new QgsServerCacheManager();
#endif
}

Expand All @@ -43,7 +43,7 @@ QgsServerInterfaceImpl::~QgsServerInterfaceImpl()
{
#ifdef HAVE_SERVER_PYTHON_PLUGINS
delete mAccessControls;
mCacheManager.reset();
delete mCacheManager;
#endif
}

Expand Down Expand Up @@ -97,7 +97,7 @@ void QgsServerInterfaceImpl::registerServerCache( QgsServerCacheFilter *serverCa

QgsServerCacheManager *QgsServerInterfaceImpl::cacheManager() const
{
return mCacheManager.get();
return mCacheManager;
}

void QgsServerInterfaceImpl::removeConfigCacheEntry( const QString &path )
Expand Down
2 changes: 1 addition & 1 deletion src/server/qgsserverinterfaceimpl.h
Expand Up @@ -92,7 +92,7 @@ class SERVER_EXPORT QgsServerInterfaceImpl : public QgsServerInterface
QString mConfigFilePath;
QgsServerFiltersMap mFilters;
QgsAccessControl *mAccessControls = nullptr;
std::unique_ptr<QgsServerCacheManager> mCacheManager = nullptr;
QgsServerCacheManager *mCacheManager = nullptr;
QgsCapabilitiesCache *mCapabilitiesCache = nullptr;
QgsRequestHandler *mRequestHandler = nullptr;
QgsServiceRegistry *mServiceRegistry = nullptr;
Expand Down
5 changes: 3 additions & 2 deletions src/server/services/wcs/qgswcsdescribecoverage.cpp
Expand Up @@ -43,7 +43,6 @@ namespace QgsWcs
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
describeDocument = &doc;
Expand All @@ -58,7 +57,9 @@ namespace QgsWcs
}
describeDocument = &doc;
}

#else
doc = createDescribeCoverageDocument( serverIface, project, version, request );
#endif
response.setHeader( "Content-Type", "text/xml; charset=utf-8" );
response.write( describeDocument->toByteArray() );
}
Expand Down
5 changes: 3 additions & 2 deletions src/server/services/wcs/qgswcsgetcapabilities.cpp
Expand Up @@ -42,7 +42,6 @@ namespace QgsWcs
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
capabilitiesDocument = &doc;
Expand All @@ -57,7 +56,9 @@ namespace QgsWcs
}
capabilitiesDocument = &doc;
}

#else
doc = createGetCapabilitiesDocument( serverIface, project, version, request );
#endif
response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) );
response.write( capabilitiesDocument->toByteArray() );
}
Expand Down
9 changes: 5 additions & 4 deletions src/server/services/wfs/qgswfsdescribefeaturetype.cpp
Expand Up @@ -44,7 +44,6 @@ namespace QgsWfs
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
describeDocument = &doc;
Expand All @@ -59,7 +58,9 @@ namespace QgsWfs
}
describeDocument = &doc;
}

#else
doc = createDescribeFeatureTypeDocument( serverIface, project, version, request );
#endif
response.setHeader( "Content-Type", "text/xml; charset=utf-8" );
response.write( describeDocument->toByteArray() );
}
Expand Down Expand Up @@ -152,7 +153,7 @@ namespace QgsWfs
{
continue;
}

#ifdef HAVE_SERVER_PYTHON_PLUGINS
if ( accessControl && !accessControl->layerReadPermission( layer ) )
{
if ( !typeNameList.isEmpty() )
Expand All @@ -164,7 +165,7 @@ namespace QgsWfs
continue;
}
}

#endif
QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );
QgsVectorDataProvider *provider = vLayer->dataProvider();
if ( !provider )
Expand Down
8 changes: 5 additions & 3 deletions src/server/services/wfs/qgswfsgetcapabilities.cpp
Expand Up @@ -48,7 +48,6 @@ namespace QgsWfs
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
capabilitiesDocument = &doc;
Expand All @@ -63,7 +62,9 @@ namespace QgsWfs
}
capabilitiesDocument = &doc;
}

#else
doc = createGetCapabilitiesDocument( serverIface, project, version, request );
#endif
response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) );
response.write( capabilitiesDocument->toByteArray() );
}
Expand Down Expand Up @@ -458,11 +459,12 @@ namespace QgsWfs
{
continue;
}
#ifdef HAVE_SERVER_PYTHON_PLUGINS
if ( accessControl && !accessControl->layerReadPermission( layer ) )
{
continue;
}

#endif
QDomElement layerElem = doc.createElement( QStringLiteral( "FeatureType" ) );

//create Name
Expand Down
8 changes: 5 additions & 3 deletions src/server/services/wfs/qgswfsgetcapabilities_1_0_0.cpp
Expand Up @@ -49,7 +49,6 @@ namespace QgsWfs
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
capabilitiesDocument = &doc;
Expand All @@ -64,7 +63,9 @@ namespace QgsWfs
}
capabilitiesDocument = &doc;
}

#else
doc = createGetCapabilitiesDocument( serverIface, project, version, request );
#endif
response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) );
response.write( capabilitiesDocument->toByteArray() );
}
Expand Down Expand Up @@ -294,11 +295,12 @@ namespace QgsWfs
{
continue;
}
#ifdef HAVE_SERVER_PYTHON_PLUGINS
if ( accessControl && !accessControl->layerReadPermission( layer ) )
{
continue;
}

#endif
QDomElement layerElem = doc.createElement( QStringLiteral( "FeatureType" ) );

//create Name
Expand Down
13 changes: 8 additions & 5 deletions src/server/services/wfs/qgswfsgetfeature.cpp
Expand Up @@ -179,9 +179,11 @@ namespace QgsWfs

QgsAccessControl *accessControl = serverIface->accessControls();

#ifdef HAVE_SERVER_PYTHON_PLUGINS
//scoped pointer to restore all original layer filters (subsetStrings) when pointer goes out of scope
//there's LOTS of potential exit paths here, so we avoid having to restore the filters manually
std::unique_ptr< QgsOWSServerFilterRestorer > filterRestorer( new QgsOWSServerFilterRestorer() );
#endif

// features counters
long sentFeatures = 0;
Expand All @@ -200,11 +202,12 @@ namespace QgsWfs
}

QgsMapLayer *layer = mapLayerMap[typeName];
#ifdef HAVE_SERVER_PYTHON_PLUGINS
if ( accessControl && !accessControl->layerReadPermission( layer ) )
{
throw QgsSecurityAccessException( QStringLiteral( "Feature access permission denied" ) );
}

#endif
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( !vlayer )
{
Expand All @@ -217,12 +220,12 @@ namespace QgsWfs
{
throw QgsRequestNotWellFormedException( QStringLiteral( "TypeName '%1' layer's provider error" ).arg( typeName ) );
}

#ifdef HAVE_SERVER_PYTHON_PLUGINS
if ( accessControl )
{
QgsOWSServerFilterRestorer::applyAccessControlLayerFilters( accessControl, vlayer, filterRestorer->originalFilters() );
}

#endif
//is there alias info for this vector layer?
QMap< int, QString > layerAliasInfo;
QgsStringMap aliasMap = vlayer->attributeAliases();
Expand Down Expand Up @@ -312,7 +315,7 @@ namespace QgsWfs
featureRequest.setFlags( featureRequest.flags() | ( withGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) );
// subset of attributes
featureRequest.setSubsetOfAttributes( attrIndexes );

#ifdef HAVE_SERVER_PYTHON_PLUGINS
if ( accessControl )
{
accessControl->filterFeatures( vlayer, featureRequest );
Expand All @@ -326,7 +329,7 @@ namespace QgsWfs
accessControl->layerAttributes( vlayer, attributes ),
vlayer->fields() );
}

#endif
if ( onlyOneLayer )
{
requestPrecision = QgsServerProjectUtils::wfsLayerPrecision( *project, vlayer->id() );
Expand Down
24 changes: 18 additions & 6 deletions src/server/services/wfs/qgswfstransaction.cpp
Expand Up @@ -299,6 +299,7 @@ namespace QgsWfs
{
throw QgsSecurityAccessException( QStringLiteral( "No permissions to do WFS changes on layer '%1'" ).arg( name ) );
}
#ifdef HAVE_SERVER_PYTHON_PLUGINS
if ( accessControl && !accessControl->layerUpdatePermission( vlayer )
&& !accessControl->layerDeletePermission( vlayer ) && !accessControl->layerInsertPermission( vlayer ) )
{
Expand All @@ -309,7 +310,7 @@ namespace QgsWfs
{
QgsOWSServerFilterRestorer::applyAccessControlLayerFilters( accessControl, vlayer, filterRestorer->originalFilters() );
}

#endif
// store layers
mapLayerMap[name] = vlayer;
}
Expand Down Expand Up @@ -338,13 +339,14 @@ namespace QgsWfs
action.errorMsg = QStringLiteral( "No permissions to do WFS updates on layer '%1'" ).arg( typeName );
continue;
}
#ifdef HAVE_SERVER_PYTHON_PLUGINS
if ( accessControl && !accessControl->layerUpdatePermission( vlayer ) )
{
action.error = true;
action.errorMsg = QStringLiteral( "No permissions to do WFS updates on layer '%1'" ).arg( typeName );
continue;
}

#endif
//get provider
QgsVectorDataProvider *provider = vlayer->dataProvider();

Expand All @@ -368,12 +370,12 @@ namespace QgsWfs
<< QgsExpressionContextUtils::projectScope( project )
<< QgsExpressionContextUtils::layerScope( vlayer );
featureRequest.setExpressionContext( expressionContext );

#ifdef HAVE_SERVER_PYTHON_PLUGINS
if ( accessControl )
{
accessControl->filterFeatures( vlayer, featureRequest );
}

#endif
// get iterator
QgsFeatureIterator fit = vlayer->getFeatures( featureRequest );
QgsFeature feature;
Expand All @@ -390,13 +392,15 @@ namespace QgsWfs
// Update the features
while ( fit.nextFeature( feature ) )
{
#ifdef HAVE_SERVER_PYTHON_PLUGINS
if ( accessControl && !accessControl->allowToEdit( vlayer, feature ) )
{
action.error = true;
action.errorMsg = QStringLiteral( "Feature modify permission denied on layer '%1'" ).arg( typeName );
vlayer->rollBack();
break;
}
#endif
QMap< QString, QString >::const_iterator it = propertyMap.constBegin();
for ( ; it != propertyMap.constEnd(); ++it )
{
Expand Down Expand Up @@ -485,6 +489,7 @@ namespace QgsWfs
{
continue;
}
#ifdef HAVE_SERVER_PYTHON_PLUGINS
// verifying changes
if ( accessControl )
{
Expand All @@ -500,6 +505,7 @@ namespace QgsWfs
}
}
}
#endif
if ( action.error )
{
continue;
Expand Down Expand Up @@ -543,13 +549,14 @@ namespace QgsWfs
action.errorMsg = QStringLiteral( "No permissions to do WFS deletes on layer '%1'" ).arg( typeName );
continue;
}
#ifdef HAVE_SERVER_PYTHON_PLUGINS
if ( accessControl && !accessControl->layerDeletePermission( vlayer ) )
{
action.error = true;
action.errorMsg = QStringLiteral( "No permissions to do WFS deletes on layer '%1'" ).arg( typeName );
continue;
}

#endif
//get provider
QgsVectorDataProvider *provider = vlayer->dataProvider();

Expand Down Expand Up @@ -581,13 +588,15 @@ namespace QgsWfs
QgsFeatureIds fids;
while ( fit.nextFeature( feature ) )
{
#ifdef HAVE_SERVER_PYTHON_PLUGINS
if ( accessControl && !accessControl->allowToEdit( vlayer, feature ) )
{
action.error = true;
action.errorMsg = QStringLiteral( "Feature modify permission denied" );
vlayer->rollBack();
break;
}
#endif
fids << feature.id();
}
if ( action.error )
Expand Down Expand Up @@ -640,13 +649,14 @@ namespace QgsWfs
action.errorMsg = QStringLiteral( "No permissions to do WFS inserts on layer '%1'" ).arg( typeName );
continue;
}
#ifdef HAVE_SERVER_PYTHON_PLUGINS
if ( accessControl && !accessControl->layerDeletePermission( vlayer ) )
{
action.error = true;
action.errorMsg = QStringLiteral( "No permissions to do WFS inserts on layer '%1'" ).arg( typeName );
continue;
}

#endif
//get provider
QgsVectorDataProvider *provider = vlayer->dataProvider();

Expand Down Expand Up @@ -674,6 +684,7 @@ namespace QgsWfs
action.errorMsg = QStringLiteral( "%1 '%2'" ).arg( ex.message() ).arg( typeName );
continue;
}
#ifdef HAVE_SERVER_PYTHON_PLUGINS
// control features
if ( accessControl )
{
Expand All @@ -690,6 +701,7 @@ namespace QgsWfs
featureIt++;
}
}
#endif
if ( action.error )
{
continue;
Expand Down

0 comments on commit e043954

Please sign in to comment.