admin管理员组

文章数量:1415139

I'm trying to limit the visibility of some fields of parse User object in cloud function. I have a "Product" class, with a pointer named "owner" to a the "User" that uploaded the item.

I also have a cloud function called "getProducts", I use query.include("owner") to get the owner data at the same time.

What i want to achieve, is that the output of the "getProduct", will be a list of products, but the "Owner" object will contain only certain fields, such as "firstName" or "facebookId", I don't want to return to the client other sensitive data even though I'm not presenting it (such as Location, email, family name etc..).

After searching I've seen 2 possible solutions. 1.) Cut the User class into 2 classes, 1 of is "Private" class with ACL just for the user. 2.) The second approach that i prefer, i to edit the fields in the cloud function, but i can't seem to change the "owner" object at the "product" object. i'm getting the error: "Error: Uncaught Tried to save an object with a pointer to a new, unsaved object. (Code: 141, Version: 1.2.19)"

var output[] = [];
_.each(results, function(result) {
    var responseData = {};
    var owner = result.get("owner");

    //Remove fields from the user object
    var itemOwnerId = owner.id;
    var itemOwnerFirstName = owner.firstName;
    var itemOwnerFacebookID = owner.facebookID;
    var itemOwner = new Parse.User();
    itemOwner.id = itemOwnerId;
    itemOwner.id = itemOwnerId;
    itemOwner.firstName = itemOwnerFirstName;
    itemOwner.facebookID = itemOwnerFacebookID;
    result.set("owner", itemOwner);
    responseData.item = result;
    output.push(responseData);
});

It seems that calling result.set("owner", itemOwner) isn't good, and throwing me exepction: rror: Uncaught Tried to save an object with a pointer to a new, unsaved object. (Code: 141, Version: 1.2.19)

What am I doing wrong?

I'm trying to limit the visibility of some fields of parse User object in cloud function. I have a "Product" class, with a pointer named "owner" to a the "User" that uploaded the item.

I also have a cloud function called "getProducts", I use query.include("owner") to get the owner data at the same time.

What i want to achieve, is that the output of the "getProduct", will be a list of products, but the "Owner" object will contain only certain fields, such as "firstName" or "facebookId", I don't want to return to the client other sensitive data even though I'm not presenting it (such as Location, email, family name etc..).

After searching I've seen 2 possible solutions. 1.) Cut the User class into 2 classes, 1 of is "Private" class with ACL just for the user. 2.) The second approach that i prefer, i to edit the fields in the cloud function, but i can't seem to change the "owner" object at the "product" object. i'm getting the error: "Error: Uncaught Tried to save an object with a pointer to a new, unsaved object. (Code: 141, Version: 1.2.19)"

var output[] = [];
_.each(results, function(result) {
    var responseData = {};
    var owner = result.get("owner");

    //Remove fields from the user object
    var itemOwnerId = owner.id;
    var itemOwnerFirstName = owner.firstName;
    var itemOwnerFacebookID = owner.facebookID;
    var itemOwner = new Parse.User();
    itemOwner.id = itemOwnerId;
    itemOwner.id = itemOwnerId;
    itemOwner.firstName = itemOwnerFirstName;
    itemOwner.facebookID = itemOwnerFacebookID;
    result.set("owner", itemOwner);
    responseData.item = result;
    output.push(responseData);
});

It seems that calling result.set("owner", itemOwner) isn't good, and throwing me exepction: rror: Uncaught Tried to save an object with a pointer to a new, unsaved object. (Code: 141, Version: 1.2.19)

What am I doing wrong?

Share Improve this question edited Jul 25, 2014 at 16:00 John Powell 12.6k6 gold badges63 silver badges69 bronze badges asked Jul 25, 2014 at 15:57 Or RapaportOr Rapaport 716 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 13

The SDK doesn't allow an object that has been changed to be serialized into a response.

A hack way to work around this would be:

result.dirty = function() { return false; };

This would disable the check and allow you to return the modified object.

If you wanted to re-enable it later, you'd need to store the original value of result.dirty and reassign it later.

本文标签: javascriptParsecom cloud functionmanually modify object fields before sending to clientStack Overflow