Documentation
¶
Index ¶
- Constants
- Variables
- func BatchInsertPhonebookEntries(ctx context.Context, entries []*PhonebookEntry) (int, int, error)
- func CanSeeAllOperatorGroups(capabilities map[string]bool) bool
- func CreatePhonebookEntry(ctx context.Context, entry *PhonebookEntry) error
- func DeletePhonebookEntryByID(ctx context.Context, id int64) error
- func EncodeSharedGroupsType(groups []string) string
- func GetAllowedOperatorGroupIDs(capabilities map[string]bool) []string
- func GetGroupPermissionID(groupName string) string
- func GetPhonebookPermissionLevel(username string) int
- func GetPhonebookPermissionLevelFromCapabilities(capabilities map[string]bool) int
- func GetSharedGroupsFromType(contactType string) []string
- func GetUserCapabilities(username string) (map[string]bool, error)
- func GetUserDisplayInfo(username string) (string, []string, error)
- func HasGroupTypePrefix(contactType string) bool
- func InitPersistence(dataDir string)
- func InitProfiles(profilesPath, usersPath string) error
- func IsReservedContactType(contactType string) bool
- func IsValidGroupContactType(contactType string) bool
- func IsValidSharedGroupName(groupName string) bool
- func LoadSessions() error
- func NormalizeSharedGroups(groups []string) []string
- func RemoveAllJWTTokens(username string) error
- func RemoveJWTToken(username, tokenToRemove string) error
- func RevokeLegacySession(username string, userSession *models.UserSession)
- func SaveSessions() error
- func SetBatchInsertPhonebookEntriesFuncForTest(fn func(context.Context, []*PhonebookEntry) (int, int, error)) func()
- func SyncPublicContactsToCentralized(ctx context.Context) error
- func UpdatePhonebookEntryFields(ctx context.Context, id int64, fields map[string]any) error
- func UserSessionInit() map[string]*models.UserSession
- type LegacyPhonebookContact
- type LegacyPhonebookQuery
- type LegacyPhonebookResult
- type PersistedSession
- type PhonebookEntry
- type ProfileData
- type ReloadStats
- type UserEndpoints
- type UserExtension
- type UserProfile
Constants ¶
const GroupTypePrefix = "group:"
GroupTypePrefix identifies contacts shared with one or more groups.
Variables ¶
var UserSessions map[string]*models.UserSession
Functions ¶
func BatchInsertPhonebookEntries ¶ added in v0.4.5
BatchInsertPhonebookEntries inserts multiple phonebook entries in a transaction.
func CanSeeAllOperatorGroups ¶ added in v0.5.8
CanSeeAllOperatorGroups reports whether the user can access all operator groups.
func CreatePhonebookEntry ¶ added in v0.5.8
func CreatePhonebookEntry(ctx context.Context, entry *PhonebookEntry) error
CreatePhonebookEntry inserts a single CTI phonebook contact.
func DeletePhonebookEntryByID ¶ added in v0.5.8
DeletePhonebookEntryByID removes a CTI phonebook contact.
func EncodeSharedGroupsType ¶ added in v0.5.8
EncodeSharedGroupsType serializes normalized group names into the contact type field.
func GetAllowedOperatorGroupIDs ¶ added in v0.5.8
GetAllowedOperatorGroupIDs returns the enabled grp_* presence-panel permission ids.
func GetGroupPermissionID ¶ added in v0.5.8
GetGroupPermissionID returns the normalized presence-panel permission id for a group name.
func GetPhonebookPermissionLevel ¶ added in v0.5.8
GetPhonebookPermissionLevel derives the legacy permission level for a user.
func GetPhonebookPermissionLevelFromCapabilities ¶ added in v0.5.8
GetPhonebookPermissionLevelFromCapabilities derives the legacy permission level from flattened capabilities.
func GetSharedGroupsFromType ¶ added in v0.5.8
GetSharedGroupsFromType parses the serialized group type and returns normalized group names.
func GetUserCapabilities ¶ added in v0.4.5
GetUserCapabilities returns all capabilities for a given username
func GetUserDisplayInfo ¶ added in v0.4.6
GetUserDisplayInfo returns display name and phone numbers for a given user.
func HasGroupTypePrefix ¶ added in v0.5.8
HasGroupTypePrefix reports whether the contact type uses the shared-group namespace.
func InitPersistence ¶ added in v0.4.0
func InitPersistence(dataDir string)
InitPersistence sets up the persistence file path
func InitProfiles ¶ added in v0.4.5
InitProfiles loads profiles and users from JSON files
func IsReservedContactType ¶ added in v0.5.8
IsReservedContactType reports whether the contact type is one of the built-in visibilities.
func IsValidGroupContactType ¶ added in v0.5.8
IsValidGroupContactType reports whether the serialized group type is syntactically valid.
func IsValidSharedGroupName ¶ added in v0.5.8
IsValidSharedGroupName reports whether a group name can be serialized in the contact type.
func LoadSessions ¶ added in v0.4.0
func LoadSessions() error
LoadSessions loads user sessions from disk
func NormalizeSharedGroups ¶ added in v0.5.8
NormalizeSharedGroups trims, deduplicates, and drops empty group names.
func RemoveAllJWTTokens ¶ added in v0.4.0
func RemoveJWTToken ¶ added in v0.4.0
func RevokeLegacySession ¶ added in v0.4.0
func RevokeLegacySession(username string, userSession *models.UserSession)
RevokeLegacySession deletes the session entry and revokes legacy persistent token (subtype "user") Requires that userSession.JWTTokens is empty.
func SetBatchInsertPhonebookEntriesFuncForTest ¶ added in v0.5.0
func SetBatchInsertPhonebookEntriesFuncForTest(fn func(context.Context, []*PhonebookEntry) (int, int, error)) func()
SetBatchInsertPhonebookEntriesFuncForTest allows tests to override the batch insert behavior.
func SyncPublicContactsToCentralized ¶ added in v0.5.10
SyncPublicContactsToCentralized republishes every public CTI contact into the centralized phonebook used for call-time name resolution (Asterisk lookup.php and the CTI customer-card "Identity" query both read phonebook.phonebook).
It mirrors exactly the nightly nethcti_export.php job. NethCTI-exported rows are marked with both type='nethcti' and sid_imported='nethcti': the middleware union search excludes them via type != 'nethcti', while cleanup here keys on sid_imported='nethcti' to stay in lockstep with the nightly export (which deletes by the same column). The function deletes those rows and reinserts every cti_phonebook row with type='public', so new/changed public contacts become immediately resolvable instead of waiting for the nightly export. Rows from other sync sources (sid_imported != 'nethcti') are left untouched.
phonebook.phonebook is a MyISAM table (no transactions), so the delete+reinsert is wrapped in LOCK TABLES ... WRITE to avoid exposing an empty result set to concurrent readers. LOCK TABLES is connection-scoped, hence the work runs on a single pinned connection.
func UpdatePhonebookEntryFields ¶ added in v0.5.8
UpdatePhonebookEntryFields updates the provided columns on a CTI phonebook contact.
func UserSessionInit ¶
func UserSessionInit() map[string]*models.UserSession
Types ¶
type LegacyPhonebookContact ¶ added in v0.5.8
type LegacyPhonebookContact struct {
ID int64 `json:"id"`
OwnerID string `json:"owner_id"`
Type string `json:"type"`
HomeEmail string `json:"homeemail"`
WorkEmail string `json:"workemail"`
HomePhone string `json:"homephone"`
WorkPhone string `json:"workphone"`
CellPhone string `json:"cellphone"`
Fax string `json:"fax"`
Title string `json:"title"`
Company string `json:"company"`
Notes string `json:"notes"`
Name string `json:"name"`
HomeStreet string `json:"homestreet"`
HomePOB string `json:"homepob"`
HomeCity string `json:"homecity"`
HomeProvince string `json:"homeprovince"`
HomePostalCode string `json:"homepostalcode"`
HomeCountry string `json:"homecountry"`
WorkStreet string `json:"workstreet"`
WorkPOB string `json:"workpob"`
WorkCity string `json:"workcity"`
WorkProvince string `json:"workprovince"`
WorkPostalCode string `json:"workpostalcode"`
WorkCountry string `json:"workcountry"`
URL string `json:"url"`
Extension string `json:"extension"`
SpeedDialNum string `json:"speeddial_num"`
Source string `json:"source"`
Contacts string `json:"contacts,omitempty"`
}
LegacyPhonebookContact mirrors the legacy phonebook search payload.
type LegacyPhonebookQuery ¶ added in v0.5.8
type LegacyPhonebookQuery struct {
Username string
UserGroups []string
View string
Visibility string
Term string
Offset int
Limit int
ApplyPagination bool
IncludePrivateContacts bool
}
LegacyPhonebookQuery describes legacy-compatible union search/list parameters.
type LegacyPhonebookResult ¶ added in v0.5.8
type LegacyPhonebookResult struct {
Count int `json:"count"`
Rows []LegacyPhonebookContact `json:"rows"`
LastSyncAt *string `json:"last_sync_at"`
}
LegacyPhonebookResult mirrors the legacy phonebook search/list envelope.
func ListLegacyPhonebook ¶ added in v0.5.8
func ListLegacyPhonebook(ctx context.Context, query LegacyPhonebookQuery) (*LegacyPhonebookResult, error)
ListLegacyPhonebook returns the legacy alphabetical list across CTI and centralized phonebooks.
func SearchLegacyPhonebook ¶ added in v0.5.8
func SearchLegacyPhonebook(ctx context.Context, query LegacyPhonebookQuery) (*LegacyPhonebookResult, error)
SearchLegacyPhonebook returns legacy-compatible search results across CTI and centralized phonebooks.
type PersistedSession ¶ added in v0.4.0
type PersistedSession struct {
Username string `json:"username"`
JWTTokens []string `json:"jwt_tokens"`
NethCTIToken string `json:"nethcti_token"`
}
PersistedSession represents minimal session data needed for persistence
type PhonebookEntry ¶ added in v0.4.5
type PhonebookEntry struct {
ID int64
OwnerID string
Type string
HomeEmail string
WorkEmail string
HomePhone string
WorkPhone string
CellPhone string
Fax string
Title string
Company string
Notes string
Name string
HomeStreet string
HomePOB string
HomeCity string
HomeProvince string
HomePostalCode string
HomeCountry string
WorkStreet string
WorkPOB string
WorkCity string
WorkProvince string
WorkPostalCode string
WorkCountry string
URL string
Extension string
SpeedDialNum string
}
PhonebookEntry represents a phonebook contact from cti_phonebook table.
func GetCentralizedPhonebookEntryByID ¶ added in v0.5.8
func GetCentralizedPhonebookEntryByID(ctx context.Context, id int64) (*PhonebookEntry, error)
GetCentralizedPhonebookEntryByID returns a single contact from the centralized phonebook table (the company-wide phonebook published for physical phones) by id. The nethcti-exported rows are excluded: those are CTI contacts and must be fetched from cti_phonebook instead, to avoid returning the duplicated copy.
func GetPhonebookEntryByID ¶ added in v0.5.8
func GetPhonebookEntryByID(ctx context.Context, id int64) (*PhonebookEntry, error)
GetPhonebookEntryByID returns a single CTI phonebook contact by id.
type ProfileData ¶ added in v0.4.5
ProfileData represents a profile with capability map
func GetUserProfile ¶ added in v0.4.5
func GetUserProfile(username string) (*ProfileData, error)
GetUserProfile returns the profile data for a given username
type ReloadStats ¶ added in v0.4.6
ReloadStats reports in-memory counters after a reload attempt.
func ReloadProfiles ¶ added in v0.4.5
func ReloadProfiles() (*ReloadStats, error)
ReloadProfiles reloads profiles and users and returns resulting counters.
type UserEndpoints ¶ added in v0.4.6
type UserEndpoints struct {
MainExtension map[string]struct{}
Extension map[string]*UserExtension
Voicemail map[string]struct{}
Email map[string]struct{}
Cellphone map[string]struct{}
}
UserEndpoints contains endpoint data loaded from users.json.
type UserExtension ¶ added in v0.4.6
UserExtension stores details for a single extension endpoint.
type UserProfile ¶ added in v0.4.5
type UserProfile struct {
Username string
Name string
ProfileID string
Endpoints UserEndpoints
PhoneNumbers []string
}
UserProfile links a username to a profile