解析400错误请求setACL

马特斯特

我有一个“管理员”角色,我想分配给当前解析中的所有User对象。但是,无论我尝试什么,都会出现400错误。当我尝试通过仪表板手动添加ACL时,它不会保存。例如,我将输入“ {” role:Administrator“:{” read“:true,” write“:true}}”“,刷新后它将恢复为(未定义)。

编辑:所以我尝试创建一个Cloud Code函数。尝试运行该功能时,在“结果:错误:未定义的未授权”旁边仍收到400错误。

main.js(云代码):

Parse.initialize("*****", "*****");
Parse.Cloud.define("modifyUser", function(request, response) {
    if (!request.user) {
        response.error("Must be signed in to call this Cloud Function.")
    return;
    }

    // The rest of the function operates on the assumption that request.user is *authorized*
    Parse.Cloud.useMasterKey();

    var query = new Parse.Query(Parse.User);
    query.find({
        success: function(results) {
        response.success("Successfully retrieved " + results.length + " scores.");
        // Do something with the returned Parse.Object values
        for (var i = 0; i < results.length; i++) { 
            var object = results[i];
            alert(object.id + ' - ' + object.get('objectId'));
        }
        },
        error: function(error) {
            response.error("Error: " + error.code + " " + error.message);
        }
    });

});

我的客户端.js文件:$(function(){console.log(“正在运行的仪表板”); Parse.initialize(“ **”,“ ** ”);

    Parse.Cloud.run('modifyUser', {username: "[email protected]"}, {
        success: function(result) {
        // result is 'Hello world!'
        console.log(result);
         },
        error: function(error) {
            console.log("error: " + error.code + " " + error.message);
        }
    });
});

更新之前:理想情况下,我想遍历Javascript文件中的所有用户,并使用以下代码更新其角色:

// set up ACL for User object
var userACL = new Parse.ACL();
userACL.setRoleWriteAccess("Administrator", true);
userACL.setRoleReadAccess("Administrator", true);

// grab all Users
var user_query = new Parse.Query(Parse.User);
user_query.find( {
    success: function(users) {
        // querying all users works successfully
        console.log(users);
        // assign Administrator ACL to each user
        for (var i=0; i<users.length; i++) {
            users[i].setACL(userACL);
            users[i].save(null, {
                success: function(user) {
                    console.log("save successfully");
                },
                error: function(error) {
                    console.log("error saving: " + error.code + " " + error.message);
                }
            });
        }
    },
    error: function(error) {
        console.log("error: " + error.code + " " + error.message);
    }
});

但是,这将返回以下内容:POST https://api.parse.com/1/classes/_User/userID此处为我尝试保存的每个用户显示400(错误请求),“用户对象不允许其他用户写入”,尽管我的用户在管理员角色下列出。

任何帮助将不胜感激。

马特斯特

好吧,我已经解决了我的问题。您不应该在Cloud Code函数中使用Parse.initialize,并且当然不能与useMasterKey一起使用。这是我偶然发现的链接:https : //www.parse.com/questions/usemasterkey-and-modifying-user-results-in-unauthorized

这确实应该在Cloud Code文档中。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章