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

Parse Server Cloud Code - Destroy with masterKey #910

Closed
sanergulec opened this issue Mar 8, 2016 · 7 comments
Closed

Parse Server Cloud Code - Destroy with masterKey #910

sanergulec opened this issue Mar 8, 2016 · 7 comments
Labels
type:question Support or code-level question

Comments

@sanergulec
Copy link

Hello,

I am trying to delete an object with the code below, but I tried lots of things and could not make it work. Am I doing something wrong in the code below?

            var notifications = Parse.Object.extend('notifications');
            var query3 = new Parse.Query(notifications);
            query3.equalTo('useridActionTaker', req.object.get('userid'));
            query3.find({useMasterKey: true}).then(function(result3) {


                  if ( result3.length > 0 ) {

                      return result3[0].destroy(null, { useMasterKey: true });

                  }

                  else {

                  }

              });
@drew-gross
Copy link
Contributor

Can you add some logging to the destroy call to determine what the error message it?

@sanergulec
Copy link
Author

I found that when I set the CLP write permission to public it is working, but when I remove the write permission, it is not. Am I using the "useMasterKey" wrong? Actually the read permission will be public, but the write permission wont be.

@drew-gross
Copy link
Contributor

No, that should be the correct way to use master key. Can you check if the error from the destroy call is a permission error vs. some other error?

@sanergulec
Copy link
Author

Hello drew-gross,

I tried to add the error log as below, and see the error, but it somehow started to work:) I guess it is because I removed the "null" part in the destroy while adding the success and error logs.

            var notifications = Parse.Object.extend('notifications');
            var query3 = new Parse.Query(notifications);
            query3.equalTo('useridActionTaker', req.object.get('userid'));
            query3.find({useMasterKey: true}).then(function(result3) {

                  if ( result3.length > 0 ) {

                      return result3[0].destroy({ useMasterKey: true,

                        success: function(result3)
                        {
                        },                  
                        error: function(error)
                        {
                          console.error(error.message);
                        }

                      });


                  }

                  else {

                  }

            });

@brendankopp
Copy link

brendankopp commented May 29, 2017

I realize this was closed, but I came across the same issue and can confirm that removing null solved the problem.

If the class has a restricted CLP in place this works:

object.destroy({useMasterKey: true});

but this does not:

object.destroy({null, useMasterKey: true});

@OpConTech
Copy link

Same here....had to remove the null.
Seems that unlike user.save there does not seem to be a first parameter in user.destroy so:

user.destroy(null, {useMasterKey:true}); // Does not work
user.destroy({useMasterKey:true}); // Works!

@JacobJT
Copy link

JacobJT commented Mar 8, 2018

That makes sense, as the first parameter of save() is a dictionary of keys to update and their value. With destroy(), you're not updating any values before doing the destroy.

If you look at the documentation for destroy(), it has only one argument: An options parameter, which is where you could add success / error handlers, as well as the session / master key.
http://parseplatform.org/Parse-SDK-JS/api/v1.11.1/Parse.Object.html#destroy

Whereas the save() documentation shows that there are several appropriate combinations of arguments: http://parseplatform.org/Parse-SDK-JS/api/v1.11.1/Parse.Object.html#save

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

6 participants