Skip to content

beforeFind is ignoring query returns #4633

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

Closed
khalilsarabey opened this issue Mar 12, 2018 · 2 comments
Closed

beforeFind is ignoring query returns #4633

khalilsarabey opened this issue Mar 12, 2018 · 2 comments

Comments

@khalilsarabey
Copy link

khalilsarabey commented Mar 12, 2018

Issue Description

Cloud Code get is ignoring beforeFind query and proceeding anyway

Steps to reproduce

I have an app with a chat feature, I'm using "Inbox" class as a chat room, and I have a "Message" class which contains the messages and each message has a pointer to an inbox.
Now adding ACL to Message class would be disastrous to maintain, since users can join and leave rooms, that way I'll need to modify the ACL of each message, imagine tens of thousands of messages (I'm optimistic!)
Thanks to beforeFind I can do the checking in a very easy and clean way, which is when a user is trying to get messages, I check the inbox id in the request, and I run a query that checks if the user is in this chat room or not. Everything makes sense, but beforeFind is totally ignoring the query and proceeding with fetching the results anyway.
Is it a bug in beforeFind or am I doing something wrong?

Here's the code:

var jsonQuery = request.query.toJSON();
var inbox = new Parse.Query('Inbox');
inbox.get(jsonQuery.where.inbox.objectId)
.then(function(results) {
if(!results) {
throw new Parse.Error(101, 'You can not view these messages');
}
});

Expected Results

I expect to return an error if no results from Inbox query

Actual Outcome

It's proceeding anyway.

Environment Setup

  • Server
    • parse-server version : 2.7.2
    • Operating System: macOS Sierra
    • Hardware: mac pro 2011
    • Localhost or remote server? Local
@flovilmart
Copy link
Contributor

This is the expected behavior. Beforefind is not designed to run queries but to alter an incoming query. Note that you could use a matchesQuery or matchesKeyInQuery in order to filter the inbox

Ex:

req.query.matchesQuery(‘inbox’, inbox)

Sent with GitHawk

@khalilsarabey
Copy link
Author

@flovilmart the savior :)
I don't know why I haven't thought of doing this, so silly of me!
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants