[FIX] 'Query' support for channels.list.joined, groups.list, groups.listAll, im.list#9424
[FIX] 'Query' support for channels.list.joined, groups.list, groups.listAll, im.list#9424rodrigok merged 5 commits intoRocketChat:developfrom
Conversation
…groups.listAll, im.list Signed-off-by: Eugene Bolshakov <[email protected]>
Signed-off-by: Eugene Bolshakov <[email protected]>
|
It looks interesting, @graywolf336 what do you think? |
Signed-off-by: Eugene Bolshakov <[email protected]>
|
The last change allows to add customFields for IM (Direct Messages). The previously changed im.list now allows to search using 'query' like { "customFields.field1": { "$regex": "^org"}} as shown below: Need to note that:
|
graywolf336
left a comment
There was a problem hiding this comment.
Looks good. If you don't mind, when this gets merged, can you submit a pull request to our Documentation repo to update the docs for these methods?
|
@xbolshe what happens when the value of the user's custom fields change? |
|
@graywolf336 Sure. I can update Documentation repo with changes of this PR and usage examples. |
Signed-off-by: Eugene Bolshakov <[email protected]>
|
@graywolf336 Docs PR is added (see a link above). |
geekgonecrazy
left a comment
There was a problem hiding this comment.
@graywolf336 @rodrigok do we want to open this up to any query? Or should this be limited in some way?
| 'u._id': this.userId | ||
| }); | ||
|
|
||
| let rooms = _.pluck(RocketChat.models.Subscriptions.find(ourQuery).fetch(), '_room'); |
There was a problem hiding this comment.
Is it safe to just blindly pass query through?
There was a problem hiding this comment.
@geekgonecrazy it's not exactly passing the query blindly. The function parseJsonQuery handles several cases and line 410 ensures that the calling user is only able to query their own...although I say that without trying it. @xbolshe what happens whenever someone passes the query with a nested property like the one the string u._id is doing? For example, { "u": { "_id": "other_users_id" } }?
There was a problem hiding this comment.
@graywolf336 One string and nested string will have different actions as described here: https://stackoverflow.com/questions/16002659/how-to-query-nested-objects
Becase "u" has several fields inside, only nested "_id" will find no records at all:
But one string provides a records selection:
So, need to use all fields nested inside "u" like shown below:
Providing 2 different values for one field like "u._id" will cause a search of no records:
Answering on your question, one field cannot be equal at the same time to 2 different values.
If a value will be duplicated like shown below, a search will be performed:
So, only records belongs to this.userId will be searched for channels.list.joined.
I have tried to inherit constraints like this.userId applied before my changes.
There was a problem hiding this comment.
Thanks for looking into it in more depth! 👍








@RocketChat/core
Closes #9423
New in the database: customFields is added to Subscription to get it from RocketChat.models.Subscriptions.find(ourQuery).fetch().
Example after this fix : get all joined channels with customFields.field1 = "aaa-2"