2015-10-05 76 views
3

我是Parse的開埠者。我以前一直在用django和django rest框架進行很多工作。我最近開始着手解析並且喜歡它,但是在我的腦海裏有一些困惑,我一直無法通過閱讀文檔來解決這個問題。解析:如何限制對Parse中對象的某些屬性的訪問?

我想限制訪問一個對象的某些屬性(/場),而不是整個對象作爲在Parse Documentation

描述例如,我有

user1 = { 
    name: "a", 
    ... 
} 

user2 = { 
    name: "b", 
    ... 
} 

and there is a object

pet = { 
    type: "Cat", 
    name: "abc", 
    hungry: true, 
} 

現在我想要一個設置,其中「user1」對象只能訪問對象「寵物」的「類型」和「名稱」屬性,而「用戶2」可以訪問「寵物」的所有三個屬性。

如何在Parse中添加這些屬性級權限?我希望我明確表達我的觀點。

回答

2

ACL是最具體的控制手段,它只能用於對象級別。在一個對象,你可以通過應用程序邏輯執行,或打斷對象分成幾部分......

Pet = { name: "Toonces", 
     type: "Cat", 
     restrictedPet:<pointer to RestrictedPet>, 
     ACL: everyone } 

RestrictedPet = { hungry: true, 
        canDriveACar: true, 
        ACL: user2 } 

當查詢寵物(比如,在JS),你可以無條件地這樣說:

var petQuery = new Parse.Query("Pet"); 
petQuery.include("restrictedPet"); 
petQuery.first(then(function(pet) { 
    if (pet.restrictedPet) { 
     // when user2 is running, she will see restricted attributes here 
     console.log("Can my pet drive? " + pet.restrictedPet.canDriveACar); 
    } 
    // the remainder of the attributes are visible here, to all 
}); 
+3

耶知道了謝謝 –