簡體   English   中英

解析400錯誤請求setACL

[英]Parse 400 Bad Request 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: "myusername@email.com"}, {
        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文檔中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM