H-47: unblock connector sandbox setup (#11)
Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
@@ -21,6 +21,14 @@ type PlatformAppHandler struct {
|
||||
svc *service.PlatformAppService
|
||||
}
|
||||
|
||||
func platformAppID(c *gin.Context) (uint, error) {
|
||||
name := "id"
|
||||
if c.Param(name) == "" {
|
||||
name = "platform_app_id"
|
||||
}
|
||||
return parseUintParam(c, name)
|
||||
}
|
||||
|
||||
// NewPlatformAppHandler creates a new PlatformApp handler with service injection.
|
||||
func NewPlatformAppHandler(svc *service.PlatformAppService) *PlatformAppHandler {
|
||||
return &PlatformAppHandler{svc: svc}
|
||||
@@ -67,7 +75,7 @@ func (h *PlatformAppHandler) List(c *gin.Context) {
|
||||
// GET /api/v1/accounts/:account_id/platform_apps/:id
|
||||
// GET /platform/api/v1/apps/:id
|
||||
func (h *PlatformAppHandler) Get(c *gin.Context) {
|
||||
id, err := parseUintParam(c, "id")
|
||||
id, err := platformAppID(c)
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid platform app ID")
|
||||
return
|
||||
@@ -109,8 +117,8 @@ func (h *PlatformAppHandler) Create(c *gin.Context) {
|
||||
}
|
||||
// Return app + plaintext token (this is the only time the plaintext token is shown)
|
||||
response.Created(c, gin.H{
|
||||
"platform_app": app,
|
||||
"access_token": plainToken, // plaintext — shown only once
|
||||
"platform_app": app,
|
||||
"access_token": plainToken, // plaintext — shown only once
|
||||
})
|
||||
}
|
||||
|
||||
@@ -118,7 +126,7 @@ func (h *PlatformAppHandler) Create(c *gin.Context) {
|
||||
// PUT /api/v1/accounts/:account_id/platform_apps/:id
|
||||
// PUT /platform/api/v1/apps/:id
|
||||
func (h *PlatformAppHandler) Update(c *gin.Context) {
|
||||
id, err := parseUintParam(c, "id")
|
||||
id, err := platformAppID(c)
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid platform app ID")
|
||||
return
|
||||
@@ -141,7 +149,7 @@ func (h *PlatformAppHandler) Update(c *gin.Context) {
|
||||
// DELETE /api/v1/accounts/:account_id/platform_apps/:id
|
||||
// DELETE /platform/api/v1/apps/:id
|
||||
func (h *PlatformAppHandler) Delete(c *gin.Context) {
|
||||
id, err := parseUintParam(c, "id")
|
||||
id, err := platformAppID(c)
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid platform app ID")
|
||||
return
|
||||
@@ -161,7 +169,7 @@ func (h *PlatformAppHandler) Delete(c *gin.Context) {
|
||||
// Reference: Chatwoot PlatformAppsController#regenerate_api_key
|
||||
// Returns the plaintext token (shown only once, never stored).
|
||||
func (h *PlatformAppHandler) RegenerateAccessToken(c *gin.Context) {
|
||||
id, err := parseUintParam(c, "id")
|
||||
id, err := platformAppID(c)
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid platform app ID")
|
||||
return
|
||||
@@ -181,7 +189,7 @@ func (h *PlatformAppHandler) RegenerateAccessToken(c *gin.Context) {
|
||||
// GET /platform/api/v1/apps/:id/access_tokens
|
||||
// GET /api/v1/accounts/:account_id/platform_apps/:id/access_tokens
|
||||
func (h *PlatformAppHandler) ListAccessTokens(c *gin.Context) {
|
||||
id, err := parseUintParam(c, "id")
|
||||
id, err := platformAppID(c)
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid platform app ID")
|
||||
return
|
||||
@@ -203,7 +211,7 @@ func (h *PlatformAppHandler) ListAccessTokens(c *gin.Context) {
|
||||
// Body: { "permissible_type": "Account|User|AgentBot", "permissible_id": 123 }
|
||||
// Reference: Chatwoot PlatformAppsController#add_permissible
|
||||
func (h *PlatformAppHandler) AddPermissible(c *gin.Context) {
|
||||
id, err := parseUintParam(c, "id")
|
||||
id, err := platformAppID(c)
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid platform app ID")
|
||||
return
|
||||
@@ -229,7 +237,7 @@ func (h *PlatformAppHandler) AddPermissible(c *gin.Context) {
|
||||
// Query params: permissible_type=Account|User|AgentBot
|
||||
// Reference: Chatwoot PlatformAppsController#remove_permissible
|
||||
func (h *PlatformAppHandler) RemovePermissible(c *gin.Context) {
|
||||
id, err := parseUintParam(c, "id")
|
||||
id, err := platformAppID(c)
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid platform app ID")
|
||||
return
|
||||
@@ -259,7 +267,7 @@ func (h *PlatformAppHandler) RemovePermissible(c *gin.Context) {
|
||||
// GET /platform/api/v1/apps/:id/permissibles
|
||||
// GET /api/v1/accounts/:account_id/platform_apps/:id/permissibles
|
||||
func (h *PlatformAppHandler) ListPermissibles(c *gin.Context) {
|
||||
id, err := parseUintParam(c, "id")
|
||||
id, err := platformAppID(c)
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid platform app ID")
|
||||
return
|
||||
@@ -321,4 +329,4 @@ type addPermissibleRequest struct {
|
||||
// --- Helper: validate permissible_type ---
|
||||
func isValidPermissibleTypeStr(t string) bool {
|
||||
return t == model.PermissibleTypeAccount || t == model.PermissibleTypeUser || t == model.PermissibleTypeAgentBot
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPlatformAppIDSupportsBothRoutes(t *testing.T) {
|
||||
for _, params := range []gin.Param{
|
||||
{Key: "id", Value: "7"},
|
||||
{Key: "platform_app_id", Value: "7"},
|
||||
} {
|
||||
ctx, _ := gin.CreateTestContext(nil)
|
||||
ctx.Params = []gin.Param{params}
|
||||
id, err := platformAppID(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint(7), id)
|
||||
}
|
||||
}
|
||||
@@ -48,8 +48,8 @@ WORKDIR /app
|
||||
# Copy binary and configs from builder
|
||||
COPY --from=builder /gochat /app/gochat
|
||||
COPY --from=builder /gochat-worker /app/gochat-worker
|
||||
COPY configs/ /app/configs/
|
||||
COPY migrations/ /app/migrations/
|
||||
COPY backend/configs/ /app/configs/
|
||||
COPY backend/migrations/ /app/migrations/
|
||||
|
||||
# Set ownership to non-root user
|
||||
RUN mkdir -p /app/storage/uploads && chown -R gochat:gochat /app
|
||||
|
||||
Reference in New Issue
Block a user