Skip to content

Commit

Permalink
fix(init): add rules & permission to init.js
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Mar 29, 2021
1 parent ce3ed49 commit 0107f03
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 33 deletions.
33 changes: 1 addition & 32 deletions init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,8 @@ const assert = require('assert')
const { MongoAccessor, getDb } = require('less-api')
const adminRules = require('./rules/admin.json')
const appRules = require('./rules/app.json')
const { permissions } = require('./permissions')

const permissions = [
{ name: 'role.create', label: '创建角色' },
{ name: 'role.read', label: '读取角色' },
{ name: 'role.edit', label: '编辑角色' },
{ name: 'role.delete', label: '删除角色' },

{ name: 'permission.create', label: '创建权限' },
{ name: 'permission.read', label: '读取权限' },
{ name: 'permission.edit', label: '编辑权限' },
{ name: 'permission.delete', label: '删除权限' },

{ name: 'admin.create', label: '创建管理员' },
{ name: 'admin.read', label: '获取管理员' },
{ name: 'admin.edit', label: '编辑管理员' },
{ name: 'admin.delete', label: '删除管理员' },

{ name: 'rule.create', label: '创建访问规则' },
{ name: 'rule.read', label: '获取访问规则' },
{ name: 'rule.edit', label: '编辑访问规则' },
{ name: 'rule.delete', label: '删除访问规则' },
{ name: 'rule.apply', label: '应用访问规则' },

{ name: 'function.create', label: '创建云函数' },
{ name: 'function.read', label: '获取云函数' },
{ name: 'function.edit', label: '编辑云函数' },
{ name: 'function.delete', label: '删除云函数' },
{ name: 'function.publish', label: '发布云函数' },
{ name: 'function.debug', label: '调试云函数' },

{ name: 'function_logs.read', label: '查看云函数日志' },
{ name: 'function_logs.delete', label: '查看云函数日志' }
]

const accessor = new MongoAccessor(Config.db.database, Config.db.uri, {
useNewUrlParser: true,
Expand Down
32 changes: 32 additions & 0 deletions init/permissions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
exports.permissions = [
{ name: 'role.create', label: '创建角色' },
{ name: 'role.read', label: '读取角色' },
{ name: 'role.edit', label: '编辑角色' },
{ name: 'role.delete', label: '删除角色' },

{ name: 'permission.create', label: '创建权限' },
{ name: 'permission.read', label: '读取权限' },
{ name: 'permission.edit', label: '编辑权限' },
{ name: 'permission.delete', label: '删除权限' },

{ name: 'admin.create', label: '创建管理员' },
{ name: 'admin.read', label: '获取管理员' },
{ name: 'admin.edit', label: '编辑管理员' },
{ name: 'admin.delete', label: '删除管理员' },

{ name: 'rule.create', label: '创建访问规则' },
{ name: 'rule.read', label: '获取访问规则' },
{ name: 'rule.edit', label: '编辑访问规则' },
{ name: 'rule.delete', label: '删除访问规则' },
{ name: 'rule.apply', label: '应用访问规则' },

{ name: 'function.create', label: '创建云函数' },
{ name: 'function.read', label: '获取云函数' },
{ name: 'function.edit', label: '编辑云函数' },
{ name: 'function.delete', label: '删除云函数' },
{ name: 'function.publish', label: '发布云函数' },
{ name: 'function.debug', label: '调试云函数' },

{ name: 'function_logs.read', label: '查看云函数日志' },
{ name: 'function_logs.delete', label: '查看云函数日志' }
]
4 changes: 3 additions & 1 deletion init/rules/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
".read": "$has('permission.read')",
".update": "$has('permission.edit')",
".add": "$has('permission.create')",
".remove": "$has('permission.delete')"
".remove": "$has('permission.delete')",
".count": "$has('permission.read')"
},
"roles": {
".read": "$has('role.read')",
Expand All @@ -32,6 +33,7 @@
},
"function_logs": {
".read": "$has('function_logs.read')",
".remove": "$has('function_logs.remove')",
".count": "$has('function_logs.read')"
}
}

0 comments on commit 0107f03

Please sign in to comment.