-
Notifications
You must be signed in to change notification settings - Fork 0
/
org.go
57 lines (52 loc) · 1.38 KB
/
org.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package Router2Mid
import (
OrgCore "github.com/fotomxq/weeekj_core/v5/org/core"
"github.com/gin-gonic/gin"
)
// headerSelectedOrg 行政组织专用顶层头
// 用于组织和用户级别通用设计
// 必须建立在RouterMiddleware.HeaderLoggedUser(c)基础之上,即路由需设计多层函数关系构建
func headerSelectedOrg(c *gin.Context) {
//获取数据
tokenInfo := GetTokenInfo(c)
//检查权限
if !checkPermissionUser(c, tokenInfo.UserID, tokenInfo.OrgID, []string{"org"}) {
return
}
//存储数据
c.Set("selectOrgID", tokenInfo.OrgID)
c.Set("selectOrgBindID", tokenInfo.OrgBindID)
//获取权限列
c.Set("selectOrgBindPermissions", OrgCore.GetPermissionByBindID(tokenInfo.OrgBindID))
//继续执行
c.Next()
}
func getOrgID(c *gin.Context) (orgID int64) {
dataAny, b := c.Get("selectOrgID")
if !b {
data := c.MustGet("OrgData").(OrgCore.FieldsOrg)
orgID = data.ID
} else {
orgID = dataAny.(int64)
}
return
}
func getOrgBindID(c *gin.Context) (bindID int64) {
dataAny, b := c.Get("selectOrgBindID")
if !b {
data := c.MustGet("OrgBindData").(OrgCore.FieldsBind)
bindID = data.ID
} else {
bindID = dataAny.(int64)
}
return
}
func getOrgBindPermissions(c *gin.Context) (data []string) {
dataAny, b := c.Get("selectOrgBindPermissions")
if !b {
data = c.MustGet("OrgBindPermissions").([]string)
} else {
data = dataAny.([]string)
}
return
}