Ruben Martinez Jr.
Ruben Martinez Jr.

Reputation: 3110

Parse User Query Only Retrieves Current user

I'm trying to run a query that retrieves a specific set of users from the User table and presents them to a given logged in user, using the Parse JS SDK. At first I was running a query like:

(new Parse.Query(Parse.Object.extends("_User"))).containedIn("objectId", [/* list of user ids */]).find(/* success & error blocks */);

but then I learned the more correct way was:

(new Parse.Query(Parse.User)).containedIn("objectId", [/* list of user ids */]).find(/* success & error blocks */);

But even with this, I would get back an empty list. I double-checked the db and made sure the ids I was passing were in there, and they were. Just for the hell of it I tried:

(new Parse.Query(Parse.User)).find(/* success & error blocks */);

And I got back the user object corresponding to the current user. So it seems my User queries are only able to access the current user. I also noticed that when I tried running an equivalent query from the Parse API Console, I got the same results! Is this some sort of global setting, or am I doing something wrong? Thanks!

Upvotes: 1

Views: 774

Answers (3)

Mo Nazemi
Mo Nazemi

Reputation: 2717

Looks like a CLP issue to me. Maybe Find permission on your User class is disabled. Go to your User class, tap on security, switch to advance and then check whether the Find permission is ticked off or not.

Upvotes: 0

Jake T.
Jake T.

Reputation: 4378

I would recommend not condensing all these calls into one line for the sake of saving lines. It sacrifices readability. Although, it's technically not wrong, and the docs even say the calls return a query so you can chain calls, so to each their own.

I don't see anything wrong with your call, though. How are you accessing the retrieved objects? What is the list of objectIds that you are passing into containedIn? We need a bit more of your code here, I think.

edit - I would say I'm 80% sure, without more information, that this is an ACL / CLP issue. Go to the dashboard, hit the _User class, press Security, and see what the read/write settings are.

Upvotes: 1

Chris L
Chris L

Reputation: 1061

I believe you have to use CloudCode due to User Security Settings in Parse. Try shifting this to a cloud code function and include

Parse.Cloud.useMasterKey()

prior to the cloudcode function. This is a security 'feature' of Parse to ensure people can't edit and access other user profiles and information.

See Parse security site here:

https://parse.com/docs/js/guide#security-object-level-access-control

and more on use and considerations of implementing useMasterKey() and its persistence.

https://parse.com/docs/js/guide#security-implementing-business-logic-in-cloud-code

Upvotes: 2

Related Questions