From 6eee55860ff15a74c9b9bc8957107bf3e213957d Mon Sep 17 00:00:00 2001 From: Rogee Date: Fri, 11 Sep 2026 11:38:15 +0800 Subject: [PATCH] fix(agent): allow super admins to manage agents --- backend/internal/router/router.go | 12 ++++++------ .../dashboard/i18n/locale/en/agentMgmt.json | 1 + .../dashboard/i18n/locale/zh_CN/agentMgmt.json | 1 + .../routes/dashboard/settings/agents/AddAgent.vue | 2 ++ 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/backend/internal/router/router.go b/backend/internal/router/router.go index 8524e547..75e8601e 100644 --- a/backend/internal/router/router.go +++ b/backend/internal/router/router.go @@ -731,17 +731,17 @@ func registerV1Routes(g *gin.RouterGroup, h *Handlers) { // Chatwoot: GET /api/v1/accounts/:account_id/agents (index) accounts.GET("/:account_id/agents", h.Agent.List) // Chatwoot: POST /api/v1/accounts/:account_id/agents (create) - accounts.POST("/:account_id/agents", middleware.RoleCheck("administrator"), h.Agent.Create) + accounts.POST("/:account_id/agents", middleware.SuperAdminOrAdministrator(), h.Agent.Create) // Chatwoot: PATCH/PUT /api/v1/accounts/:account_id/agents/:id (update) - accounts.PATCH("/:account_id/agents/:agent_id", middleware.RoleCheck("administrator"), h.Agent.Update) - accounts.PUT("/:account_id/agents/:agent_id", middleware.RoleCheck("administrator"), h.Agent.Update) + accounts.PATCH("/:account_id/agents/:agent_id", middleware.SuperAdminOrAdministrator(), h.Agent.Update) + accounts.PUT("/:account_id/agents/:agent_id", middleware.SuperAdminOrAdministrator(), h.Agent.Update) // Chatwoot: DELETE /api/v1/accounts/:account_id/agents/:id (destroy) - accounts.DELETE("/:account_id/agents/:agent_id", middleware.RoleCheck("administrator"), h.Agent.Delete) - accounts.POST("/:account_id/agents/:agent_id/reset_password", middleware.RoleCheck("administrator"), h.Agent.ResetPassword) + accounts.DELETE("/:account_id/agents/:agent_id", middleware.SuperAdminOrAdministrator(), h.Agent.Delete) + accounts.POST("/:account_id/agents/:agent_id/reset_password", middleware.SuperAdminOrAdministrator(), h.Agent.ResetPassword) // Chatwoot: GET /api/v1/accounts/:account_id/agents/:id (show) — was missing accounts.GET("/:account_id/agents/:agent_id", h.Agent.Get) // Chatwoot: POST /api/v1/accounts/:account_id/agents/bulk_create - accounts.POST("/:account_id/agents/bulk_create", middleware.RoleCheck("administrator"), h.Agent.BulkCreate) + accounts.POST("/:account_id/agents/bulk_create", middleware.SuperAdminOrAdministrator(), h.Agent.BulkCreate) // Bulk assign/unassign conversations to agents (ref: Chatwoot agents_controller.rb #bulk_assign, #bulk_unassign) accounts.POST("/:account_id/agents/bulk_assign", h.AgentBulk.BulkAssign) accounts.POST("/:account_id/agents/bulk_unassign", h.AgentBulk.BulkUnassign) diff --git a/frontend/app/javascript/dashboard/i18n/locale/en/agentMgmt.json b/frontend/app/javascript/dashboard/i18n/locale/en/agentMgmt.json index 0d54a762..d8f1a613 100644 --- a/frontend/app/javascript/dashboard/i18n/locale/en/agentMgmt.json +++ b/frontend/app/javascript/dashboard/i18n/locale/en/agentMgmt.json @@ -46,6 +46,7 @@ "API": { "SUCCESS_MESSAGE": "Agent added successfully", "EXIST_MESSAGE": "Agent email already in use, Please try another email address", + "PERMISSION_MESSAGE": "Administrator permission is required to add an agent.", "LIMIT_MESSAGE": "Agent limit reached. Please upgrade your plan or add more seats.", "ERROR_MESSAGE": "Could not connect to Woot Server, Please try again later" } diff --git a/frontend/app/javascript/dashboard/i18n/locale/zh_CN/agentMgmt.json b/frontend/app/javascript/dashboard/i18n/locale/zh_CN/agentMgmt.json index 1b41eecc..93231bcf 100644 --- a/frontend/app/javascript/dashboard/i18n/locale/zh_CN/agentMgmt.json +++ b/frontend/app/javascript/dashboard/i18n/locale/zh_CN/agentMgmt.json @@ -46,6 +46,7 @@ "API": { "SUCCESS_MESSAGE": "添加客服成功", "EXIST_MESSAGE": "该邮箱已被注册,请输入新的电子邮箱", + "PERMISSION_MESSAGE": "需要管理员权限才能添加客服", "LIMIT_MESSAGE": "客服数量已达到上限,请升级套餐或增加客服名额", "ERROR_MESSAGE": "无法连接服务器,请稍后再试" } diff --git a/frontend/app/javascript/dashboard/routes/dashboard/settings/agents/AddAgent.vue b/frontend/app/javascript/dashboard/routes/dashboard/settings/agents/AddAgent.vue index 706eb74b..96ada35d 100644 --- a/frontend/app/javascript/dashboard/routes/dashboard/settings/agents/AddAgent.vue +++ b/frontend/app/javascript/dashboard/routes/dashboard/settings/agents/AddAgent.vue @@ -96,6 +96,8 @@ const addAgent = async () => { if (status === 422 && !attributes.includes('base')) { useAlert(t('AGENT_MGMT.ADD.API.EXIST_MESSAGE')); + } else if (status === 403 || data?.error?.code === 'FORBIDDEN') { + useAlert(t('AGENT_MGMT.ADD.API.PERMISSION_MESSAGE')); } else if (status === 402 || data?.error?.code === 'PAYMENT_REQUIRED') { useAlert(t('AGENT_MGMT.ADD.API.LIMIT_MESSAGE')); } else {