Skip to content
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

acl.setRoleReadAccess("admin", true); doesn't work in parse server afterSave triger #3272

Closed
ArMouReR opened this issue Dec 21, 2016 · 8 comments

Comments

@ArMouReR
Copy link

Issue Description

Here is my code of user afterSave that worked in hosted server

Parse.Cloud.afterSave(Parse.User, function (request) {
    var user = request.object;
    if (!user.existed()) {
        var acl = new Parse.ACL(user);
        acl.setPublicReadAccess(false);
        acl.setRoleReadAccess("admin", true);
        acl.setRoleWriteAccess("admin", true);
    	user.setACL(acl);
        user.save(null,{useMasterKey: true});
    }
});

Adding admin role to asl generated the following error:
Error generating response. TypeError: Tried to create an ACL with an invalid permission type.

If I remove admin role addition everything works as expected.

  • Server
    • parse-server version v2.3.1
    • AWS Elasticbeanstalk
@hramos
Copy link
Contributor

hramos commented Feb 10, 2017

Thanks for your question!

We want to make sure to keep signal strong in the GitHub issue tracker – to make sure that it remains the best place to track issues that affect the development of Parse Server.

Questions like yours deserve a purpose-built Q&A forum. Would you like to post this question to Stack Overflow with the tag #parse.com? We'll be happy to answer there. Post a link to your Stack Overflow question here, so that we don't lose track of it.

You may also use Server Fault for questions about managing your own servers.

@hramos hramos closed this as completed Feb 10, 2017
@drbarto
Copy link

drbarto commented Jan 14, 2018

@ArMouReR did you ever solve your issue? I have a very similar problem (see this SO post) and would be very thankful if you could share your solution.

@flovilmart
Copy link
Contributor

Can you provide the server logs or is it a JS SDK issue?

@drbarto
Copy link

drbarto commented Jan 14, 2018

Here's the log entry showing the error:

error: Failed running cloud function createTask for user undefined with:
  Input: {"elementId":"rotQDxPIbR","typeId":"BVPif8wV4r","assignedById":"17sTGcULJU","assignedToId":"17sTGcULJU","fulfillmentId":"e4eGcnJ4yF"}
  Error: {"code":141,"message":{}} functionName=createTask, code=141, , elementId=rotQDxPIbR, typeId=BVPif8wV4r, assignedById=17sTGcULJU, assignedToId=17sTGcULJU, fulfillmentId=e4eGcnJ4yF, user=undefined
error: Error generating response. ParseError {
  code: 141,
  message: 
   TypeError: Tried to create an ACL with an invalid permission type.
       at new ParseACL (/cc/node_modules/parse/lib/node/ParseACL.js:85:21)
       at ParseObject.value (/cc/node_modules/parse/lib/node/ParseObject.js:738:42)
       at ParseObject.value (/cc/node_modules/parse/lib/node/ParseObject.js:1070:19)
       at ParsePromise.<anonymous> (/cc/cloud/functions/admin/create_task.js:118:14)
       at ParsePromise.wrappedResolvedCallback (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:153:43)
       at ParsePromise.value (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:89:36)
       at resolveOne (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:517:29)
       at ParsePromise.object.then.errors.(anonymous function) (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:526:13)
       at ParsePromise.wrappedResolvedCallback (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:153:43)
       at ParsePromise.value (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:89:36)
       at ParsePromise.<anonymous> (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:163:29)
       at ParsePromise.wrappedResolvedCallback (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:153:43)
       at /cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:219:35
       at _combinedTickCallback (internal/process/next_tick.js:67:7)
       at process._tickDomainCallback (internal/process/next_tick.js:122:9) } code=141, 
error: TypeError: Tried to create an ACL with an invalid permission type.
    at new ParseACL (/cc/node_modules/parse/lib/node/ParseACL.js:85:21)
    at ParseObject.value (/cc/node_modules/parse/lib/node/ParseObject.js:738:42)
    at ParseObject.value (/cc/node_modules/parse/lib/node/ParseObject.js:1070:19)
    at ParsePromise.<anonymous> (/cc/cloud/functions/admin/create_task.js:118:14)
    at ParsePromise.wrappedResolvedCallback (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:153:43)
    at ParsePromise.value (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:89:36)
    at resolveOne (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:517:29)
    at ParsePromise.object.then.errors.(anonymous function) (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:526:13)
    at ParsePromise.wrappedResolvedCallback (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:153:43)
    at ParsePromise.value (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:89:36)
    at ParsePromise.<anonymous> (/cc/node_modules/parse-server/node_modules/parse/lib/node/ParsePromise.js:163:29)

The code responsible for this error looks like this:

const acl = new Parse.ACL();
acl.setRoleReadAccess('name', true);
const task = new Task(args);
task.setACL(acl); // <-- error

The Task type is defined in another file and required in the Cloud Code file:

// task.js
module.exports = Parse.Object.extend('Task');
// create_task.js
const Task = require('./task');

NOTE: an interesting discovery I made after hours of digging & debugging is that when I don't import the object type Task but create it locally, setting the ACL does not cause the error:

const task = new Parse.Object('Task', args);
task.setACL(acl); // <-- no error

@ArMouReR
Copy link
Author

My code that works right now on Parse server:
`
Parse.Cloud.afterSave(Parse.User, function (request) {
var user = request.object;
if (!user.existed()) {
var acl = Utils.getAclForUser(user) ;
user.setACL(acl);
user.save(null, {useMasterKey: true});
}
});

getAclForUser: function (user) {
    var acl = new Parse.ACL(user);
    acl.setRoleReadAccess("admin", true);
    acl.setRoleWriteAccess("admin", true);
    return acl;
}

`

@drbarto
Copy link

drbarto commented Jan 14, 2018

@ArMouReR Thanks! The new (working) code looks almost identical to the old (problematic) code in your original post, so I guess the code itself is ok -- the problem must be related to some contextual issue that you somehow solved. Heads up for fixing your bug, I hope I get mine fixed as well :)

@drbarto
Copy link

drbarto commented Jan 16, 2018

@flovilmart In case you are still interested: the issue was caused by having global.Parse = require('parse/node') in a global Mocha test setup file; when running all integration tests (> 300 tests, taking about 4 minutes) this caused some weird effects like the mentioned Tried to create an ACL with an invalid permission type, but also You cannot use [object Object] as a query parameter; both errors only occurred when the runtime was under heavy load and running all tests -- just running a single test never produced any errors.

@flovilmart
Copy link
Contributor

Ok, maybe related to side effects of having parse global. I believe in test environments, you should disable the single instance per object: http://parseplatform.org/Parse-SDK-JS/api/v1.11.0/Parse.Object.html#.disableSingleInstance

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

4 participants