Skip to content

Can't get ACL in afterSave hook when create a ParseObject with ACL #821

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
wangmengyan95 opened this issue Mar 4, 2016 · 3 comments
Closed
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@wangmengyan95
Copy link
Contributor

Make sure these boxes are checked before submitting your issue -- thanks for reporting issues back to Parse Server!

-[ ] You've met the prerequisites.

-[ ] You're running the latest version of Parse Server.

-[ ] You've searched through existing issues. Chances are that your issue has been reported or resolved before.

Environment Setup

Run parse-server master branch locally

Steps to reproduce

Step 1. Set a afterSave hook for a ParseObject like

Parse.Cloud.afterSave('Test', function(req) {
  console.log(req.object._toFullJSON());
});

Step 2. Create a ParseObject by JS SDK or REST API

var Parse = require('parse/node');
Parse.initialize("myAppId");
Parse.serverURL = 'http://localhost:1337/parse'

var Test = Parse.Object.extend("Test");
var test = new Test();
test.set('score', 123);

var acl = new Parse.ACL();
acl.setPublicReadAccess(true);
test.setACL(acl);

test.save(null,{
  success: function(test) {
    console.log(test._toFullJSON());
    console.log('success');
  },
  error: function(test, error) {
    console.log('error');
  }
});
curl -X POST -H "X-Parse-Application-Id: myAppId"   -H "Content-Type: application/json"   -d '{"key":"value", "ACL": {"*": {"read": true, "write": true}}}'   http://localhost:1337/parse/classes/Test

Logs/Trace

The log of the cloud code is

{ score: 123,
  createdAt: '2016-03-04T06:50:29.581Z',
  updatedAt: '2016-03-04T06:50:29.581Z',
  objectId: 'DTMuWpx1h6',
  __type: 'Object',
  className: 'Test' }

If we try to retrive the ParseObject by REST API, like

curl -X GET   -H "X-Parion-Id: myAppId"  http://localhost:1337/parse/classes/GameScore/DTMuWpx1h6

The return value is

{"ACL":{"*":{"read":true}},"score":123,"updatedAt":"2016-03-04T05:03:43.273Z","createdAt":"2016-03-04T05:03:43.273Z","objectId":"vptX9lZTtS"}

This means we successfully save the ParseObject, we just do not expose the ACL info to afterSave hook.

If we go deeper we can find in RestWrite, before runDatabaseOperation, this.data contains the ACL info, but after runDatabaseOperation, this.data does not have the ACL info.

Update:
If we update the ParseObject with ACL, we can get the ACL info in the afterSave hook.

@wangmengyan95 wangmengyan95 added the type:bug Impaired feature or lacking behavior that is likely assumed label Mar 4, 2016
@wangmengyan95 wangmengyan95 changed the title Can't get ACL in afterSave hook Can't get ACL in afterSave hook when create a ParseObject with ACL Mar 4, 2016
@nlutsenko
Copy link
Contributor

Awesome, thanks for an extensive testing - will take a look tomorrow.

@nlutsenko
Copy link
Contributor

Found the reason, working on a fix - when we do transform* for running RestWrite - we are deleting an ACL, since we are not copying the data that goes into the database, but rather doing transform/untransform on it, which erases ACL since it's required to be in a different format...
The fix is somewhat trivial, but would need to investigate a bit on what is the implication on this.

@wangmengyan95
Copy link
Contributor Author

@nlutsenko thanks, you are awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

2 participants