我需要在文档级别控制 SubClient 用户类型在登录时在列表中看到的内容。
我有表 userTable
和 docTable
。
该应用程序只是一个团队文档应用程序。经理登录并设置一个客户端,在该客户端下是关联的文档和任意数量的子客户端,但通常都在 4 或 5 左右。客户端、子客户端和文档组成一个组。客户一对多=>子客户和客户=>文档。单向。
我有这个UI控制“子客户端”在登录时看到的 PDF。从数据库的角度来看,处理文档级读取权限的最佳方法是一个简单的 userDocJunctionTable
,其中包含 userID、DocID、AccessRightCode
字段。
我觉得我没有想到什么,我发现的每个例子对于这个应用程序来说都过于复杂,比如 databaseanswers.org/.../document_management_for_security .
JIC 这是一个 Yii2 应用程序,具有基于数据库的 RBAC 身份验证。
最佳答案
CREATE TABLE userTable
(
UserID int PRIMARY KEY,
UserEmail varchar(50) NOT NULL,
UserPassword varchar(50) NOT NULL
);
CREATE TABLE documentTable
(
DocumentID int PRIMARY KEY,
DocumentDescription varchar(500) NOT NULL
);
CREATE TABLE UDJunction
(
-- User/Document Junction table
id int auto_increment primary key,
userId int not null,
documentId int not null,
-- charlyRoot (OP) had this:
readaccess tinyint not null, -- 1 = yes, 0 no
-- Drew recommends this (extensible to dozens of permissions per file):
docPermissions int not null, -- or just jam a bitmask in here (bit OR)
unique key(userId,documentId), -- WHAT IS THIS USED FOR?
key (documentId,userId),
CONSTRAINT fk_ud_user FOREIGN KEY (userId) REFERENCES userTable(userId),
CONSTRAINT fk_ud_documents FOREIGN KEY (documentId) REFERENCES documentTable(documentId)
);
Drew 的引用资料来自 here :
unique key(studentId,courseId,term), -- no duplicates allowed for the combo (note student can re-take it next term) key (courseId,studentId),
关于php - 文档级读取权限联结表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38043577/