加入权限管理

This commit is contained in:
marvzhang
2020-03-20 17:43:11 +08:00
parent 1e2b580ed4
commit fa62e1a2dc
26 changed files with 437 additions and 70 deletions

20
backend/services/auth.go Normal file
View File

@@ -0,0 +1,20 @@
package services
import (
"crawlab/constants"
"github.com/gin-gonic/gin"
"github.com/globalsign/mgo/bson"
)
func GetAuthQuery(query bson.M, c *gin.Context) bson.M {
user := GetCurrentUser(c)
if user.Role == constants.RoleAdmin {
// 获得所有数据
return query
} else {
// 只获取自己的数据
query["user_id"] = user.Id
return query
}
}