2017-08-31 122 views
0
用戶/角色的訪問

是否有解析服務器使用ACL拒絕訪問項目爲特定用戶或角色的方法嗎?拒絕與ACL

說我有一個社交網絡應用程序,用戶發佈更新。我有一個名爲all_users的角色,將所有註冊用戶添加到該角色中。除了作者已被封鎖的用戶以外,所有更新均可由此角色讀取。

我可以授予讀取和寫入權限的用戶/角色,但是,消除讀寫通過解析儀表板的訪問完全刪除的條目。

提示將不勝感激。

回答

1

我不是100%肯定的答案,所以我做了什麼,我通常會做,做一個單元測試來弄明白。

當它發生時,我正在一家公關創建一個「所有用戶角色」,這將提高對您目前的解決方案,特別是如果你的社交網絡起飛和你有很多很多的用戶。

見問題:https://github.com/parse-community/parse-server/issues/4107

你可以跟蹤我的解決方案的當前狀態(目前的工作,但還沒有準備好,只是還沒有合併)位置:https://github.com/parse-community/parse-server/pull/4111

但是,所有我的工作on是'所有用戶角色'的情況,而不是'拒絕用戶'你需要的情況。

我做了什麼,以測試你的問題是從我的PR擴展單元測試來解決您的特定(有趣)的使用情況:

it('should respect for read.', function (done) { 
    let role, user; 

    const userP = new Parse.User() 
    .set('username', 'userA') 
    .set('password', 'password') 
    .save() 
    .then((user) => Parse.User.logIn(user.get('username'), 'password')); 

    const roleP = new Parse.Role('aRole', new Parse.ACL()) 
    .save(); 

    Parse.Promise.when(userP, roleP) 
    .then((newUser, newrole) => { 
     user = newUser; 
     role = newrole; 
     const acl = new Parse.ACL(); 
     acl.setRoleReadAccess(role, true); 
     return new Parse.Object('Foo') 
     .setACL(acl) 
     .save(); 
    }) 
    .then(() => new Parse.Query('Foo').first()) 
    .then((obj) => { 
     expect(obj).not.toBeDefined(); 
     return new Parse.Query(Parse.Role) 
     .equalTo('name', '_All_Role') 
     .first() 
    }) 
    .then((allRole) => { 
     expect(allRole).toBeDefined(); 

     const roles = role.relation('roles'); 
     roles.add(allRole); 
     return role.save(null, { useMasterKey: true }); 
    }) 
    .then(() => new Parse.Query('Foo').first()) 
    .then((obj) => { 
     expect(obj).toBeDefined(); 
     const acl = obj.getACL(); 
     acl.setReadAccess(user.id, false); // <--- this is what you want!!! 
     console.log(acl); 
     const valid = obj.setACL(acl); 
     expect(valid).toBe(true); 
     return obj.save(); 
    }) 
    .then(() => new Parse.Query('Foo').first()) 
    .then((obj) => { 
     expect(obj).not.toBeDefined(); // <--- but this fails :(.... 
     done(); 
    }) 
    .catch(done.fail); 
}); 

正如我懷疑,測試失敗。我不擅長解析權限(雖然是學習),但我目前的理解是,在沒有優先級的概念的情況下,所以一旦通過所有人組添加了權限,就無法「否認」。換句話說,當前的權限模型是添加了權限,但沒有明確拒絕。

您的使用情況是引人注目的,但這樣找到一種方法,以適應你的使用情況會很有趣。通常情況下,無論你是否需要弄清楚如何添加它以使其可以被一般用例所接受,或者招募能夠(不是志願者)的人,我的跳舞卡片已經滿了:)。