Skip to content

Commit

Permalink
[server][wfs] Fix getcap not allowing updates on aspatial layers
Browse files Browse the repository at this point in the history
Fix #60185
  • Loading branch information
elpaso authored and github-actions[bot] committed Jan 25, 2025
1 parent c71dee8 commit 6814e28
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/server/services/wfs/qgswfsgetcapabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ namespace QgsWfs
operationsElement.appendChild( operationElement );
}

if ( ( provider->capabilities() & Qgis::VectorProviderCapability::ChangeAttributeValues ) && ( provider->capabilities() & Qgis::VectorProviderCapability::ChangeGeometries ) && wfstUpdateLayersId.contains( layer->id() ) )
if ( ( provider->capabilities() & Qgis::VectorProviderCapability::ChangeAttributeValues ) && ( !layer->isSpatial() || provider->capabilities() & Qgis::VectorProviderCapability::ChangeGeometries ) && wfstUpdateLayersId.contains( layer->id() ) )
{
//wfs:Update element
QDomElement operationElement = doc.createElement( QStringLiteral( "Operation" ) );
Expand Down
37 changes: 36 additions & 1 deletion tests/src/python/test_qgsserver_wfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@
QgsGeometry,
QgsProject,
QgsVectorLayer,
QgsMemoryProviderUtils,
QgsWkbTypes,
QgsVectorDataProvider,
QgsFields,
QgsField,
)
from qgis.server import QgsServerRequest
from qgis.server import QgsServerRequest, QgsServer, QgsBufferServerResponse
from qgis.testing import unittest
from test_qgsserver import QgsServerTestBase
from qgis.PyQt.QtCore import QVariant, QUrl

# Strip path and content length because path may vary
RE_STRIP_UNCHECKABLE = rb'MAP=[^"]+|Content-Length: \d+|timeStamp="[^"]+"'
Expand Down Expand Up @@ -1531,5 +1537,34 @@ def test_GetFeature_with_datetime(self):
)


def test_wfs_aspatial_getcapabilities(self):
### Test issue GH #60185 - WFS GetCapabilities for aspatial layers"""

# create a memory layer with no geometry
fields = QgsFields()
fields.append(QgsField('id', QVariant.Int))
fields.append(QgsField('name', QVariant.String))
layer = QgsMemoryProviderUtils.createMemoryLayer('no_geom', fields, QgsWkbTypes.NoGeometry)

provider = layer.dataProvider()
self.assertTrue(layer.isValid())
self.assertFalse(layer.isSpatial())
self.assertFalse(provider.capabilities( ) & QgsVectorDataProvider.Capability.ChangeGeometries)

project = QgsProject()
project.addMapLayer(layer)
project.writeEntry( "WFSLayers" , "/", [layer.id()] )
project.writeEntry( "WFSTLayers" , "Update", [layer.id()] )
project.writeEntry( "WFSTLayers" , "Insert", [layer.id()] )
project.writeEntry( "WFSTLayers" , "Delete", [layer.id()] )

server = QgsServer()
request = QgsServerRequest()
request.setUrl(QUrl("?SERVICE=WFS&REQUEST=GetCapabilities"))
response = QgsBufferServerResponse()
server.handleRequest(request, response, project)
body = response.body().data().decode("utf8").replace("\n", "")
self.assertIn("<Operation>Update</Operation>", body)

if __name__ == "__main__":
unittest.main()

0 comments on commit 6814e28

Please sign in to comment.