作者 tangxvhui

权限校验模块设计开始

... ... @@ -14,7 +14,7 @@ type AuthController struct {
//URLMapping 实现ControllerInterface中的URLMapping
func (c *AuthController) URLMapping() {
c.Mapping("RefreshToken", c.RefreshToken)
}
// RefreshToken ....
... ...
package routers
// type PermissionBase struct {
// Check int8 `json:"check"`
// }
//PermissionBase 路由对应的权限
type PermissionBase struct {
CodeName string //模块标识
ActionName string
MethodMap map[string]func()
}
func (p PermissionBase) ValidMapping(actionName string, fn func()) {
p.MethodMap[actionName] = fn
}
//职位管理相关
var routerPermission = map[string]PermissionBase{
"/v1/department/list": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "check"},
"/v1/department/add": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "add"},
"/v1/department/edit": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "edit"},
"/v1/department/delete": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "delete"},
}
//PermissionWithPosition 职位管理相关
type PermissionWithPosition struct {
Check int8 `json:"check"`
PermissionBase
}
func (c PermissionWithPosition) Code() string {
return "OPPMG_POSITION"
//GetCode 模块标识
func (c *PermissionWithPosition) GetCodeName() string {
return "OPPMG_DEPARTMENT"
}
//部门管理相关
type PermissionWithDepart struct {
Check int8 `json:"check"`
//Valid 权限校验
func (c PermissionWithPosition) Valid(userCompanyID int64) bool {
return true
}
//PermissionWithDepart 部门管理相关
// type PermissionWithDepart struct {
// Check int8 `json:"check"`
// }
... ...
... ... @@ -89,11 +89,3 @@ func init() {
beego.SetStaticPath("/log", beego.AppConfig.String("log_filename"))
}
//routerPermission 路由对应的权限
// var routerPermission = map[string]string{
// : "show",
// "post:/v1/company/position": "add",
// "put:/v1/company/position": "edit",
// "delete:/v1/company/position": "delete",
// }
... ...
... ... @@ -147,6 +147,61 @@ token 的响应内容
## 公司部门管理
### 部门列表
- 请求路径:/v1/department/list
- 请求方式:post
- 请求 json:
```json
{
}
```
- 正常响应 json
```json
{
"code": 0,
"msg": "成功",
"data": {
"list": [
{
"id": 1,
"company_id": 1,
"name": "部门1",
"parant_id": 0,
"manages": [{
"id":1,
"name":"主管"
}],
"member": 1
},
{
"id": 2,
"company_id": 1,
"name": "部门1-2",
"parant_id": 1,
"manages": [{
"id":1,
"name":"主管"
}],
"member": 1
}
]
}
}
```
- 备注;无
---
### 添加部门
- 请求路径:/v1/department/add
... ... @@ -234,6 +289,79 @@ token 的响应内容
## 公司职位管理
### 职位列表
- 请求路径:/v1/position/list
- 请求方式:post
- 请求 json:
```json
{
}
```
- 响应 json
```json
{
"code": 0,
"msg": "成功",
"data": [
{
"id": 1,
"name": "董事长",
"parent_id": 0
},
{
"id": 2,
"name": "总经理",
"parent_id": 1
},
{
"id": 3,
"name": "副总经理",
"parent_id": 2
},
{
"id": 4,
"name": "技术总监",
"parent_id": 2
},
{
"id": 5,
"name": "职位a",
"parent_id": 0
},
{
"id": 6,
"name": "职位b-1",
"parent_id": 9
},
{
"id": 7,
"name": "职位a-2",
"parent_id": 5
},
{
"id": 8,
"name": "职位a-1-1",
"parent_id": 6
},
{
"id": 9,
"name": "职位b-1",
"parent_id": 0
}
]
}
```
- 备注;无
---
### 添加职位
- 请求路径:/v1/position/add
... ... @@ -320,6 +448,129 @@ token 的响应内容
---
## 公司员工角色
### 角色列表
- 请求路径:/v1/rbac/role/list
- 请求方式:post
- 请求 json:
```json
{
}
```
- 响应 json
```json
{
"code": 0,
"msg": "成功",
"data": {
"list": [
{
"id": 1,
"company_id": 1,
"name": "部门1",
"parant_id": 0,
"manages": [],
"members": [
{
"id": 1,
"name": "Jennifer Clark"
}
],
"member": 1
},
{
"id": 2,
"company_id": 1,
"name": "部门1-2",
"parant_id": 1,
"manages": [],
"members": [],
"member": 1
},
{
"id": 3,
"company_id": 1,
"name": "部门1-2-3",
"parant_id": 2,
"manages": [],
"members": [],
"member": 0
},
{
"id": 4,
"company_id": 1,
"name": "部门1-2-4",
"parant_id": 2,
"manages": [],
"members": [],
"member": 0
},
{
"id": 5,
"company_id": 1,
"name": "部门1-2-5",
"parant_id": 3,
"manages": [],
"members": [],
"member": 0
},
{
"id": 7,
"company_id": 1,
"name": "部门1-2-5-7",
"parant_id": 5,
"manages": [],
"members": [],
"member": 0
},
{
"id": 10,
"company_id": 1,
"name": "部门2",
"parant_id": 0,
"manages": [],
"members": [],
"member": 0
},
{
"id": 26,
"company_id": 1,
"name": "部门名称1",
"parant_id": 1,
"manages": [
{
"id": 1,
"name": "Jennifer Clark"
}
],
"members": [],
"member": 0
},
{
"id": 27,
"company_id": 1,
"name": "部门名称1",
"parant_id": 1,
"manages": [],
"members": [],
"member": 0
}
]
}
}
```
- 备注;无
---
### 添加角色
... ...