From c48d8b93ddfb94642d6d27ad3e9a39eaab83d4d8 Mon Sep 17 00:00:00 2001 From: qinyening <710leo@gmail.com> Date: Wed, 3 Feb 2021 11:01:29 +0800 Subject: [PATCH] add some permssion api (#572) --- src/modules/rdb/http/router.go | 2 ++ src/modules/rdb/http/router_node_role.go | 9 ++++++++ src/modules/rdb/http/router_resource.go | 27 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/modules/rdb/http/router.go b/src/modules/rdb/http/router.go index e436a295..6cf4d245 100644 --- a/src/modules/rdb/http/router.go +++ b/src/modules/rdb/http/router.go @@ -136,6 +136,7 @@ func Config(r *gin.Engine) { userLogin.GET("/node/:id/roles", rolesUnderNodeGets) userLogin.POST("/node/:id/roles", rolesUnderNodePost) userLogin.DELETE("/node/:id/roles", rolesUnderNodeDel) + userLogin.DELETE("/node/:id/roles/try", rolesUnderNodeDelTry) userLogin.GET("/node/:id/resources", resourceUnderNodeGet) userLogin.GET("/node/:id/resources/cate-count", renderNodeResourcesCountByCate) userLogin.POST("/node/:id/resources/bind", resourceBindNode) @@ -149,6 +150,7 @@ func Config(r *gin.Engine) { userLogin.GET("/resources/search", resourceSearchGet) userLogin.PUT("/resources/note", resourceNotePut) + userLogin.PUT("/resources/note/try", resourceNotePutTry) userLogin.GET("/resources/bindings", resourceBindingsGet) userLogin.GET("/resources/orphan", resourceOrphanGet) diff --git a/src/modules/rdb/http/router_node_role.go b/src/modules/rdb/http/router_node_role.go index 29505625..d7dd9eed 100644 --- a/src/modules/rdb/http/router_node_role.go +++ b/src/modules/rdb/http/router_node_role.go @@ -114,3 +114,12 @@ func rolesUnderNodeDel(c *gin.Context) { renderMessage(c, err) } + +func rolesUnderNodeDelTry(c *gin.Context) { + node := Node(urlParamInt64(c, "id")) + + me := loginUser(c) + me.CheckPermByNode(node, "rdb_perm_grant") + + renderMessage(c, nil) +} diff --git a/src/modules/rdb/http/router_resource.go b/src/modules/rdb/http/router_resource.go index b0fa5afb..899f3447 100644 --- a/src/modules/rdb/http/router_resource.go +++ b/src/modules/rdb/http/router_resource.go @@ -131,6 +131,33 @@ func resourceHttpRegister(count int, items []v1ContainersRegisterItem) { } } +// 游离资源页面修改备注权限测试,超级管理员,或者是租户管理员有权限 +func resourceNotePutTry(c *gin.Context) { + path := queryStr(c, "tenant", "") + me := loginUser(c) + + if me.IsRooter() { + renderMessage(c, nil) + return + } + + if path == "" { + bomb("no privilege") + } + + tenantNode, err := models.NodeGet("path=?", path) + if tenantNode == nil || err != nil { + bomb("no privilege") + } + + exists, err := models.NodesAdminExists([]int64{tenantNode.Id}, me.Id) + if err != nil || !exists { + bomb("no privilege") + } + + renderMessage(c, nil) +} + // 游离资源页面修改备注,超级管理员,或者是租户管理员 func resourceNotePut(c *gin.Context) { var f resourceNotePutForm