Files
gochat/backend/internal/model/account_ldap_settings.go
T
rogee aeddedf2a3 Reorganize repo: backend/, deploy/, docs/ layout + AGENTS.md
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.
2026-07-07 14:44:12 +08:00

47 lines
3.2 KiB
Go

package model
// Reference: M13 §4.4 — LDAP/Active Directory per-account configuration
// Enables multi-tenant LDAP identity isolation: each account (tenant) can configure
// its own LDAP server, allowing enterprise customers to connect to their existing
// Active Directory or LDAP infrastructure while maintaining complete isolation
// between tenants.
// This is a GoChat enterprise feature that Chatwoot does not offer.
import (
"encoding/json"
"time"
"gorm.io/gorm"
)
// AccountLDAPSettings stores per-account LDAP configuration for multi-tenant identity isolation.
// Each account can have exactly one active LDAP configuration.
type AccountLDAPSettings struct {
ID uint `gorm:"primaryKey" json:"id"`
AccountID uint `gorm:"not null;uniqueIndex" json:"account_id"` // one active config per account
Host string `gorm:"size:200;not null" json:"host"` // LDAP server hostname
Port int `gorm:"not null;default:389" json:"port"` // LDAP port (389=plain, 636=LDAPS)
UseTLS bool `gorm:"default:false" json:"use_tls"` // use StartTLS on connection
BaseDN string `gorm:"size:200;not null" json:"base_dn"` // search base DN (e.g. dc=example,dc=com)
BindDN string `gorm:"size:200" json:"bind_dn,omitempty"` // service account bind DN
BindPassword string `gorm:"size:200" json:"-"` // bind password (not exposed via API)
UserFilter string `gorm:"size:200;default:'(objectClass=person)'" json:"user_filter"` // LDAP search filter for users
EmailAttribute string `gorm:"size:50;default:'mail'" json:"email_attribute"` // attribute for email
NameAttribute string `gorm:"size:50;default:'cn'" json:"name_attribute"` // attribute for display name
FirstNameAttribute string `gorm:"size:50;default:'givenName'" json:"first_name_attribute"` // attribute for first name
LastNameAttribute string `gorm:"size:50;default:'sn'" json:"last_name_attribute"` // attribute for last name
GroupAttribute string `gorm:"size:50;default:'memberOf'" json:"group_attribute"` // attribute for group membership
GroupFilter string `gorm:"size:200" json:"group_filter,omitempty"` // filter for group search (e.g. (objectClass=group))
RoleMappings json.RawMessage `gorm:"type:jsonb" json:"role_mappings"` // LDAP group -> GoChat role mapping
AutoProvision bool `gorm:"default:true" json:"auto_provision"` // auto-create GoChat user on first LDAP login
SyncInterval int `gorm:"default:3600" json:"sync_interval"` // group sync interval in seconds
Active bool `gorm:"default:true" json:"active"` // whether this config is active
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"`
Account Account `gorm:"foreignKey:AccountID" json:"account,omitempty"`
}
func (AccountLDAPSettings) TableName() string { return "account_ldap_settings" }