kamax-matrix / mxisd

Federated Matrix Identity Server
GNU Affero General Public License v3.0
223 stars 115 forks source link

Wordpress Identity store returns duplicate results for Directory feature #75

Closed maxidorius closed 6 years ago

maxidorius commented 6 years ago

When searching for a user, duplicate results are returned in case the search match both in the Matrix ID/Display name and the 3PIDs. Previously, this was done by Riot directly but it seems to no longer be the case, so we'll fix on our end.

Example:

Apr 24 10:58:19 domain mxisd[492]: .740  INFO [nio-8090-exec-5]    i.k.m.directory.DirectoryManager : Performing search for 'us'
Apr 24 10:58:19 domain mxisd[492]: .740  INFO [nio-8090-exec-5]    i.k.m.directory.DirectoryManager : Original request URL: http://domain.com/_matrix/client/r0/user_directory/search
Apr 24 10:58:19 domain mxisd[492]: .740  INFO [nio-8090-exec-5]    i.k.m.directory.DirectoryManager : Skipping HS directory data, disabled in config
Apr 24 10:58:19 domain mxisd[492]: .740  INFO [nio-8090-exec-5]    i.k.m.directory.DirectoryManager : Using Directory provider WordpressDirectoryProvider
Apr 24 10:58:19 domain mxisd[492]: .740  INFO [nio-8090-exec-5] .k.m.b.w.WordpressDirectoryProvider : Searching users by display name using 'us'
Apr 24 10:58:19 domain mxisd[492]: .741  INFO [nio-8090-exec-5] .k.m.b.w.WordpressDirectoryProvider : Will execute query: SELECT DISTINCT LOWER(user_login), LOWER(display_name) FROM wp_users u LEFT JOIN wp_usermeta m ON m.user_id = u.id WHERE u.display_name LIKE ? OR (m.meta_key = 'nickname' AND m.meta_value = ?) OR (m.meta_key = 'first_name' AND m.meta_value = ?) OR (m.meta_key = 'last_name' AND m.meta_value = ?);
Apr 24 10:58:19 domain mxisd[492]: .743  INFO [nio-8090-exec-5]    i.k.m.directory.DirectoryManager : Display name: found 2 match(es) for 'us'
Apr 24 10:58:19 domain mxisd[492]: .743  INFO [nio-8090-exec-5] .k.m.b.w.WordpressDirectoryProvider : Searching users by 3PID using 'us'
Apr 24 10:58:19 domain mxisd[492]: .743  INFO [nio-8090-exec-5] .k.m.b.w.WordpressDirectoryProvider : Will execute query: SELECT DISTINCT LOWER(user_login), LOWER(display_name) FROM wp_users WHERE user_email LIKE ?
Apr 24 10:58:19 domain mxisd[492]: .744  INFO [nio-8090-exec-5]    i.k.m.directory.DirectoryManager : Threepid: found 2 match(es) for 'us'
Apr 24 10:58:19 domain mxisd[492]: .744  INFO [nio-8090-exec-5]    i.k.m.directory.DirectoryManager : Total matches: 4 - limited? false
Apr 24 10:58:19 domain mxisd[492]: .930  INFO [nio-8090-exec-3]    i.k.m.directory.DirectoryManager : Performing search for 'use'
Apr 24 10:58:19 domain mxisd[492]: .930  INFO [nio-8090-exec-3]    i.k.m.directory.DirectoryManager : Original request URL: http://domain.com/_matrix/client/r0/user_directory/search
Apr 24 10:58:19 domain mxisd[492]: .930  INFO [nio-8090-exec-3]    i.k.m.directory.DirectoryManager : Skipping HS directory data, disabled in config
Apr 24 10:58:19 domain mxisd[492]: .930  INFO [nio-8090-exec-3]    i.k.m.directory.DirectoryManager : Using Directory provider WordpressDirectoryProvider
Apr 24 10:58:19 domain mxisd[492]: .930  INFO [nio-8090-exec-3] .k.m.b.w.WordpressDirectoryProvider : Searching users by display name using 'use'
Apr 24 10:58:19 domain mxisd[492]: .930  INFO [nio-8090-exec-3] .k.m.b.w.WordpressDirectoryProvider : Will execute query: SELECT DISTINCT LOWER(user_login), LOWER(display_name) FROM wp_users u LEFT JOIN wp_usermeta m ON m.user_id = u.id WHERE u.display_name LIKE ? OR (m.meta_key = 'nickname' AND m.meta_value = ?) OR (m.meta_key = 'first_name' AND m.meta_value = ?) OR (m.meta_key = 'last_name' AND m.meta_value = ?);
Apr 24 10:58:19 domain mxisd[492]: .932  INFO [nio-8090-exec-3]    i.k.m.directory.DirectoryManager : Display name: found 2 match(es) for 'use'
Apr 24 10:58:19 domain mxisd[492]: .932  INFO [nio-8090-exec-3] .k.m.b.w.WordpressDirectoryProvider : Searching users by 3PID using 'use'
Apr 24 10:58:19 domain mxisd[492]: .932  INFO [nio-8090-exec-3] .k.m.b.w.WordpressDirectoryProvider : Will execute query: SELECT DISTINCT LOWER(user_login), LOWER(display_name) FROM wp_users WHERE user_email LIKE ?
Apr 24 10:58:19 domain mxisd[492]: .932  INFO [nio-8090-exec-3]    i.k.m.directory.DirectoryManager : Threepid: found 2 match(es) for 'use'
Apr 24 10:58:19 domain mxisd[492]: .932  INFO [nio-8090-exec-3]    i.k.m.directory.DirectoryManager : Total matches: 4 - limited? false
Apr 24 10:58:20 domain mxisd[492]: .049  INFO [nio-8090-exec-4]    i.k.m.directory.DirectoryManager : Performing search for 'user'
Apr 24 10:58:20 domain mxisd[492]: .049  INFO [nio-8090-exec-4]    i.k.m.directory.DirectoryManager : Original request URL: http://domain.com/_matrix/client/r0/user_directory/search
Apr 24 10:58:20 domain mxisd[492]: .049  INFO [nio-8090-exec-4]    i.k.m.directory.DirectoryManager : Skipping HS directory data, disabled in config
Apr 24 10:58:20 domain mxisd[492]: .049  INFO [nio-8090-exec-4]    i.k.m.directory.DirectoryManager : Using Directory provider WordpressDirectoryProvider
Apr 24 10:58:20 domain mxisd[492]: .049  INFO [nio-8090-exec-4] .k.m.b.w.WordpressDirectoryProvider : Searching users by display name using 'user'
Apr 24 10:58:20 domain mxisd[492]: .049  INFO [nio-8090-exec-4] .k.m.b.w.WordpressDirectoryProvider : Will execute query: SELECT DISTINCT LOWER(user_login), LOWER(display_name) FROM wp_users u LEFT JOIN wp_usermeta m ON m.user_id = u.id WHERE u.display_name LIKE ? OR (m.meta_key = 'nickname' AND m.meta_value = ?) OR (m.meta_key = 'first_name' AND m.meta_value = ?) OR (m.meta_key = 'last_name' AND m.meta_value = ?);
Apr 24 10:58:20 domain mxisd[492]: .050  INFO [nio-8090-exec-4]    i.k.m.directory.DirectoryManager : Display name: found 1 match(es) for 'user'
Apr 24 10:58:20 domain mxisd[492]: .050  INFO [nio-8090-exec-4] .k.m.b.w.WordpressDirectoryProvider : Searching users by 3PID using 'user'
Apr 24 10:58:20 domain mxisd[492]: .050  INFO [nio-8090-exec-4] .k.m.b.w.WordpressDirectoryProvider : Will execute query: SELECT DISTINCT LOWER(user_login), LOWER(display_name) FROM wp_users WHERE user_email LIKE ?
Apr 24 10:58:20 domain mxisd[492]: .051  INFO [nio-8090-exec-4]    i.k.m.directory.DirectoryManager : Threepid: found 1 match(es) for 'user'
Apr 24 10:58:20 domain mxisd[492]: .051  INFO [nio-8090-exec-4]    i.k.m.directory.DirectoryManager : Total matches: 2 - limited? false
maxidorius commented 6 years ago

Fixed by b493ccd