配置安全性以仅允许某些用户更新条目,但允许在 Backand 中读取所有用户
Configure Security to allow update of entries only for some users but allow read for all in Backand
是否可以配置 table 的安全性,只允许数据库 table 中某个条目的某些用户(所有者)修改该条目?
例如,在笔记应用程序中,每条笔记都分配给拥有该笔记的用户列表。所有用户都应该能够看到所有注释,但只有该节点的所有者才能 edit/delete 此注释条目。
我只找到了一个解决方案来过滤谁可以看到笔记但不能过滤谁可以编辑笔记。
您需要为此创建一个操作。
转到操作 table。 Select 更新期间事件。
这是取自 https://github.com/backand/todos-with-users
的示例
// if the current user has an *Admin* role then he is allowed to update a todo for other users
if (userProfile.role == "Admin")
return {};
if (!dbRow.created_by)
throw new Error('Todo with no creator can\'t be updated.');
// do not allow users to change the created by field
if (dbRow.created_by != userInput.created_by)
throw new Error('You can\'t change the creator of the todo.');
// do not allow non *Admin* users to change the creator of the todo
if (dbRow.created_by != userProfile.userId)
throw new Error('You can only update your own todo.');
return {};
是否可以配置 table 的安全性,只允许数据库 table 中某个条目的某些用户(所有者)修改该条目?
例如,在笔记应用程序中,每条笔记都分配给拥有该笔记的用户列表。所有用户都应该能够看到所有注释,但只有该节点的所有者才能 edit/delete 此注释条目。
我只找到了一个解决方案来过滤谁可以看到笔记但不能过滤谁可以编辑笔记。
您需要为此创建一个操作。 转到操作 table。 Select 更新期间事件。 这是取自 https://github.com/backand/todos-with-users
的示例// if the current user has an *Admin* role then he is allowed to update a todo for other users
if (userProfile.role == "Admin")
return {};
if (!dbRow.created_by)
throw new Error('Todo with no creator can\'t be updated.');
// do not allow users to change the created by field
if (dbRow.created_by != userInput.created_by)
throw new Error('You can\'t change the creator of the todo.');
// do not allow non *Admin* users to change the creator of the todo
if (dbRow.created_by != userProfile.userId)
throw new Error('You can only update your own todo.');
return {};