user1635282
user1635282

Reputation: 41

Cannot save a ParseUser that is not authenticated, updating an object with a relation with a ParseUser

I am workin in an Android Project using parse.com and I have a table Requirement which has a column called "user_assigned" which is a relation to ParseUser. This user is in charge to modify the requirement even if he didn't create the Requirement, but when this user try to update the requirement values, it returns "Cannot save a ParseUser that is not authenticated"

P.D. All the ACL in the requirement are public, write and read.

        // setting write permission
        ParseACL postACL = new ParseACL(ParseUser.getCurrentUser());
        postACL.setPublicWriteAccess(true);
        postACL.setPublicReadAccess(true);          
        requirement.setACL(postACL);

        requirement.saveInBackground(new SaveCallback() {

        @Override
        public void done(ParseException e) {
           callback.onFinish((Exception) e, requirement);
        }

I don't want to change the user assigned I want to change other fields but the way I get and change the relation from the table is

       ParseRelation<ParseUser> relation = requirement.getRelation("user_assigned");
       relation.add(requirement.getUserAssigned());

Upvotes: 0

Views: 558

Answers (1)

user1635282
user1635282

Reputation: 41

I found a solution,

What is happening: 3 tables, Project, User and Requirements where a Requirement has a pointer to the Project and the Project has another pointer to an User called projectOwner. The problem happen when another user different to the projectOwner read some values of the projectOwner associated with the Requirements. If the new user wants to save some changes in the Requirements parse return the error "Cannot save a ParseUser that is not authenticated".

To fix it, i only read the objectId of the projectOwner and after I got the rest of the attributes of the ParseUser calling

ParseUser.getQuery(); query.get(objectId)

In other words, in my class Project, i have a method to get the attributes. When I want to get the projectUser (pointer) i got it like this:

    User uTemp = (User) this.getParseUser("owner");
    if(uTemp != null){
    //  this.setOwner(uTemp.extractAttributes());
        uTemp = uTemp.getObjectId();
        uTemp = UserDAO.getUserByObjectId(uTemp.getObjectId());
        this.setOwner(uTemp);
    }

I could fixed thanks to this, I hope it can be helpful.

Upvotes: 3

Related Questions