根据信誉实施权限 [英] Implementing permissions based on reputation

查看:61
本文介绍了根据信誉实施权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个网站,其中有项目,用户和每个用户或用户组的权限.这是一个社区协作工具,我有4个不同的权限:

I'm creating a website in which there are projects, users, and permissions for each user or groups of users. What this is is a community collaboration tool, and I have 4 different permissions:

  • 创建者-进行更改,接受更改,更改权限
  • 接受更改
  • 进行更改
  • 查看

我如何在数据库中为用户组实现这种权限系统?

How could I implement, in a database, this kind of permission system, for groups of users?

组/权限是由信誉定义的,就像在StackOverflow上一样.

Groups/permissions are defined by reputation, like on StackOverflow.

编辑2-更详细:每个文件都需要具有权限,项目需要新创建文件的默认权限,并且我还需要设置MySQL数据库权限.

Edit 2 - more in detail: Each file needs to have a permission, projects need default permissions for newly created files, and I also need to set up MySQL database permissions.

推荐答案

user_table
id, etc

permission table
id, user_id, permission_type

采用这种结构,每个用户可以拥有与其帐户相关联的几种权限类型,一种可以可以访问的功能集.您将无需更改表结构即可添加新的权限类型.

with this structure, each user could have several permission types associated with their account, one for each set of features they could have access to. you would never need to change the table structure in order to add new types of permissions.

要更进一步,您可以将每种类型的权限都设置为二进制数.这样,您可以使用按位运算符使一组权限由一个整数表示.

to take this a step further, you could make each type of permission a binary number. this way you could make a set of permissions be represented by one integer by using bitwise operators.

例如,如果您有常量

PERMISSION_CHANGE_PERMISSIONS = bindec('001') = 1
PERMISSION_MAKE_CHANGES = bindec('010') = 2
PERMISSION_ACCEPT_CHANGES = bindec('100') = 4

您可以使用按位运算符"|"将这些值组合为一个整数

you could combine these values into one integer using a bitwise operator "|"

(PERMISSION_CHANGE_PERMISSIONS | PERMISSION_MAKE_CHANGES) = bindec('011') = 3 = $users_combined_permissions

然后要检查它们是否具有特定权限,请使用按位运算符&"

then to check if they have a specific permission, use the bitwise operator "&"

($users_combined_permissions & PERMISSION_MAKE_CHANGES) = true

如果这样做,则每组权限只需要一个数据库记录.

if you did that, you would only need one db record for each set of permissions.

这篇关于根据信誉实施权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆