Commit c93b1efb authored by Steven's avatar Steven

chore: update workspace setting store

parent 58ae3217
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
- [store/workspace_setting.proto](#store_workspace_setting-proto) - [store/workspace_setting.proto](#store_workspace_setting-proto)
- [WorkspaceGeneralSetting](#memos-store-WorkspaceGeneralSetting) - [WorkspaceGeneralSetting](#memos-store-WorkspaceGeneralSetting)
- [WorkspaceMemoRelatedSetting](#memos-store-WorkspaceMemoRelatedSetting)
- [WorkspaceSetting](#memos-store-WorkspaceSetting) - [WorkspaceSetting](#memos-store-WorkspaceSetting)
- [WorkspaceSettingKey](#memos-store-WorkspaceSettingKey) - [WorkspaceSettingKey](#memos-store-WorkspaceSettingKey)
...@@ -457,6 +458,22 @@ ...@@ -457,6 +458,22 @@
<a name="memos-store-WorkspaceMemoRelatedSetting"></a>
### WorkspaceMemoRelatedSetting
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| disallow_public_visible | [bool](#bool) | | disallow_public_share disallows set memo as public visible. |
| display_with_update_time | [bool](#bool) | | display_with_update_time orders and displays memo with update time. |
<a name="memos-store-WorkspaceSetting"></a> <a name="memos-store-WorkspaceSetting"></a>
### WorkspaceSetting ### WorkspaceSetting
...@@ -466,7 +483,8 @@ ...@@ -466,7 +483,8 @@
| Field | Type | Label | Description | | Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- | | ----- | ---- | ----- | ----------- |
| key | [WorkspaceSettingKey](#memos-store-WorkspaceSettingKey) | | | | key | [WorkspaceSettingKey](#memos-store-WorkspaceSettingKey) | | |
| general | [WorkspaceGeneralSetting](#memos-store-WorkspaceGeneralSetting) | | | | general_setting | [WorkspaceGeneralSetting](#memos-store-WorkspaceGeneralSetting) | | |
| memo_related_setting | [WorkspaceMemoRelatedSetting](#memos-store-WorkspaceMemoRelatedSetting) | | |
...@@ -484,6 +502,7 @@ ...@@ -484,6 +502,7 @@
| ---- | ------ | ----------- | | ---- | ------ | ----------- |
| WORKSPACE_SETTING_KEY_UNSPECIFIED | 0 | | | WORKSPACE_SETTING_KEY_UNSPECIFIED | 0 | |
| WORKSPACE_SETTING_GENERAL | 1 | WORKSPACE_SETTING_GENERAL is the key for general settings. | | WORKSPACE_SETTING_GENERAL | 1 | WORKSPACE_SETTING_GENERAL is the key for general settings. |
| WORKSPACE_SETTING_MEMO_RELATED | 2 | WORKSPACE_SETTING_MEMO_RELATED is the key for memo related settings. |
......
This diff is collapsed.
...@@ -8,12 +8,15 @@ enum WorkspaceSettingKey { ...@@ -8,12 +8,15 @@ enum WorkspaceSettingKey {
WORKSPACE_SETTING_KEY_UNSPECIFIED = 0; WORKSPACE_SETTING_KEY_UNSPECIFIED = 0;
// WORKSPACE_SETTING_GENERAL is the key for general settings. // WORKSPACE_SETTING_GENERAL is the key for general settings.
WORKSPACE_SETTING_GENERAL = 1; WORKSPACE_SETTING_GENERAL = 1;
// WORKSPACE_SETTING_MEMO_RELATED is the key for memo related settings.
WORKSPACE_SETTING_MEMO_RELATED = 2;
} }
message WorkspaceSetting { message WorkspaceSetting {
WorkspaceSettingKey key = 1; WorkspaceSettingKey key = 1;
oneof value { oneof value {
WorkspaceGeneralSetting general = 2; WorkspaceGeneralSetting general_setting = 2;
WorkspaceMemoRelatedSetting memo_related_setting = 3;
} }
} }
...@@ -29,3 +32,10 @@ message WorkspaceGeneralSetting { ...@@ -29,3 +32,10 @@ message WorkspaceGeneralSetting {
// additional_style is the additional style. // additional_style is the additional style.
string additional_style = 6; string additional_style = 6;
} }
message WorkspaceMemoRelatedSetting {
// disallow_public_share disallows set memo as public visible.
bool disallow_public_visible = 1;
// display_with_update_time orders and displays memo with update time.
bool display_with_update_time = 2;
}
...@@ -57,7 +57,7 @@ func convertWorkspaceSettingFromStore(setting *storepb.WorkspaceSetting) *apiv2p ...@@ -57,7 +57,7 @@ func convertWorkspaceSettingFromStore(setting *storepb.WorkspaceSetting) *apiv2p
return &apiv2pb.WorkspaceSetting{ return &apiv2pb.WorkspaceSetting{
Name: fmt.Sprintf("%s%s", WorkspaceSettingNamePrefix, setting.Key.String()), Name: fmt.Sprintf("%s%s", WorkspaceSettingNamePrefix, setting.Key.String()),
Value: &apiv2pb.WorkspaceSetting_GeneralSetting{ Value: &apiv2pb.WorkspaceSetting_GeneralSetting{
GeneralSetting: convertWorkspaceGeneralSettingFromStore(setting.GetGeneral()), GeneralSetting: convertWorkspaceGeneralSettingFromStore(setting.GetGeneralSetting()),
}, },
} }
} }
...@@ -66,8 +66,8 @@ func convertWorkspaceSettingToStore(setting *apiv2pb.WorkspaceSetting) *storepb. ...@@ -66,8 +66,8 @@ func convertWorkspaceSettingToStore(setting *apiv2pb.WorkspaceSetting) *storepb.
settingKeyString, _ := ExtractWorkspaceSettingKeyFromName(setting.Name) settingKeyString, _ := ExtractWorkspaceSettingKeyFromName(setting.Name)
return &storepb.WorkspaceSetting{ return &storepb.WorkspaceSetting{
Key: storepb.WorkspaceSettingKey(storepb.WorkspaceSettingKey_value[settingKeyString]), Key: storepb.WorkspaceSettingKey(storepb.WorkspaceSettingKey_value[settingKeyString]),
Value: &storepb.WorkspaceSetting_General{ Value: &storepb.WorkspaceSetting_GeneralSetting{
General: convertWorkspaceGeneralSettingToStore(setting.GetGeneralSetting()), GeneralSetting: convertWorkspaceGeneralSettingToStore(setting.GetGeneralSetting()),
}, },
} }
} }
......
...@@ -74,7 +74,7 @@ func (d *DB) UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.Works ...@@ -74,7 +74,7 @@ func (d *DB) UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.Works
ON DUPLICATE KEY UPDATE value = ?` ON DUPLICATE KEY UPDATE value = ?`
var valueString string var valueString string
if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL { if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL {
valueBytes, err := protojson.Marshal(upsert.GetGeneral()) valueBytes, err := protojson.Marshal(upsert.GetGeneralSetting())
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -116,7 +116,7 @@ func (d *DB) ListWorkspaceSettingsV1(ctx context.Context, find *store.FindWorksp ...@@ -116,7 +116,7 @@ func (d *DB) ListWorkspaceSettingsV1(ctx context.Context, find *store.FindWorksp
if err := protojson.Unmarshal([]byte(valueString), generalSetting); err != nil { if err := protojson.Unmarshal([]byte(valueString), generalSetting); err != nil {
return nil, err return nil, err
} }
workspaceSetting.Value = &storepb.WorkspaceSetting_General{General: generalSetting} workspaceSetting.Value = &storepb.WorkspaceSetting_GeneralSetting{GeneralSetting: generalSetting}
} else { } else {
// Skip unknown workspace setting key. // Skip unknown workspace setting key.
continue continue
......
...@@ -84,7 +84,7 @@ func (d *DB) UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.Works ...@@ -84,7 +84,7 @@ func (d *DB) UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.Works
SET value = EXCLUDED.value` SET value = EXCLUDED.value`
var valueString string var valueString string
if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL { if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL {
valueBytes, err := protojson.Marshal(upsert.GetGeneral()) valueBytes, err := protojson.Marshal(upsert.GetGeneralSetting())
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -126,7 +126,7 @@ func (d *DB) ListWorkspaceSettingsV1(ctx context.Context, find *store.FindWorksp ...@@ -126,7 +126,7 @@ func (d *DB) ListWorkspaceSettingsV1(ctx context.Context, find *store.FindWorksp
if err := protojson.Unmarshal([]byte(valueString), generalSetting); err != nil { if err := protojson.Unmarshal([]byte(valueString), generalSetting); err != nil {
return nil, err return nil, err
} }
workspaceSetting.Value = &storepb.WorkspaceSetting_General{General: generalSetting} workspaceSetting.Value = &storepb.WorkspaceSetting_GeneralSetting{GeneralSetting: generalSetting}
} else { } else {
// Skip unknown workspace setting key. // Skip unknown workspace setting key.
continue continue
......
...@@ -84,7 +84,7 @@ func (d *DB) UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.Works ...@@ -84,7 +84,7 @@ func (d *DB) UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.Works
SET value = EXCLUDED.value` SET value = EXCLUDED.value`
var valueString string var valueString string
if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL { if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL {
valueBytes, err := protojson.Marshal(upsert.GetGeneral()) valueBytes, err := protojson.Marshal(upsert.GetGeneralSetting())
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -125,7 +125,7 @@ func (d *DB) ListWorkspaceSettingsV1(ctx context.Context, find *store.FindWorksp ...@@ -125,7 +125,7 @@ func (d *DB) ListWorkspaceSettingsV1(ctx context.Context, find *store.FindWorksp
if err := protojson.Unmarshal([]byte(valueString), generalSetting); err != nil { if err := protojson.Unmarshal([]byte(valueString), generalSetting); err != nil {
return nil, err return nil, err
} }
workspaceSetting.Value = &storepb.WorkspaceSetting_General{General: generalSetting} workspaceSetting.Value = &storepb.WorkspaceSetting_GeneralSetting{GeneralSetting: generalSetting}
} else { } else {
// Skip unknown workspace setting key. // Skip unknown workspace setting key.
continue continue
......
...@@ -52,7 +52,7 @@ func (s *Store) MigrateWorkspaceSetting(ctx context.Context) error { ...@@ -52,7 +52,7 @@ func (s *Store) MigrateWorkspaceSetting(ctx context.Context) error {
if _, err := s.UpsertWorkspaceSettingV1(ctx, &storepb.WorkspaceSetting{ if _, err := s.UpsertWorkspaceSettingV1(ctx, &storepb.WorkspaceSetting{
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL, Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
Value: &storepb.WorkspaceSetting_General{General: workspaceGeneralSetting}, Value: &storepb.WorkspaceSetting_GeneralSetting{GeneralSetting: workspaceGeneralSetting},
}); err != nil { }); err != nil {
return errors.Wrap(err, "failed to upsert workspace general setting") return errors.Wrap(err, "failed to upsert workspace general setting")
} }
......
...@@ -123,7 +123,7 @@ func (s *Store) GetWorkspaceGeneralSetting(ctx context.Context) (*storepb.Worksp ...@@ -123,7 +123,7 @@ func (s *Store) GetWorkspaceGeneralSetting(ctx context.Context) (*storepb.Worksp
workspaceGeneralSetting := &storepb.WorkspaceGeneralSetting{} workspaceGeneralSetting := &storepb.WorkspaceGeneralSetting{}
if workspaceSetting != nil { if workspaceSetting != nil {
workspaceGeneralSetting = workspaceSetting.GetGeneral() workspaceGeneralSetting = workspaceSetting.GetGeneralSetting()
} }
return workspaceGeneralSetting, nil return workspaceGeneralSetting, nil
} }
...@@ -15,8 +15,8 @@ func TestWorkspaceSettingV1Store(t *testing.T) { ...@@ -15,8 +15,8 @@ func TestWorkspaceSettingV1Store(t *testing.T) {
ts := NewTestingStore(ctx, t) ts := NewTestingStore(ctx, t)
workspaceSetting, err := ts.UpsertWorkspaceSettingV1(ctx, &storepb.WorkspaceSetting{ workspaceSetting, err := ts.UpsertWorkspaceSettingV1(ctx, &storepb.WorkspaceSetting{
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL, Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
Value: &storepb.WorkspaceSetting_General{ Value: &storepb.WorkspaceSetting_GeneralSetting{
General: &storepb.WorkspaceGeneralSetting{ GeneralSetting: &storepb.WorkspaceGeneralSetting{
DisallowSignup: true, DisallowSignup: true,
}, },
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment