提问人:user22926391 提问时间:11/16/2023 最后编辑:philipxyuser22926391 更新时间:11/17/2023 访问量:43
角色和许可架构设计问题
Roles and permissioned schema design issue
问:
我正在开发一个多租户 QSR 食品计费 SaaS 网站,系统中有一个超级管理员来管理整个应用程序。超级管理员可以创建多个租户,每个租户可以创建多个品牌。每个品牌都可以创建多个网点/部署。每个网点可以有多个员工或用户负责 QSR 计费。
我想将应用程序转换为基于角色的许可应用程序:某些用户(例如超级管理员或租户管理员)有权创建角色,并且默认情况下某些权限链接到角色。有一些选项可以向某些用户授予更多或更少的权限。权限最高可达 4-5k,因此我没有创建权限集合并将用户存储在具有指定权限的数组中,而是将权限存储在用户架构中,指定哪些用户具有哪些权限。
我应该如何将权限直接链接到角色?
如何将默认权限直接链接到任何角色,以便在创建新角色时,它必须具有一些默认权限,并且可以根据要求增加和减少权限?
有哪些更改,以便角色可以链接到权限,并提供切换某些角色权限的选项?
var userSchema = new mongoose.Schema(
{
name:{
firstName: {
type: String,
required: true,
},
lastName: {
type: String,
},
},
username: {
type: String,
required: true,
unique: true,
},
email: {
type: String,
required: true,
unique: true,
},
password: {
type: String,
required: true,
},
mobileNumber: {
type: Number,
required: true,
},
role: {
type: String,
enum: ["superAdmin","tenantAdmin", "brandAdmin", "outletAdmin", "employee"],
required: true,
},
tenantDetails:{
_id:mongoose.Schema.Types.ObjectId,
name:String,
},
brandDetails: {
_id: mongoose.Schema.Types.ObjectId,
name: String,
},
outletDetails: {
_id: mongoose.Schema.Types.ObjectId,
name: String,
},
permissions: [
{
name: {
type: String,
unique: true,
required: true,
},
operations: {
create: {
type: Boolean,
default: false,
},
read: {
type: Boolean,
default: false,
},
update: {
type: Boolean,
default: false,
},
delete: {
type: Boolean,
default: false,
},
},
},
],
address: {
location: {
type: String,
required: true,
},
state:{
type: String,
required:true,
},
city: {
type: String,
required: true,
},
pincode: {
type: Number,
required:true
},
},
profilePhoto: {
type: String,
default:
"https://upload.wikimedia.org/wikipedia/commons/thumb/f/f9/OOjs_UI_icon_userAvatar-constructive.svg/2048px-OOjs_UI_icon_userAvatar-constructive.svg.png",
},
isDeleted: {
type: Boolean,
default: false,
},
isActive: {
type: Boolean,
default: true,
},
},
{ timestamps: true }
);
答: 暂无答案
评论