实施基于声誉的权限

2023-10-12php开发问题
0

本文介绍了实施基于声誉的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在创建一个网站,其中有每个用户或用户组的项目、用户和权限.这是一个社区协作工具,我有 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.

这篇关于实施基于声誉的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17