Restructure the monorepo into clear top-level directories: - backend/: Go module root (cmd, internal, pkg, configs, migrations, docs/swagger, scripts, tests, go.mod, Makefile, .air.toml) - deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd - docs/: project documentation + reports/ (moved from repo root) - AGENTS.md: new AI coding-agent guide at repo root Update all references to the new layout: - Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root) - docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile, env_file ../../.env, volume mounts ../../backend:/app - deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile - CI: working-directory: backend for go commands, file deploy/docker/Dockerfile, coverage path backend/coverage.out, health_check backend/scripts/ - backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../ - README: architecture tree, quickstart, config paths updated Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh, gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to preserve history. Build, vet, SQLite tests, and docker compose config verified.
55 lines
2.6 KiB
Go
55 lines
2.6 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// PlatformApp represents a platform-level application (partner API / agent bot / integration)
|
|
// that authenticates via AccessToken and operates within specific accounts.
|
|
// Reference: Chatwoot app/models/platform_app.rb + app/models/agent_bot.rb + P2B M12 spec
|
|
//
|
|
// PlatformApps are used for:
|
|
// - API-based integrations (webhooks, CRM sync, etc.)
|
|
// - Agent bots that automate conversation handling
|
|
// - Third-party applications that need API access to GoChat
|
|
//
|
|
// Authentication: PlatformApps use AccessToken authentication (AccessTokenable concern).
|
|
// The token is auto-created on PlatformApp creation and rotated via regenerate endpoints.
|
|
// Corresponds to Chatwoot's AccessTokenable concern for agent bots / platform apps.
|
|
|
|
// PlatformApp represents a platform application with AccessToken authentication.
|
|
type PlatformApp struct {
|
|
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
|
Name string `gorm:"size:255;not null" json:"name"`
|
|
Description string `gorm:"type:text" json:"description,omitempty"`
|
|
Icon string `gorm:"size:255" json:"icon,omitempty"`
|
|
URL string `gorm:"size:512" json:"url,omitempty"`
|
|
Config json.RawMessage `gorm:"type:jsonb;default:'{}';serializer:json" json:"config,omitempty"`
|
|
Active *bool `gorm:"default:true;not null" json:"active"`
|
|
AccountID *uint `gorm:"index" json:"account_id,omitempty"` // nil = platform-level (no account restriction)
|
|
Type string `gorm:"size:50;default:'api'" json:"type"` // api, agent_bot, integration
|
|
Status string `gorm:"size:50;default:'active'" json:"status"` // active, disabled
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
|
|
|
|
// Relations
|
|
Account Account `gorm:"foreignKey:AccountID" json:"account,omitempty"`
|
|
Permissibles []Permissible `gorm:"foreignKey:PlatformAppID" json:"permissibles,omitempty"`
|
|
AccessToken *AccessToken `gorm:"foreignKey:OwnerID;conditions:owner_type='PlatformApp'" json:"access_token,omitempty"`
|
|
}
|
|
|
|
func (PlatformApp) TableName() string { return "platform_apps" }
|
|
|
|
// IsPlatformLevel returns true if this app is not restricted to any account (AccountID is nil).
|
|
func (a *PlatformApp) IsPlatformLevel() bool {
|
|
return a.AccountID == nil
|
|
}
|
|
|
|
// IsActive returns true if the app is both Active and Status=active.
|
|
func (a *PlatformApp) IsActive() bool {
|
|
return a.Active != nil && *a.Active && a.Status == "active"
|
|
} |