Skip to content

Commit

Permalink
Add different output format to the GetSubsetString request
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Apr 13, 2023
1 parent a5cbd4e commit d663929
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

* Add `FILTER_TYPE` to the `GETSUBSETSTRING` request with different values : `SQL` default value, `SAFESQL` or `EXPRESSION`

## 2.7.0 - 2023-03-16

* Always provide a name with the version 'not found' when fetching the list of plugin
Expand Down
12 changes: 11 additions & 1 deletion lizmap_server/lizmap_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,22 @@ def polygon_filter(
return

try:
filter_type_param = params.get('FILTER_TYPE', '').upper()
if filter_type_param == 'SQL':
filter_type = FilterType.PlainSqlQuery
elif filter_type_param == 'SAFESQL':
filter_type = FilterType.SafeSqlQuery
elif filter_type_param == 'EXPRESSION':
filter_type = FilterType.QgisExpression
else:
filter_type = FilterType.PlainSqlQuery

edition_context = is_editing_context(self.server_iface.requestHandler())
filter_polygon_config = FilterByPolygon(
cfg.get("filter_by_polygon"),
layer,
edition_context,
filter_type=FilterType.PlainSqlQuery,
filter_type=filter_type,
)
if filter_polygon_config.is_filtered():
if not filter_polygon_config.is_valid():
Expand Down
17 changes: 15 additions & 2 deletions test/test_lizmap_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_lizmap_getserversettings(client):


def test_lizmap_service_filter_polygon_with_user(client):
""" Test get polygon filter with the Lizmap service with a user. """
""" Test get polygon filter with the Lizmap service with a user as SQL or QGIS expression. """
project_file = "test_filter_layer_data_by_polygon_for_groups.qgs"

qs = (
Expand All @@ -70,7 +70,8 @@ def test_lizmap_service_filter_polygon_with_user(client):
"REQUEST=GETSUBSETSTRING&"
"MAP=france_parts.qgs&"
"LAYER=shop_bakery&"
"LIZMAP_USER_GROUPS=montferrier-sur-lez"
# "FILTER_TYPE=SQL&" SQL must be the default value when not provided
"LIZMAP_USER_GROUPS=montferrier-sur-lez&"
)
rv = client.get(qs, project_file)
assert rv.status_code == 200
Expand All @@ -79,10 +80,22 @@ def test_lizmap_service_filter_polygon_with_user(client):

b = json.loads(rv.content.decode('utf-8'))

# SQL as output, the default format
assert b['filter'] == '"id" IN ( 68 )'
assert b['status'] == 'success'
assert b['polygons'].startswith('SRID=3857;MultiPolygon')

# QGIS expression
qs += 'FILTER_TYPE=expression&'
rv = client.get(qs, project_file)
assert rv.status_code == 200
assert rv.headers.get('Content-Type', '').find('application/json') == 0
b = json.loads(rv.content.decode('utf-8'))
# geom_from_wkt is a QGIS expression subset
assert 'geom_from_wkt' in b['filter']
assert b['status'] == 'success'
assert b['polygons'].startswith('SRID=3857;MultiPolygon')


def test_lizmap_service_filter_polygon_without_user(client):
""" Test get polygon filter with the Lizmap service without a user. """
Expand Down

0 comments on commit d663929

Please sign in to comment.