From 333c1b5dd057d055f3f39fac1273e83a307a78fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferdinand=20M=C3=BCtsch?= Date: Sat, 3 Dec 2022 00:14:37 +0100 Subject: [PATCH] feat(subscriptions): introduce config options and user attribute to support subscriptions --- config/config.go | 5 +++++ models/user.go | 43 ++++++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/config/config.go b/config/config.go index 21ab8e5..185a469 100644 --- a/config/config.go +++ b/config/config.go @@ -122,6 +122,10 @@ type serverConfig struct { TlsKeyPath string `yaml:"tls_key_path" default:"" env:"WAKAPI_TLS_KEY_PATH"` } +type subscriptionsConfig struct { + Enabled bool `yaml:"enabled" default:"false" env:"WAKAPI_SUBSCRIPTIONS_ENABLED"` +} + type sentryConfig struct { Dsn string `env:"WAKAPI_SENTRY_DSN"` EnableTracing bool `yaml:"enable_tracing" env:"WAKAPI_SENTRY_TRACING"` @@ -161,6 +165,7 @@ type Config struct { Security securityConfig Db dbConfig Server serverConfig + Subscriptions subscriptionsConfig Sentry sentryConfig Mail mailConfig } diff --git a/models/user.go b/models/user.go index 5377b32..0317935 100644 --- a/models/user.go +++ b/models/user.go @@ -13,27 +13,28 @@ func init() { } type User struct { - ID string `json:"id" gorm:"primary_key"` - ApiKey string `json:"api_key" gorm:"unique; default:NULL"` - Email string `json:"email" gorm:"index:idx_user_email; size:255"` - Location string `json:"location"` - Password string `json:"-"` - CreatedAt CustomTime `gorm:"type:timestamp; default:CURRENT_TIMESTAMP" swaggertype:"string" format:"date" example:"2006-01-02 15:04:05.000"` - LastLoggedInAt CustomTime `gorm:"type:timestamp; default:CURRENT_TIMESTAMP" swaggertype:"string" format:"date" example:"2006-01-02 15:04:05.000"` - ShareDataMaxDays int `json:"-"` - ShareEditors bool `json:"-" gorm:"default:false; type:bool"` - ShareLanguages bool `json:"-" gorm:"default:false; type:bool"` - ShareProjects bool `json:"-" gorm:"default:false; type:bool"` - ShareOSs bool `json:"-" gorm:"default:false; type:bool; column:share_oss"` - ShareMachines bool `json:"-" gorm:"default:false; type:bool"` - ShareLabels bool `json:"-" gorm:"default:false; type:bool"` - IsAdmin bool `json:"-" gorm:"default:false; type:bool"` - HasData bool `json:"-" gorm:"default:false; type:bool"` - WakatimeApiKey string `json:"-"` // for relay middleware and imports - WakatimeApiUrl string `json:"-"` // for relay middleware and imports - ResetToken string `json:"-"` - ReportsWeekly bool `json:"-" gorm:"default:false; type:bool"` - PublicLeaderboard bool `json:"-" gorm:"default:false; type:bool"` + ID string `json:"id" gorm:"primary_key"` + ApiKey string `json:"api_key" gorm:"unique; default:NULL"` + Email string `json:"email" gorm:"index:idx_user_email; size:255"` + Location string `json:"location"` + Password string `json:"-"` + CreatedAt CustomTime `gorm:"type:timestamp; default:CURRENT_TIMESTAMP" swaggertype:"string" format:"date" example:"2006-01-02 15:04:05.000"` + LastLoggedInAt CustomTime `gorm:"type:timestamp; default:CURRENT_TIMESTAMP" swaggertype:"string" format:"date" example:"2006-01-02 15:04:05.000"` + ShareDataMaxDays int `json:"-"` + ShareEditors bool `json:"-" gorm:"default:false; type:bool"` + ShareLanguages bool `json:"-" gorm:"default:false; type:bool"` + ShareProjects bool `json:"-" gorm:"default:false; type:bool"` + ShareOSs bool `json:"-" gorm:"default:false; type:bool; column:share_oss"` + ShareMachines bool `json:"-" gorm:"default:false; type:bool"` + ShareLabels bool `json:"-" gorm:"default:false; type:bool"` + IsAdmin bool `json:"-" gorm:"default:false; type:bool"` + HasData bool `json:"-" gorm:"default:false; type:bool"` + WakatimeApiKey string `json:"-"` // for relay middleware and imports + WakatimeApiUrl string `json:"-"` // for relay middleware and imports + ResetToken string `json:"-"` + ReportsWeekly bool `json:"-" gorm:"default:false; type:bool"` + PublicLeaderboard bool `json:"-" gorm:"default:false; type:bool"` + SubscribedUntil *CustomTime `json:"-" gorm:"type:timestamp" swaggertype:"string" format:"date" example:"2006-01-02 15:04:05.000"` } type Login struct {