[系统用户]实现基础的权限校验
This commit is contained in:
@@ -88,7 +88,16 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
defer this.CreateLogInfo("创建系统用户 %d", createResp.AdminId)
|
||||
|
||||
// 通知更改
|
||||
err = configloaders.NotifyAdminModuleMappingChange()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package admins
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
@@ -20,5 +21,12 @@ func (this *DeleteAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
// 通知更改
|
||||
err = configloaders.NotifyAdminModuleMappingChange()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ func init() {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth()).
|
||||
Data("teaMenu", "admins").
|
||||
Data("teaModule", "admin").
|
||||
Prefix("/admins").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/createPopup", new(CreatePopupAction)).
|
||||
GetPost("/updatePopup", new(UpdatePopupAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
Post("/updateOn", new(UpdateOnAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package admins
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
|
||||
type UpdateOnAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateOnAction) RunPost(params struct{}) {
|
||||
this.Success()
|
||||
}
|
||||
@@ -125,5 +125,12 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
// 通知更改
|
||||
err = configloaders.NotifyAdminModuleMappingChange()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ func init() {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth()).
|
||||
Helper(clusterutils.NewClustersHelper()).
|
||||
Data("teaModule", "node").
|
||||
Prefix("/clusters").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/create", new(CreateAction)).
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package dashboard
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
@@ -11,5 +14,14 @@ func (this *IndexAction) Init() {
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
this.RedirectURL("/servers")
|
||||
// 取得用户的权限
|
||||
module, ok := configloaders.FindFirstAdminModule(this.AdminId())
|
||||
if ok {
|
||||
for _, m := range configloaders.AllModuleMaps() {
|
||||
if m.GetString("code") == module {
|
||||
this.RedirectURL(m.GetString("url"))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ func init() {
|
||||
server.
|
||||
Helper(new(helpers.UserMustAuth)).
|
||||
Helper(new(Helper)).
|
||||
Data("teaModule", "dns").
|
||||
Prefix("/dns").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/updateClusterPopup", new(UpdateClusterPopupAction)).
|
||||
|
||||
@@ -10,6 +10,7 @@ func init() {
|
||||
server.
|
||||
Helper(new(helpers.UserMustAuth)).
|
||||
Helper(new(Helper)).
|
||||
Data("teaModule", "log").
|
||||
Prefix("/log").
|
||||
Get("", new(IndexAction)).
|
||||
Get("/exportExcel", new(ExportExcelAction)).
|
||||
|
||||
@@ -10,6 +10,7 @@ func init() {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth()).
|
||||
Helper(NewHelper()).
|
||||
Data("teaModule", "server").
|
||||
Prefix("/servers").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/create", new(CreateAction)).
|
||||
|
||||
@@ -10,6 +10,7 @@ func init() {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth()).
|
||||
Helper(NewHelper()).
|
||||
Data("teaModule", "setting").
|
||||
Prefix("/settings").
|
||||
Get("", new(IndexAction)).
|
||||
EndAll()
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
// 认证拦截
|
||||
type UserMustAuth struct {
|
||||
AdminId int
|
||||
AdminId int64
|
||||
Grant string
|
||||
}
|
||||
|
||||
@@ -48,12 +48,19 @@ func (this *UserMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramNam
|
||||
}
|
||||
|
||||
var session = action.Session()
|
||||
var adminId = session.GetInt("adminId")
|
||||
var adminId = session.GetInt64("adminId")
|
||||
if adminId <= 0 {
|
||||
this.login(action)
|
||||
return false
|
||||
}
|
||||
|
||||
// 检查用户权限
|
||||
teaModule := action.Data.GetString("teaModule")
|
||||
if len(teaModule) > 0 && !configloaders.AllowModule(adminId, teaModule) {
|
||||
action.WriteString("Permission Denied.")
|
||||
return false
|
||||
}
|
||||
|
||||
// 检查用户是否存在
|
||||
rpc, err := nodes.SharedRPC()
|
||||
if err != nil {
|
||||
@@ -111,7 +118,7 @@ func (this *UserMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramNam
|
||||
if !action.Data.Has("teaMenu") {
|
||||
action.Data["teaMenu"] = ""
|
||||
}
|
||||
action.Data["teaModules"] = this.modules()
|
||||
action.Data["teaModules"] = this.modules(adminId)
|
||||
action.Data["teaSubMenus"] = []map[string]interface{}{}
|
||||
action.Data["teaTabbar"] = []map[string]interface{}{}
|
||||
if len(config.Version) == 0 {
|
||||
@@ -142,12 +149,13 @@ func (this *UserMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramNam
|
||||
}
|
||||
|
||||
// 菜单配置
|
||||
func (this *UserMustAuth) modules() []maps.Map {
|
||||
return []maps.Map{
|
||||
func (this *UserMustAuth) modules(adminId int64) []maps.Map {
|
||||
allMaps := []maps.Map{
|
||||
{
|
||||
"code": "servers",
|
||||
"name": "网站服务",
|
||||
"icon": "clone outsize",
|
||||
"code": "servers",
|
||||
"module": configloaders.AdminModuleCodeServer,
|
||||
"name": "网站服务",
|
||||
"icon": "clone outsize",
|
||||
"subItems": []maps.Map{
|
||||
{
|
||||
"name": "通用设置",
|
||||
@@ -177,9 +185,10 @@ func (this *UserMustAuth) modules() []maps.Map {
|
||||
},
|
||||
},
|
||||
{
|
||||
"code": "clusters",
|
||||
"name": "边缘节点",
|
||||
"icon": "cloud",
|
||||
"code": "clusters",
|
||||
"module": configloaders.AdminModuleCodeNode,
|
||||
"name": "边缘节点",
|
||||
"icon": "cloud",
|
||||
"subItems": []maps.Map{
|
||||
{
|
||||
"name": "SSH认证",
|
||||
@@ -189,9 +198,10 @@ func (this *UserMustAuth) modules() []maps.Map {
|
||||
},
|
||||
},
|
||||
{
|
||||
"code": "dns",
|
||||
"name": "域名解析",
|
||||
"icon": "globe",
|
||||
"code": "dns",
|
||||
"module": configloaders.AdminModuleCodeDNS,
|
||||
"name": "域名解析",
|
||||
"icon": "globe",
|
||||
"subItems": []maps.Map{
|
||||
{
|
||||
"name": "问题修复",
|
||||
@@ -206,21 +216,33 @@ func (this *UserMustAuth) modules() []maps.Map {
|
||||
},
|
||||
},
|
||||
{
|
||||
"code": "admins",
|
||||
"name": "系统用户",
|
||||
"icon": "users",
|
||||
"code": "admins",
|
||||
"module": configloaders.AdminModuleCodeAdmin,
|
||||
"name": "系统用户",
|
||||
"icon": "users",
|
||||
},
|
||||
{
|
||||
"code": "log",
|
||||
"name": "日志审计",
|
||||
"icon": "history",
|
||||
"code": "log",
|
||||
"module": configloaders.AdminModuleCodeLog,
|
||||
"name": "日志审计",
|
||||
"icon": "history",
|
||||
},
|
||||
{
|
||||
"code": "settings",
|
||||
"name": "系统设置",
|
||||
"icon": "setting",
|
||||
"code": "settings",
|
||||
"module": configloaders.AdminModuleCodeSetting,
|
||||
"name": "系统设置",
|
||||
"icon": "setting",
|
||||
},
|
||||
}
|
||||
|
||||
result := []maps.Map{}
|
||||
for _, m := range allMaps {
|
||||
module := m.GetString("module")
|
||||
if configloaders.AllowModule(adminId, module) {
|
||||
result = append(result, m)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// 跳转到登录页
|
||||
|
||||
Reference in New Issue
Block a user