2017-08-31 126 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); 
}); 

正如我怀疑,测试失败。我不擅长解析权限(虽然是学习),但我目前的理解是,在没有优先级的概念的情况下,所以一旦通过所有人组添加了权限,就无法“否认”。换句话说,当前的权限模型是添加了权限,但没有明确拒绝。

您的使用情况是引人注目的,但这样找到一种方法,以适应你的使用情况会很有趣。通常情况下,无论你是否需要弄清楚如何添加它以使其可以被一般用例所接受,或者招募能够(不是志愿者)的人,我的跳舞卡片已经满了:)。