私ならこうします。
table name: permission
columns: id, permission_name
次に、多対多の関係テーブルを使用して、ユーザーに複数の権限を割り当てることができます
table name: user_permission
columns: permission_id, user_id
この設計により、必要な数のアクセス許可を追加し、必要な数のユーザーに割り当てることができます。
上記の設計は要件に合いますが、アプリケーションに ACL を実装する独自の方法があります。ここに投稿しています。
私の ACL の実装方法は次のようになります。
- ユーザーにロールが割り当てられます (管理者、ゲスト、スタッフ、パブリック)
- ロールには、1 つまたは複数の権限が割り当てられます (user_write、user_modify、report_read) など。
- ユーザーの権限は、そのユーザーが属するロールから継承されます
- ユーザーには、ロールから継承された権限とは別に、手動の権限を割り当てることができます。
これを行うために、次のデータベース設計を考え出しました。
role
I store the role name here
+----------+
| Field |
+----------+
| id |
| role_name |
+----------+
permission:
I store the permission name and key here
Permission name is for displaying to user.
Permission key is for determining the permission.
+----------------+
| Field |
+----------------+
| id |
| permission_name |
| permission_key |
+----------------+
role_permission
I assign permission to role here
+---------------+
| Field |
+---------------+
| id |
| role_id |
| permission_id |
+---------------+
user_role
I assign role to the user here
+---------------+
| Field |
+---------------+
| id |
| user_id |
| role_id |
+---------------+
user_permission
I store the manual permission I may allow for the user here
+---------------+
| Field |
+---------------+
| id |
| user_id |
| permission_id |
+---------------+
これにより、ACL をより詳細に制御できます。スーパー管理者が自分で権限を割り当てることを許可できます。私が言ったように、これはあなたにアイデアを与えるためのものです.