FriendsOfFlarum / user-directory

The permission based public user directory extension for your Flarum forum.
https://discuss.flarum.org/d/5682
MIT License
22 stars 17 forks source link

Group filter does not work well #96

Open ayyilmaz opened 1 year ago

ayyilmaz commented 1 year ago

I think group filter does not work well. Because when I select more than groups it does not show any user.

I selected admins it showed 1 user and then I also selected moderators but it show 0 users. My expectation is that when both are selected, the admin user will be listed even if there is no moderator. Filter use AND operator instead of OR.

Bug Report

Current Behavior A clear and concise description of the behavior.

Steps to Reproduce

  1. Go to 'user directory page'
  2. Click on 'Filter Group'
  3. Select one group then another groups
  4. when I select more than groups it does not show any user if user is not member of both groups.

Expected Behavior when both are selected, the admin user will be listed even if there is no moderator. Filter use AND operator instead of OR.

Screenshots If applicable, add screenshots to help explain your problem.

Environment

Possible solution(s) We should filter with OR operator instead of AND

clarkwinkelmann commented 1 year ago

This is the currently expected behavior.

The search filter in FoF User Directory maps each criteria to its own token in the q search query, which Flarum automatically translates into an AND query.

https://github.com/FriendsOfFlarum/user-directory/blob/eebe17b589b8dd405f0b054d2e02097ca1534840/js/src/forum/searchTypes/GroupFilter.js#L55

Flarum's group: gambit supports providing multiple groups in a single token to perform an OR query https://github.com/flarum/framework/blob/main/framework/core/src/User/Query/GroupFilterGambit.php but this feature is currently not used by User Directory.

I personally think the current implementation makes sense, so I wouldn't want to remove the ability to perform AND queries. But I'm not sure how to accommodate having both AND and OR queries, this would make the UI very complicated.

Another problem is that the javascript search type interface currently used to create custom search properties just doesn't support gambits with multiple criteria, it always matches one item to one gambit/token, with no way to group multiple ones. So that would require some significant refactor.

Also partially of relevance but not directly in this source code, The Taxonomies extension uses the same interface to provide a custom filter. If we change groups to be OR by default, there will be inconsistencies with the other tokens that use AND by default https://github.com/flamarkt/taxonomies/blob/2e2a024b01c4cc3b4daadf4a509e0b6113931b29/js/src/forum/addUserDirectorySearchType.ts#L121

I'm not sure if there are any other extensions extending the available search filters.


A workaround to achieve the filtering you want without changing how the extension works would be to manually type the group:group1,group2 in the search query. I think it will work fine. If this breaks the UI, we can publish a simple fix to make sure multi-criteria gambits aren't parsed by the filter system.