2014-08-27 48 views
0

我在解析中有一個成就類,而且_User可以在我正在處理的遊戲中的某個地方獲得成就。出於某種原因,沒有獲得成就的用戶應該無法看到關於它的信息。成就和ACL

我知道如何在傳統的數據庫模式(使用多對多關係)中實現它,但我想知道如何在Parse中使用爲這類事件設計的權限和ACL來實現它(我只看到如何使用ACL進行一對一的關係)。

我的想法是添加一個關係列到_User類。但是如何確保_User只能獲得他們獲得的成就信息。

我是否有義務將Cloud Code用於這類事情?

回答

1

您必須創建關聯表或更好的兩個表之間的分析關係。

https://parse.com/docs/relations_guide#manytomany

一類添加關係列如下:

enter image description here

如果關係到指定的成就存在,比用戶可以獲取他的信息

編輯1

Through ACL中,你可以做同樣的事情(我使用一些的OBJ-C代碼只是爲了解釋):

// Having the instance to an existing Achievement object 
PFObject* achievement = [PFObject objectWithClassName:kTbAchievements]; 
[achievement setObjectId:@"mwQipJGpSb"]; 
[achievement fetch]; // gain full object from Parse server 

// Way for get current achievement acl informations 
//PFACL* currentAchievementACL = [achievement ACL]; 

// Creation of ACL for this achivement (just for this example), otherwise use " 
// [achievement ACL]" for getting existing achievement ACL 

PFACL* acl = [PFACL ACL]; // Instance of new Acl object 

// allowing read access to user with objectId == userId1 
[acl setReadAccess:YES forUserId:@"userId1"]; 

// allowing read access to user with objectId == userId2 
[acl setReadAccess:YES forUserId:@"userId2"]; 

[achievement setACL:acl]; // assign new created ACL obj 
[achievement save]; // updating the achievement 


// check for user authorizations 
BOOL check1 = [acl getReadAccessForUserId:@"userId1"]; // YES, granted 
BOOL check2 = [acl getReadAccessForUserId:@"userId2"]; // YES, granted 
BOOL check3 = [acl getReadAccessForUserId:@"userId3"]; // NO, denied 

這是你要做什麼樣的儀表板爲您選擇的成就 enter image description here

希望它可以幫助

+0

我知道。謝謝,但你如何將這些關係與ACL關聯?實際上,我正在尋找一種動態ACL? – user1553136 2014-08-27 15:00:53

+0

好的,我將用可能的ACL解決方案編輯答案 – 2014-08-27 15:17:13

+0

謝謝!你認爲這是可擴展的嗎? – user1553136 2014-08-27 17:07:36

0

您是否擔心用戶黑客入侵Parse數據庫以瞭解他們沒有的成就?如果是這樣,那麼ACL是一個很好的解決方案。 ACL是爲了解決安全問題。

如果您希望他們只能看到他們在遊戲界面中所取得的成就,那麼我只會使用關係鏈接成​​就。這將是一個過濾問題。

您需要問自己,這是安全問題還是過濾問題。