mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-03 12:17:55 +00:00
refactor: workspace setting definitions
This commit is contained in:
@ -3,6 +3,14 @@ package postgres
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
)
|
||||
|
||||
var (
|
||||
protojsonUnmarshaler = protojson.UnmarshalOptions{
|
||||
DiscardUnknown: true,
|
||||
}
|
||||
)
|
||||
|
||||
func placeholder(n int) string {
|
||||
|
@ -23,13 +23,13 @@ func (d *DB) UpsertUserSetting(ctx context.Context, upsert *storepb.UserSetting)
|
||||
`
|
||||
|
||||
var valueString string
|
||||
if upsert.Key == storepb.UserSettingKey_ACCESS_TOKENS {
|
||||
if upsert.Key == storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS {
|
||||
valueBytes, err := protojson.Marshal(upsert.GetAccessTokens())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
valueString = string(valueBytes)
|
||||
} else if upsert.Key == storepb.UserSettingKey_GENERAL {
|
||||
} else if upsert.Key == storepb.UserSettingKey_USER_SETTING_GENERAL {
|
||||
valueBytes, err := protojson.Marshal(upsert.GetGeneral())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -82,16 +82,16 @@ func (d *DB) ListUserSettings(ctx context.Context, find *store.FindUserSetting)
|
||||
return nil, err
|
||||
}
|
||||
userSetting.Key = storepb.UserSettingKey(storepb.UserSettingKey_value[keyString])
|
||||
if userSetting.Key == storepb.UserSettingKey_ACCESS_TOKENS {
|
||||
userSettingAccessTokens := &storepb.UserSettingAccessTokens{}
|
||||
if userSetting.Key == storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS {
|
||||
userSettingAccessTokens := &storepb.UserSetting_AccessTokensSetting{}
|
||||
if err := protojson.Unmarshal([]byte(valueString), userSettingAccessTokens); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
userSetting.Value = &storepb.UserSetting_AccessTokens{
|
||||
AccessTokens: userSettingAccessTokens,
|
||||
}
|
||||
} else if userSetting.Key == storepb.UserSettingKey_GENERAL {
|
||||
userSettingGeneral := &storepb.UserSettingGeneral{}
|
||||
} else if userSetting.Key == storepb.UserSettingKey_USER_SETTING_GENERAL {
|
||||
userSettingGeneral := &storepb.UserSetting_GeneralSetting{}
|
||||
if err := protojson.Unmarshal([]byte(valueString), userSettingGeneral); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -3,11 +3,12 @@ package postgres
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
storepb "github.com/yourselfhosted/slash/proto/gen/store"
|
||||
"github.com/yourselfhosted/slash/store"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
)
|
||||
|
||||
func (d *DB) UpsertWorkspaceSetting(ctx context.Context, upsert *storepb.WorkspaceSetting) (*storepb.WorkspaceSetting, error) {
|
||||
@ -21,18 +22,18 @@ func (d *DB) UpsertWorkspaceSetting(ctx context.Context, upsert *storepb.Workspa
|
||||
SET value = EXCLUDED.value
|
||||
`
|
||||
var valueString string
|
||||
if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_LICENSE_KEY {
|
||||
valueString = upsert.GetLicenseKey()
|
||||
} else if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SECRET_SESSION {
|
||||
valueString = upsert.GetSecretSession()
|
||||
} else if upsert.Key == storepb.WorkspaceSettingKey_WORKSAPCE_SETTING_ENABLE_SIGNUP {
|
||||
valueString = strconv.FormatBool(upsert.GetEnableSignup())
|
||||
} else if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_CUSTOM_STYLE {
|
||||
valueString = upsert.GetCustomStyle()
|
||||
} else if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_INSTANCE_URL {
|
||||
valueString = upsert.GetInstanceUrl()
|
||||
} else if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_DEFAULT_VISIBILITY {
|
||||
valueString = upsert.GetDefaultVisibility().String()
|
||||
if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL {
|
||||
valueBytes, err := protojson.Marshal(upsert.GetGeneral())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
valueString = string(valueBytes)
|
||||
} else if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SHORTCUT_RELATED {
|
||||
valueBytes, err := protojson.Marshal(upsert.GetShortcutRelated())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
valueString = string(valueBytes)
|
||||
} else {
|
||||
return nil, errors.New("invalid workspace setting key")
|
||||
}
|
||||
@ -76,22 +77,29 @@ func (d *DB) ListWorkspaceSettings(ctx context.Context, find *store.FindWorkspac
|
||||
return nil, err
|
||||
}
|
||||
workspaceSetting.Key = storepb.WorkspaceSettingKey(storepb.WorkspaceSettingKey_value[keyString])
|
||||
if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_LICENSE_KEY {
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_LicenseKey{LicenseKey: valueString}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SECRET_SESSION {
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_SecretSession{SecretSession: valueString}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSAPCE_SETTING_ENABLE_SIGNUP {
|
||||
enableSignup, err := strconv.ParseBool(valueString)
|
||||
if err != nil {
|
||||
if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL {
|
||||
workspaceSettingGeneral := &storepb.WorkspaceSetting_GeneralSetting{}
|
||||
if err := protojsonUnmarshaler.Unmarshal([]byte(valueString), workspaceSettingGeneral); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_EnableSignup{EnableSignup: enableSignup}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_CUSTOM_STYLE {
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_CustomStyle{CustomStyle: valueString}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_INSTANCE_URL {
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_InstanceUrl{InstanceUrl: valueString}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_DEFAULT_VISIBILITY {
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_DefaultVisibility{DefaultVisibility: storepb.Visibility(storepb.Visibility_value[valueString])}
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_General{
|
||||
General: workspaceSettingGeneral,
|
||||
}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SHORTCUT_RELATED {
|
||||
workspaceSettingShortcutRelated := &storepb.WorkspaceSetting_ShortcutRelatedSetting{}
|
||||
if err := protojsonUnmarshaler.Unmarshal([]byte(valueString), workspaceSettingShortcutRelated); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_ShortcutRelated{
|
||||
ShortcutRelated: workspaceSettingShortcutRelated,
|
||||
}
|
||||
} else if slices.Contains([]storepb.WorkspaceSettingKey{
|
||||
storepb.WorkspaceSettingKey_WORKSPACE_SETTING_LICENSE_KEY,
|
||||
storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SECRET_SESSION,
|
||||
storepb.WorkspaceSettingKey_WORKSPACE_SETTING_CUSTOM_STYLE,
|
||||
storepb.WorkspaceSettingKey_WORKSPACE_SETTING_DEFAULT_VISIBILITY,
|
||||
}, workspaceSetting.Key) {
|
||||
workspaceSetting.Raw = valueString
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
@ -104,3 +112,14 @@ func (d *DB) ListWorkspaceSettings(ctx context.Context, find *store.FindWorkspac
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (d *DB) DeleteWorkspaceSetting(ctx context.Context, key storepb.WorkspaceSettingKey) error {
|
||||
stmt := `
|
||||
DELETE FROM workspace_setting
|
||||
WHERE key = $1
|
||||
`
|
||||
if _, err := d.db.ExecContext(ctx, stmt, key.String()); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
9
store/db/sqlite/common.go
Normal file
9
store/db/sqlite/common.go
Normal file
@ -0,0 +1,9 @@
|
||||
package sqlite
|
||||
|
||||
import "google.golang.org/protobuf/encoding/protojson"
|
||||
|
||||
var (
|
||||
protojsonUnmarshaler = protojson.UnmarshalOptions{
|
||||
DiscardUnknown: true,
|
||||
}
|
||||
)
|
@ -22,13 +22,13 @@ func (d *DB) UpsertUserSetting(ctx context.Context, upsert *storepb.UserSetting)
|
||||
SET value = EXCLUDED.value
|
||||
`
|
||||
var valueString string
|
||||
if upsert.Key == storepb.UserSettingKey_ACCESS_TOKENS {
|
||||
if upsert.Key == storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS {
|
||||
valueBytes, err := protojson.Marshal(upsert.GetAccessTokens())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
valueString = string(valueBytes)
|
||||
} else if upsert.Key == storepb.UserSettingKey_GENERAL {
|
||||
} else if upsert.Key == storepb.UserSettingKey_USER_SETTING_GENERAL {
|
||||
valueBytes, err := protojson.Marshal(upsert.GetGeneral())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -81,16 +81,16 @@ func (d *DB) ListUserSettings(ctx context.Context, find *store.FindUserSetting)
|
||||
return nil, err
|
||||
}
|
||||
userSetting.Key = storepb.UserSettingKey(storepb.UserSettingKey_value[keyString])
|
||||
if userSetting.Key == storepb.UserSettingKey_ACCESS_TOKENS {
|
||||
userSettingAccessTokens := &storepb.UserSettingAccessTokens{}
|
||||
if userSetting.Key == storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS {
|
||||
userSettingAccessTokens := &storepb.UserSetting_AccessTokensSetting{}
|
||||
if err := protojson.Unmarshal([]byte(valueString), userSettingAccessTokens); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
userSetting.Value = &storepb.UserSetting_AccessTokens{
|
||||
AccessTokens: userSettingAccessTokens,
|
||||
}
|
||||
} else if userSetting.Key == storepb.UserSettingKey_GENERAL {
|
||||
userSettingGeneral := &storepb.UserSettingGeneral{}
|
||||
} else if userSetting.Key == storepb.UserSettingKey_USER_SETTING_GENERAL {
|
||||
userSettingGeneral := &storepb.UserSetting_GeneralSetting{}
|
||||
if err := protojson.Unmarshal([]byte(valueString), userSettingGeneral); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -3,11 +3,12 @@ package sqlite
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
storepb "github.com/yourselfhosted/slash/proto/gen/store"
|
||||
"github.com/yourselfhosted/slash/store"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
)
|
||||
|
||||
func (d *DB) UpsertWorkspaceSetting(ctx context.Context, upsert *storepb.WorkspaceSetting) (*storepb.WorkspaceSetting, error) {
|
||||
@ -21,20 +22,18 @@ func (d *DB) UpsertWorkspaceSetting(ctx context.Context, upsert *storepb.Workspa
|
||||
SET value = EXCLUDED.value
|
||||
`
|
||||
var valueString string
|
||||
if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_LICENSE_KEY {
|
||||
valueString = upsert.GetLicenseKey()
|
||||
} else if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SECRET_SESSION {
|
||||
valueString = upsert.GetSecretSession()
|
||||
} else if upsert.Key == storepb.WorkspaceSettingKey_WORKSAPCE_SETTING_ENABLE_SIGNUP {
|
||||
valueString = strconv.FormatBool(upsert.GetEnableSignup())
|
||||
} else if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_CUSTOM_STYLE {
|
||||
valueString = upsert.GetCustomStyle()
|
||||
} else if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_INSTANCE_URL {
|
||||
valueString = upsert.GetInstanceUrl()
|
||||
} else if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_DEFAULT_VISIBILITY {
|
||||
valueString = upsert.GetDefaultVisibility().String()
|
||||
} else if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_FAVICON_PROVIDER {
|
||||
valueString = upsert.GetFaviconProvider()
|
||||
if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL {
|
||||
valueBytes, err := protojson.Marshal(upsert.GetGeneral())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
valueString = string(valueBytes)
|
||||
} else if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SHORTCUT_RELATED {
|
||||
valueBytes, err := protojson.Marshal(upsert.GetShortcutRelated())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
valueString = string(valueBytes)
|
||||
} else {
|
||||
return nil, errors.New("invalid workspace setting key")
|
||||
}
|
||||
@ -78,24 +77,29 @@ func (d *DB) ListWorkspaceSettings(ctx context.Context, find *store.FindWorkspac
|
||||
return nil, err
|
||||
}
|
||||
workspaceSetting.Key = storepb.WorkspaceSettingKey(storepb.WorkspaceSettingKey_value[keyString])
|
||||
if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_LICENSE_KEY {
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_LicenseKey{LicenseKey: valueString}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SECRET_SESSION {
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_SecretSession{SecretSession: valueString}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSAPCE_SETTING_ENABLE_SIGNUP {
|
||||
enableSignup, err := strconv.ParseBool(valueString)
|
||||
if err != nil {
|
||||
if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL {
|
||||
workspaceSettingGeneral := &storepb.WorkspaceSetting_GeneralSetting{}
|
||||
if err := protojsonUnmarshaler.Unmarshal([]byte(valueString), workspaceSettingGeneral); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_EnableSignup{EnableSignup: enableSignup}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_CUSTOM_STYLE {
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_CustomStyle{CustomStyle: valueString}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_INSTANCE_URL {
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_InstanceUrl{InstanceUrl: valueString}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_DEFAULT_VISIBILITY {
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_DefaultVisibility{DefaultVisibility: storepb.Visibility(storepb.Visibility_value[valueString])}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_FAVICON_PROVIDER {
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_FaviconProvider{FaviconProvider: valueString}
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_General{
|
||||
General: workspaceSettingGeneral,
|
||||
}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SHORTCUT_RELATED {
|
||||
workspaceSettingShortcutRelated := &storepb.WorkspaceSetting_ShortcutRelatedSetting{}
|
||||
if err := protojsonUnmarshaler.Unmarshal([]byte(valueString), workspaceSettingShortcutRelated); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_ShortcutRelated{
|
||||
ShortcutRelated: workspaceSettingShortcutRelated,
|
||||
}
|
||||
} else if slices.Contains([]storepb.WorkspaceSettingKey{
|
||||
storepb.WorkspaceSettingKey_WORKSPACE_SETTING_LICENSE_KEY,
|
||||
storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SECRET_SESSION,
|
||||
storepb.WorkspaceSettingKey_WORKSPACE_SETTING_CUSTOM_STYLE,
|
||||
storepb.WorkspaceSettingKey_WORKSPACE_SETTING_DEFAULT_VISIBILITY,
|
||||
}, workspaceSetting.Key) {
|
||||
workspaceSetting.Raw = valueString
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
@ -108,3 +112,14 @@ func (d *DB) ListWorkspaceSettings(ctx context.Context, find *store.FindWorkspac
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (d *DB) DeleteWorkspaceSetting(ctx context.Context, key storepb.WorkspaceSettingKey) error {
|
||||
stmt := `
|
||||
DELETE FROM workspace_setting
|
||||
WHERE key = ?
|
||||
`
|
||||
if _, err := d.db.ExecContext(ctx, stmt, key.String()); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -48,4 +48,5 @@ type Driver interface {
|
||||
// WorkspaceSetting model related methods.
|
||||
UpsertWorkspaceSetting(ctx context.Context, upsert *storepb.WorkspaceSetting) (*storepb.WorkspaceSetting, error)
|
||||
ListWorkspaceSettings(ctx context.Context, find *FindWorkspaceSetting) ([]*storepb.WorkspaceSetting, error)
|
||||
DeleteWorkspaceSetting(ctx context.Context, key storepb.WorkspaceSettingKey) error
|
||||
}
|
||||
|
57
store/migrator.go
Normal file
57
store/migrator.go
Normal file
@ -0,0 +1,57 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
storepb "github.com/yourselfhosted/slash/proto/gen/store"
|
||||
)
|
||||
|
||||
func (s *Store) MigrateWorkspaceSettings(ctx context.Context) error {
|
||||
workspaceSettings, err := s.driver.ListWorkspaceSettings(ctx, &FindWorkspaceSetting{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
workspaceSettingGeneral, err := s.GetWorkspaceSetting(ctx, &FindWorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if workspaceSettingGeneral == nil || workspaceSettingGeneral.GetGeneral() == nil {
|
||||
workspaceSettingGeneral = &storepb.WorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
Value: &storepb.WorkspaceSetting_General{
|
||||
General: &storepb.WorkspaceSetting_GeneralSetting{},
|
||||
},
|
||||
}
|
||||
}
|
||||
updateWorkspaceSetting := false
|
||||
for _, workspaceSetting := range workspaceSettings {
|
||||
if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_LICENSE_KEY {
|
||||
workspaceSettingGeneral.GetGeneral().LicenseKey = workspaceSetting.Raw
|
||||
updateWorkspaceSetting = true
|
||||
if err := s.DeleteWorkspaceSetting(ctx, storepb.WorkspaceSettingKey_WORKSPACE_SETTING_LICENSE_KEY); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_CUSTOM_STYLE {
|
||||
workspaceSettingGeneral.GetGeneral().CustomStyle = workspaceSetting.Raw
|
||||
updateWorkspaceSetting = true
|
||||
if err := s.DeleteWorkspaceSetting(ctx, storepb.WorkspaceSettingKey_WORKSPACE_SETTING_CUSTOM_STYLE); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SECRET_SESSION {
|
||||
workspaceSettingGeneral.GetGeneral().SecretSession = workspaceSetting.Raw
|
||||
updateWorkspaceSetting = true
|
||||
if err := s.DeleteWorkspaceSetting(ctx, storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SECRET_SESSION); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if updateWorkspaceSetting {
|
||||
if _, err := s.UpsertWorkspaceSetting(ctx, workspaceSettingGeneral); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
@ -54,16 +54,16 @@ func (s *Store) GetUserSetting(ctx context.Context, find *FindUserSetting) (*sto
|
||||
}
|
||||
|
||||
// GetUserAccessTokens returns the access tokens of the user.
|
||||
func (s *Store) GetUserAccessTokens(ctx context.Context, userID int32) ([]*storepb.UserSettingAccessTokens_AccessToken, error) {
|
||||
func (s *Store) GetUserAccessTokens(ctx context.Context, userID int32) ([]*storepb.UserSetting_AccessTokensSetting_AccessToken, error) {
|
||||
userSetting, err := s.GetUserSetting(ctx, &FindUserSetting{
|
||||
UserID: &userID,
|
||||
Key: storepb.UserSettingKey_ACCESS_TOKENS,
|
||||
Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if userSetting == nil {
|
||||
return []*storepb.UserSettingAccessTokens_AccessToken{}, nil
|
||||
return []*storepb.UserSetting_AccessTokensSetting_AccessToken{}, nil
|
||||
}
|
||||
|
||||
accessTokensUserSetting := userSetting.GetAccessTokens()
|
||||
|
@ -3,6 +3,8 @@ package store
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
storepb "github.com/yourselfhosted/slash/proto/gen/store"
|
||||
)
|
||||
|
||||
@ -50,3 +52,11 @@ func (s *Store) GetWorkspaceSetting(ctx context.Context, find *FindWorkspaceSett
|
||||
s.workspaceSettingCache.Store(workspaceSetting.Key, workspaceSetting)
|
||||
return workspaceSetting, nil
|
||||
}
|
||||
|
||||
func (s *Store) DeleteWorkspaceSetting(ctx context.Context, key storepb.WorkspaceSettingKey) error {
|
||||
if err := s.driver.DeleteWorkspaceSetting(ctx, key); err != nil {
|
||||
return errors.Wrap(err, "failed to delete workspace setting")
|
||||
}
|
||||
s.workspaceSettingCache.Delete(key)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user