@@ -391,19 +391,25 @@ def get_lizmap_layer_filter(self, layer: QgsVectorLayer, filter_type: FilterType
391
391
392
392
return login_filter
393
393
394
- login_filter = self ._filter_by_login (cfg_layer_login_filter , groups , user_login )
394
+ login_filter = self ._filter_by_login (
395
+ cfg_layer_login_filter ,
396
+ groups ,
397
+ user_login ,
398
+ layer .dataProvider ().name (),
399
+ )
395
400
if polygon_filter :
396
401
return f'{ polygon_filter } AND { login_filter } '
397
402
398
403
return login_filter
399
404
400
405
@staticmethod
401
- def _filter_by_login (cfg_layer_login_filter : dict , groups : tuple , login : str ) -> str :
406
+ def _filter_by_login (cfg_layer_login_filter : dict , groups : tuple , login : str , provider : str ) -> str :
402
407
""" Build the string according to the filter by login configuration.
403
408
404
409
:param cfg_layer_login_filter: The Lizmap Filter by login configuration.
405
410
:param groups: List of groups for the current user
406
411
:param login: The current user
412
+ :param provider: The layer data provider ('postgres' for example)
407
413
"""
408
414
# List of values for expression
409
415
values = []
@@ -420,7 +426,9 @@ def _filter_by_login(cfg_layer_login_filter: dict, groups: tuple, login: str) ->
420
426
421
427
# Since LWC 3.8, we allow to have a list of groups (or logins)
422
428
# separated by comma, with NO SPACES
423
- # e.g. field "filter_field" can contain 'group_a,group_b,group_c'
429
+ # only for PostgreSQL layers and if the option allow_multiple_acl_values
430
+ # is set to True
431
+ # For example the field can contain 'group_a,group_b,group_c'
424
432
# To use only pure SQL allowed by QGIS, we can use LIKE items
425
433
# For big dataset, a GIN index with pg_trgm must be used for the
426
434
# filter field to improve performance
@@ -442,17 +450,19 @@ def _filter_by_login(cfg_layer_login_filter: dict, groups: tuple, login: str) ->
442
450
# equality
443
451
filters .append (f'{ quoted_field } = { quoted_value } ' )
444
452
445
- # begins with value & comma
446
- quoted_like_value = QgsExpression .quotedString (f'{ value } ,%' )
447
- filters .append (f'{ quoted_field } LIKE { quoted_like_value } ' )
453
+ # Add LIKE statements to manage multiple values separated by comma
454
+ if provider == 'postgres' and cfg_layer_login_filter .get ('allow_multiple_acl_values' ):
455
+ # begins with value & comma
456
+ quoted_like_value = QgsExpression .quotedString (f'{ value } ,%' )
457
+ filters .append (f'{ quoted_field } LIKE { quoted_like_value } ' )
448
458
449
- # ends with comma & value
450
- quoted_like_value = QgsExpression .quotedString (f'%,{ value } ' )
451
- filters .append (f'{ quoted_field } LIKE { quoted_like_value } ' )
459
+ # ends with comma & value
460
+ quoted_like_value = QgsExpression .quotedString (f'%,{ value } ' )
461
+ filters .append (f'{ quoted_field } LIKE { quoted_like_value } ' )
452
462
453
- # value between two commas
454
- quoted_like_value = QgsExpression .quotedString (f'%,{ value } ,%' )
455
- filters .append (f'{ quoted_field } LIKE { quoted_like_value } ' )
463
+ # value between two commas
464
+ quoted_like_value = QgsExpression .quotedString (f'%,{ value } ,%' )
465
+ filters .append (f'{ quoted_field } LIKE { quoted_like_value } ' )
456
466
457
467
# Build the filter for this value
458
468
value_filters .append (' OR ' .join (filters ))
0 commit comments