2024-01-06 17:56:32 +00:00
|
|
|
package models
|
|
|
|
|
2024-01-07 07:52:23 +00:00
|
|
|
import (
|
2024-05-22 15:45:43 +00:00
|
|
|
"fmt"
|
2024-08-24 07:17:26 +00:00
|
|
|
"gorm.io/datatypes"
|
2024-01-07 07:52:23 +00:00
|
|
|
"time"
|
2024-03-20 12:56:07 +00:00
|
|
|
|
|
|
|
"github.com/samber/lo"
|
2024-05-22 15:45:43 +00:00
|
|
|
"github.com/spf13/viper"
|
2024-01-07 07:52:23 +00:00
|
|
|
)
|
2024-01-06 17:56:32 +00:00
|
|
|
|
|
|
|
type Account struct {
|
|
|
|
BaseModel
|
|
|
|
|
2024-10-12 17:45:08 +00:00
|
|
|
Name string `json:"name" gorm:"uniqueIndex"`
|
|
|
|
Nick string `json:"nick"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Avatar *string `json:"avatar"`
|
|
|
|
Banner *string `json:"banner"`
|
|
|
|
ConfirmedAt *time.Time `json:"confirmed_at"`
|
|
|
|
SuspendedAt *time.Time `json:"suspended_at"`
|
|
|
|
PermNodes datatypes.JSONMap `json:"perm_nodes"`
|
|
|
|
AuthConfig datatypes.JSONType[AuthConfig] `json:"auth_config"`
|
2024-04-05 17:07:36 +00:00
|
|
|
|
2024-08-24 07:17:26 +00:00
|
|
|
AutomatedBy *Account `json:"automated_by" gorm:"foreignKey:AutomatedID"`
|
|
|
|
AutomatedID *uint `json:"automated_id"`
|
|
|
|
|
|
|
|
AffiliatedTo *Realm `json:"affiliated_to" gorm:"foreignKey:AffiliatedID"`
|
|
|
|
AffiliatedID *uint `json:"affiliated_id"`
|
|
|
|
|
2024-07-15 16:02:28 +00:00
|
|
|
Profile AccountProfile `json:"profile,omitempty"`
|
|
|
|
Contacts []AccountContact `json:"contacts,omitempty"`
|
|
|
|
Badges []Badge `json:"badges,omitempty"`
|
2024-06-26 09:59:15 +00:00
|
|
|
|
2024-07-14 16:01:17 +00:00
|
|
|
Tickets []AuthTicket `json:"tickets,omitempty"`
|
|
|
|
Factors []AuthFactor `json:"factors,omitempty"`
|
2024-04-05 17:07:36 +00:00
|
|
|
|
2024-07-15 16:02:28 +00:00
|
|
|
Relations []AccountRelationship `json:"relations,omitempty" gorm:"foreignKey:AccountID"`
|
2024-01-06 17:56:32 +00:00
|
|
|
}
|
|
|
|
|
2024-05-22 15:45:43 +00:00
|
|
|
func (v Account) GetAvatar() *string {
|
|
|
|
if v.Avatar != nil {
|
2024-08-18 14:08:58 +00:00
|
|
|
return lo.ToPtr(fmt.Sprintf("%s/%s", viper.GetString("content_endpoint"), *v.Avatar))
|
2024-05-22 15:45:43 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v Account) GetBanner() *string {
|
|
|
|
if v.Banner != nil {
|
2024-08-18 14:08:58 +00:00
|
|
|
return lo.ToPtr(fmt.Sprintf("%s/%s", viper.GetString("content_endpoint"), *v.Banner))
|
2024-05-22 15:45:43 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-28 16:32:39 +00:00
|
|
|
func (v Account) GetPrimaryEmail() AccountContact {
|
|
|
|
val, _ := lo.Find(v.Contacts, func(item AccountContact) bool {
|
|
|
|
return item.Type == EmailAccountContact && item.IsPrimary
|
|
|
|
})
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
|
2024-01-06 17:56:32 +00:00
|
|
|
type AccountContactType = int8
|
|
|
|
|
|
|
|
const (
|
|
|
|
EmailAccountContact = AccountContactType(iota)
|
|
|
|
)
|
|
|
|
|
|
|
|
type AccountContact struct {
|
|
|
|
BaseModel
|
|
|
|
|
|
|
|
Type int8 `json:"type"`
|
|
|
|
Content string `json:"content" gorm:"uniqueIndex"`
|
|
|
|
IsPublic bool `json:"is_public"`
|
|
|
|
IsPrimary bool `json:"is_primary"`
|
|
|
|
VerifiedAt *time.Time `json:"verified_at"`
|
|
|
|
AccountID uint `json:"account_id"`
|
|
|
|
}
|