Skip to content

beforeFind always returns master: false #4679

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 26, 2018 · 2 comments
Closed

beforeFind always returns master: false #4679

khalilsarabey opened this issue Mar 26, 2018 · 2 comments

Comments

@khalilsarabey
Copy link

khalilsarabey commented Mar 26, 2018

Hello!

I'm using beforeFind on a Message class to filter messages according to conversations and everything is working well.
However, in some cases, I want to bypass this filter, specifically when a conversation is deleted, so what I'm doing is I'm running find on Message class and I'm using the master key in order to destroy all those messages, however, beforeFind is always returning master as false.

Here is the actual code in beforeFind:

     let isMaster = request.master;    

     if(!isMaster) {
        if(!request.user) {
            throw new Parse.Error("You are not logged in, please log in");
        }
        let jsonQuery = request.query.toJSON();
        if(jsonQuery.where.inbox) {
            let inbox = new Parse.Query('Inbox');
            inbox.get(jsonQuery.where.inbox.objectId).then(function(results) {
                request.query.matchesQuery('inbox', results);
            });
        }
    }

And the query I'm running is:

        let message = new Parse.Query('Message');
        message.equalTo('inbox', request.object);
        return message.find(null, {useMasterKey: true});

The result in the debugger is this:

parse-app > { triggerName: 'beforeFind',
parse-app >   query:
parse-app >    ParseQuery {
parse-app >      className: 'Message',
parse-app >      _where: { inbox: [Object] },
parse-app >      _include: [],
parse-app >      _limit: 100,
parse-app >      _skip: 0,
parse-app >      _extraOptions: {} },
parse-app >   master: false,
parse-app >   count: false,

Maybe this is a bug? or am I missing something?
According to the documentation this should work ...

Thanks!

@flovilmart
Copy link
Contributor

According to the documentation, find only takes one argument http://parseplatform.org/Parse-SDK-JS/api/v1.11.1/Parse.Query.html#find

message.find({useMasterKey: true})

No, it’s not a bug.

@khalilsarabey
Copy link
Author

I'm sorry!
Stupid mistake from my part:

message.find(null, {useMasterKey: true});

should be:

message.find({useMasterKey: true});

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