Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve user/group filter to allow multiple users/groups #4559

Merged
merged 3 commits into from
Aug 23, 2024

Conversation

nboisteault
Copy link
Member

@nboisteault nboisteault commented Jun 27, 2024

Lizmap Web Client allows filtering the content of vector layers depending on the authenticated user. Before version 3.8, for the attribute filter, every layer to filter must have a field which value must be only one group identifier (or one user login), such as:

id name filter_field
1 one group_a
2 two group_b
3 three group_b
4 four all

This modification allows using a list of groups (or a list of users) separated with a comma (with no spaces) inside the field used as the source of filtering. This will ease showing some features for more than one group (or user). For example, the filtered layer could contain:

id name filter_field
1 one group_a,group_b
2 two group_b
3 three group_b,all
4 four all

We focus on keeping the filter sent to the layer provider as standard as possible, to be able to be directly used by PostgreSQL and avoid evaluating a complex expression on all features.

This new feature is only available:

  • for PostgreSQL layers
  • if the map editor has chosen to allow multiple values in the filter field (this can be configured in Lizmap desktop plugin)

These safeguards allow Lizmap default behaviour to not change between version 3.7 and 3.8. The map editor will decide to manually activate this new feature. It is safer, as a specific index must be added to have good performance with the new multiple value search.

The filter is built this way:

  • we explode the list of groups and use LIKE statements combining all possibilities. For example, the above example will lead to a filter like this if the authenticated user is in the group group_a:
    "filter_field" = 'group_a' OR "filter_field" LIKE 'group_a,%' OR "filter_field" LIKE '%,group_a' OR "filter_field" LIKE '%,group_a,%'
    OR
    "filter_field" = 'all' OR "filter_field" LIKE 'all,%' OR "filter_field" LIKE '%,all' OR "filter_field" LIKE '%,all,%'
  • no space must be used between the group (or user) names and commas.

On big datasets, a proper GIN index using the extension pg_trgm is highly recommended.

CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE INDEX ON some_schema.some_table USING GIN (filter_field gin_trgm_ops);

Linked to 3liz/qgis-lizmap-server-plugin#86

Funded by: Conseil Départemental du Calvados https://www.calvados.fr/

@github-actions github-actions bot added this to the 3.9.0 milestone Jun 27, 2024
@Gustry Gustry added the sponsored development This development has been funded label Jul 3, 2024
@mdouchin mdouchin self-assigned this Aug 19, 2024
@mdouchin mdouchin added the run end2end If the PR must run end2end tests or not label Aug 19, 2024
@mdouchin mdouchin force-pushed the filter_by_multiple_users_or_groups branch from eb2061e to 114c7c4 Compare August 19, 2024 10:57
Copy link
Member

@Gustry Gustry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

lizmap/modules/lizmap/lib/Project/Project.php Show resolved Hide resolved
@mdouchin mdouchin force-pushed the filter_by_multiple_users_or_groups branch 2 times, most recently from 72ed743 to 01a8330 Compare August 21, 2024 14:48
@Gustry
Copy link
Member

Gustry commented Aug 21, 2024

> 45 |         await expect(page.locator('[id="jforms_admin_config_section_lizmap\\.repositories\\.view_6"]')).toBeChecked();

E2E tests are failing because of the new group, about the checkboxes in the administration panel, in the "Map repository" creation.

@mdouchin mdouchin force-pushed the filter_by_multiple_users_or_groups branch from 0c5c617 to 4fc54e4 Compare August 22, 2024 08:44
@mdouchin
Copy link
Collaborator

> 45 |         await expect(page.locator('[id="jforms_admin_config_section_lizmap\\.repositories\\.view_6"]')).toBeChecked();

E2E tests are failing because of the new group, about the checkboxes in the administration panel, in the "Map repository" creation.

Fixed !

@mdouchin
Copy link
Collaborator

The end2end PlayWright test needs 3liz/qgis-lizmap-server-plugin#86 to pass

@mdouchin
Copy link
Collaborator

mdouchin commented Aug 22, 2024

I added the Draft flag again, as I am still working on it to use the new behaviour only:

  • for PostgreSQL layers
  • if the map editor has chosen to allow multiple values in the filter field.

This will allow Lizmap default behaviour to not change between version 3.7 and 3.8 and let the editor control this new feature. It is safer as a specific index must be added to have good performance with the new multiple value search.

@mdouchin mdouchin force-pushed the filter_by_multiple_users_or_groups branch from a6e11fb to 29ba3d0 Compare August 23, 2024 10:42
Copy link
Member

@Gustry Gustry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add to check during this review, the plugin is generating true boolean values ;-)

…reSQL layers & if allow_multiple_acl_values is true
@mdouchin mdouchin force-pushed the filter_by_multiple_users_or_groups branch from 29ba3d0 to 0c1f319 Compare August 23, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport release_3_8 doc-needed enhancement postgresql run end2end If the PR must run end2end tests or not sponsored development This development has been funded
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants