diff --git a/lizmap/definitions/layouts.py b/lizmap/definitions/layouts.py index cc30e996..3a9131d6 100644 --- a/lizmap/definitions/layouts.py +++ b/lizmap/definitions/layouts.py @@ -65,6 +65,8 @@ def __init__(self): 'type': InputType.Text, 'header': tr('Allowed groups'), 'default': '', + 'separator': ',', + 'use_json': True, 'tooltip': tr( 'Use a comma separated list of Lizmap groups ids to restrict access ' 'to this layer edition.') diff --git a/lizmap/table_manager/base.py b/lizmap/table_manager/base.py index 165ed2ef..5f60aa16 100755 --- a/lizmap/table_manager/base.py +++ b/lizmap/table_manager/base.py @@ -368,6 +368,10 @@ def _edit_row(self, row, data): cell.setData(Qt.ToolTipRole, value) elif input_type == InputType.Text: + separator = self.definitions.layer_config[key].get('separator', ',') + if separator and isinstance(value, list): + value = separator.join(value) + cell.setText(value) cell.setData(Qt.UserRole, value) cell.setData(Qt.ToolTipRole, value) @@ -571,7 +575,12 @@ def to_json(self, version=None) -> dict: elif input_type == InputType.List: layer_data[key] = cell elif input_type == InputType.Text: - layer_data[key] = cell + json_array = self.definitions.layer_config[key].get('use_json') + separator = self.definitions.layer_config[key].get('separator', ',') + if json_array and separator and cell: + layer_data[key] = cell.split(separator) + else: + layer_data[key] = cell elif input_type == InputType.MultiLine: layer_data[key] = cell elif input_type == InputType.HtmlWysiwyg: diff --git a/lizmap/test/test_table_manager.py b/lizmap/test/test_table_manager.py index 63486e1d..37925fcd 100755 --- a/lizmap/test/test_table_manager.py +++ b/lizmap/test/test_table_manager.py @@ -239,6 +239,10 @@ def test_layout_definitions(self): { "layout": "A4 Landscape", "enabled": False, + "allowed_groups": [ + 'admins', + 'group_a', + ], "formats_available": ( "pdf", "png", @@ -249,7 +253,20 @@ def test_layout_definitions(self): "300", ), "default_dpi": "300" - } + }, + { + "layout": "Cadastre", + "enabled": True, + "allowed_groups": 'im,an,admin', # input as a string, output as array + "formats_available": ( + "pdf", + ), + "default_format": "pdf", + "dpi_available": ( + "100", + ), + "default_dpi": "100" + }, ] } table_manager.load_qgis_layouts(cfg) @@ -262,6 +279,10 @@ def test_layout_definitions(self): { "layout": "A4 Landscape", "enabled": False, # Value overriden by the CFG file compare to other layouts. + "allowed_groups": [ + 'admins', + 'group_a', + ], "formats_available": ( "pdf", "png" @@ -276,6 +297,11 @@ def test_layout_definitions(self): { "layout": "Cadastre", "enabled": True, + "allowed_groups": [ + "im", + "an", + "admin", + ], "formats_available": ( "pdf", ), @@ -288,6 +314,7 @@ def test_layout_definitions(self): { "layout": "Local planning", "enabled": True, + # "allowed_groups": [], "formats_available": ( "pdf", ), @@ -300,6 +327,7 @@ def test_layout_definitions(self): { "layout": "Economy", "enabled": True, + # "allowed_groups": [], "formats_available": ( "pdf", ),