forked from baron/baron-sso
This commit includes: - Added SharedLink data model and Keto-bypassed public API for orgchart view - Configured 'orgfront' as a new OAuth2 client in hydra - Applied MH Dashboard premium beige theme to OrgChart - Implemented user lookup fallback to company code
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package domain
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type SharedLink struct {
|
|
ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid()" json:"id"`
|
|
TenantID string `gorm:"type:uuid;not null;index" json:"tenantId"`
|
|
Token string `gorm:"uniqueIndex;not null" json:"token"`
|
|
Name string `gorm:"not null" json:"name"` // 링크 식별을 위한 이름 (예: "24년 상반기 채용공고용")
|
|
Description string `json:"description"`
|
|
AccessLevel string `gorm:"default:'READ_ONLY'" json:"accessLevel"`
|
|
IsActive bool `gorm:"default:true" json:"isActive"`
|
|
ExpiresAt *time.Time `json:"expiresAt"`
|
|
Password string `json:"-"` // 필요 시 비밀번호 (선택 사항)
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
// Relation
|
|
Tenant Tenant `gorm:"foreignKey:TenantID" json:"-"`
|
|
}
|
|
|
|
func (s *SharedLink) BeforeCreate(tx *gorm.DB) (err error) {
|
|
if s.ID == "" {
|
|
s.ID = uuid.NewString()
|
|
}
|
|
if s.Token == "" {
|
|
// 32바이트(64자)의 강력한 난수 토큰 생성
|
|
b := make([]byte, 32)
|
|
if _, err := rand.Read(b); err != nil {
|
|
return err
|
|
}
|
|
s.Token = hex.EncodeToString(b)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *SharedLink) IsValid() bool {
|
|
if !s.IsActive {
|
|
return false
|
|
}
|
|
if s.ExpiresAt != nil && s.ExpiresAt.Before(time.Now()) {
|
|
return false
|
|
}
|
|
return true
|
|
}
|