在设计 Stack Overflow 使用的基于点的权限系统时,需要考虑哪些架构最佳实践?

发布于 2024-10-19 01:42:39 字数 583 浏览 4 评论 0原文

Stack Overflow 有一个基于点的权限系统,它决定了网站上的很多内容,例如您可以编辑的内容以及向系统添加新标签的能力。

您会给设计此类系统的人什么建议,特别是在架构实现方面?您在哪里存储权限?如何使用这些权限来确定哪些字段在视图中显示为可编辑?有没有好的开源代码示例可以学习?

关于对象模型(例如问题或文档)的所有权或共享,在该对象模型上存储对该所有者的引用与在帐户模型中存储对该对象的引用有何优缺点?例如

document = { id:          21234,
             owner_id:    4d3ca9f1c067,
             shared_with: [a50d1e000138, 4d3ca9f1c067a, 50d1e000138] }

user = { id:              4d3ca9f1c067,
         documents_owned: [21234, 31452, 12312],
         collaborates_on: [23432, 43642, 12314, 23453] }

Stack Overflow has a points-based permissions system that determines a lot of things on the site, such as what you can edit and the ability to add new tags to the system.

What advice, specifically with regards to architectural implementation, would you give to someone designing such a system? Where do you store permissions? How do you use these permissions to determine what fields appear editable in the view? Are there any good open-source code examples to study from?

With regards to ownership or sharing of a object model such as a question or document, what are the pros/cons of storing a reference to the owner on that object's model versus storing a reference to that object in the account model? e.g.

document = { id:          21234,
             owner_id:    4d3ca9f1c067,
             shared_with: [a50d1e000138, 4d3ca9f1c067a, 50d1e000138] }

vs.

user = { id:              4d3ca9f1c067,
         documents_owned: [21234, 31452, 12312],
         collaborates_on: [23432, 43642, 12314, 23453] }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断肠人 2024-10-26 01:42:39

将权限作为需要权限的点对存储在单独的模型中。

在视图中,参考上面描述的权限模型,确定登录用户是否有足够的权限来显示每个项目。

模型选项:我更喜欢前者,因为(1)它具有更简单、更扁平的结构,因此在列出问题时不会通过用户表进行嵌套循环,并且(2)删除文档不需要更新用户对象。 (除非他们的分数因文档被删除等而下降。)

Store the permission in a separate model as permission-required points pairs.

In the view, determine whether the logged-in user has sufficient permissions per item to display, referring to the permissions model described above.

Model options: I'd prefer the former since (1) it has a simpler, flatter structure, so no nested loops through the user table when listing questions, and (2) deleting a document will not entail updating a user object. (Unless their score drops when the doc is deleted or such.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文