mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-24 17:41:03 +01:00
加入权限管理
This commit is contained in:
20
backend/services/auth.go
Normal file
20
backend/services/auth.go
Normal 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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user