Skip to content

Commit

Permalink
CFG - Store allowed_groups as an array for layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Oct 12, 2023
1 parent 2bf8ca2 commit 50cb25c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lizmap/definitions/layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
11 changes: 10 additions & 1 deletion lizmap/table_manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
30 changes: 29 additions & 1 deletion lizmap/test/test_table_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ def test_layout_definitions(self):
{
"layout": "A4 Landscape",
"enabled": False,
"allowed_groups": [
'admins',
'group_a',
],
"formats_available": (
"pdf",
"png",
Expand All @@ -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)
Expand All @@ -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"
Expand All @@ -276,6 +297,11 @@ def test_layout_definitions(self):
{
"layout": "Cadastre",
"enabled": True,
"allowed_groups": [
"im",
"an",
"admin",
],
"formats_available": (
"pdf",
),
Expand All @@ -288,6 +314,7 @@ def test_layout_definitions(self):
{
"layout": "Local planning",
"enabled": True,
# "allowed_groups": [],
"formats_available": (
"pdf",
),
Expand All @@ -300,6 +327,7 @@ def test_layout_definitions(self):
{
"layout": "Economy",
"enabled": True,
# "allowed_groups": [],
"formats_available": (
"pdf",
),
Expand Down

0 comments on commit 50cb25c

Please sign in to comment.