我需要在文档级别控制SubClient的用户类型在登录时在列表中看到的内容。
我有表userTable
和docTable
。
该应用程序只是一个团队文档应用程序。管理员登录并设置客户端,在该客户端下是任意数量的关联文档和子客户端,但通常都是4或5左右。客户端,子客户端和文档组成一个组。客户一对多=>子客户和客户=文档。单向的。
我有UI来控制'SubClient'在登录时看到的PDF。从数据库的角度来看,处理文档级读取权限的最佳方法是使用{{1}的简单userDocJunctionTable
}}领域。
我觉得我没有想到什么,我发现的每个例子对于这个应用来说都过于复杂,比如databaseanswers.org/.../document_management_for_security。
JIC它是基于DB的RBAC身份验证的Yii2应用程序。
答案 0 :(得分:1)
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)
);
来自here的引用:
unique key(studentId,courseId,term), -- no duplicates allowed for the combo (note student can re-take it next term) key (courseId,studentId),