Go CLI: Fix alter role (#16226)

### What problem does this PR solve?

As title.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-06-22 17:33:47 +08:00
committed by GitHub
parent 329e09f16a
commit 05e758e4fe
10 changed files with 453 additions and 396 deletions

View File

@@ -125,15 +125,15 @@ func (h *Handler) DropRole(c *gin.Context) {
success(c, role, "")
}
// GetRolePermission handle get role permission
func (h *Handler) GetRolePermission(c *gin.Context) {
// ShowRolePermission handle get role permission
func (h *Handler) ShowRolePermission(c *gin.Context) {
roleName := c.Param("role_name")
if roleName == "" {
errorResponse(c, "Role name is required", 400)
return
}
permissions, err := h.service.GetRolePermission(roleName)
permissions, err := h.service.ShowRolePermission(roleName)
if err != nil {
errorResponse(c, err.Error(), 500)
return
@@ -1269,8 +1269,8 @@ func (h *Handler) PurgeUsersData(c *gin.Context) {
success(c, result, "")
}
// CreateUserAPIKey handle create tenant API key
func (h *Handler) CreateUserAPIKey(c *gin.Context) {
// GenerateUserAPIKey handle create tenant API key
func (h *Handler) GenerateUserAPIKey(c *gin.Context) {
encodedUsername := c.Param("username")
username, err := common.DecodeEmail(encodedUsername)
if err != nil {
@@ -1278,7 +1278,7 @@ func (h *Handler) CreateUserAPIKey(c *gin.Context) {
return
}
apiKey, err := h.service.CreateUserAPIKey(username)
apiKey, err := h.service.GenerateUserAPIKey(username)
if err != nil {
errorResponse(c, err.Error(), 500)
return

View File

@@ -85,14 +85,12 @@ func (s *Service) DropRole(roleName string) (map[string]interface{}, error) {
return result, nil
}
// GetRolePermission get role permissions
func (s *Service) GetRolePermission(roleName string) ([]map[string]interface{}, error) {
result := []map[string]interface{}{
{
"command": "get_role_permission",
"role_name": roleName,
"error": "'get role permissions' is implemented in enterprise edition",
},
// ShowRolePermission get role permissions
func (s *Service) ShowRolePermission(roleName string) (map[string]interface{}, error) {
result := map[string]interface{}{
"command": "show_role_permission",
"role_name": roleName,
"error": "'show role permissions' is implemented in enterprise edition",
}
return result, nil
@@ -834,8 +832,8 @@ func (s *Service) PurgeUsersData(preview bool, days int, userPlan *string, userA
return result, nil
}
// CreateUserAPIKey create tenant API key for tenant
func (s *Service) CreateUserAPIKey(username string) (map[string]interface{}, error) {
// GenerateUserAPIKey create tenant API key for tenant
func (s *Service) GenerateUserAPIKey(username string) (map[string]interface{}, error) {
user, err := s.userDAO.GetByEmail(username)
if err != nil {

View File

@@ -622,6 +622,23 @@ func (h *Handler) ShutdownService(c *gin.Context) {
success(c, result, "")
}
// StartService handle start service
func (h *Handler) StartService(c *gin.Context) {
serviceID := c.Param("service_id")
if serviceID == "" {
errorResponse(c, "Service ID is required", 400)
return
}
result, err := h.service.StartService(serviceID)
if err != nil {
errorResponse(c, err.Error(), 500)
return
}
success(c, result, "")
}
// RestartService handle restart service
func (h *Handler) RestartService(c *gin.Context) {
serviceID := c.Param("service_id")

View File

@@ -75,6 +75,7 @@ func (r *Router) Setup(engine *gin.Engine) {
protected.GET("/services/:service_id", r.handler.GetService)
protected.DELETE("/services/:service_id", r.handler.ShutdownService)
protected.PUT("/services/:service_id", r.handler.RestartService)
protected.POST("/services/:service_id", r.handler.StartService)
// Variables/Settings
protected.GET("/variables", r.handler.ListVariables)
@@ -156,7 +157,7 @@ func (r *Router) Setup(engine *gin.Engine) {
protected.DELETE("/users/data", r.handler.PurgeUsersData)
// API Keys
protected.POST("/users/:username/keys", r.handler.CreateUserAPIKey)
protected.POST("/users/:username/keys", r.handler.GenerateUserAPIKey)
protected.DELETE("/users/:username/keys/:key", r.handler.DeleteUserAPIKey)
protected.GET("/users/:username/keys", r.handler.ListUserAPIKeys)
@@ -171,7 +172,7 @@ func (r *Router) Setup(engine *gin.Engine) {
protected.GET("/roles/:role_name", r.handler.ShowRole)
protected.PUT("/roles/:role_name", r.handler.UpdateRole)
protected.DELETE("/roles/:role_name", r.handler.DropRole)
protected.GET("/roles/:role_name/permission", r.handler.GetRolePermission)
protected.GET("/roles/:role_name/permission", r.handler.ShowRolePermission)
protected.POST("/roles/:role_name/permission", r.handler.GrantRolePermission)
protected.DELETE("/roles/:role_name/permission", r.handler.RevokeRolePermission)
protected.GET("/roles/resource", r.handler.ListResources)

View File

@@ -534,12 +534,13 @@ func (s *Service) GetUserDetails(username string) (map[string]interface{}, error
}
return map[string]interface{}{
"id": user.ID,
"email": user.Email,
"nickname": user.Nickname,
"is_active": user.IsActive,
"create_time": user.CreateTime,
"update_time": user.UpdateTime,
"id": user.ID,
"email": user.Email,
"nickname": user.Nickname,
"is_active": user.IsActive,
"is_superuser": user.IsSuperuser,
"create_time": user.CreateTime,
"update_time": user.UpdateTime,
}, nil
}
@@ -1412,17 +1413,27 @@ func (s *Service) checkTaskExecutorAlive(name string) (map[string]interface{}, e
func (s *Service) ShutdownService(serviceID string) (map[string]interface{}, error) {
// TODO: Implement with proper service manager
return map[string]interface{}{
"command": "shutdown service",
"service_id": serviceID,
"status": "shutdown",
"error": "shutdown service not implemented",
}, nil
}
// StartService start service
func (s *Service) StartService(serviceID string) (map[string]interface{}, error) {
return map[string]interface{}{
"command": "start service",
"service_id": serviceID,
"error": "command 'start service' isn't implemented",
}, nil
}
// RestartService restart service
func (s *Service) RestartService(serviceID string) (map[string]interface{}, error) {
// TODO: Implement with proper service manager
return map[string]interface{}{
"command": "restart service",
"service_id": serviceID,
"status": "restarted",
"error": "command 'restart service' isn't implemented",
}, nil
}