Commit c93b1efb authored by Steven's avatar Steven

chore: update workspace setting store

parent 58ae3217
......@@ -38,6 +38,7 @@
- [store/workspace_setting.proto](#store_workspace_setting-proto)
- [WorkspaceGeneralSetting](#memos-store-WorkspaceGeneralSetting)
- [WorkspaceMemoRelatedSetting](#memos-store-WorkspaceMemoRelatedSetting)
- [WorkspaceSetting](#memos-store-WorkspaceSetting)
- [WorkspaceSettingKey](#memos-store-WorkspaceSettingKey)
......@@ -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>
### WorkspaceSetting
......@@ -466,7 +483,8 @@
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| 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 @@
| ---- | ------ | ----------- |
| WORKSPACE_SETTING_KEY_UNSPECIFIED | 0 | |
| 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 {
WORKSPACE_SETTING_KEY_UNSPECIFIED = 0;
// WORKSPACE_SETTING_GENERAL is the key for general settings.
WORKSPACE_SETTING_GENERAL = 1;
// WORKSPACE_SETTING_MEMO_RELATED is the key for memo related settings.
WORKSPACE_SETTING_MEMO_RELATED = 2;
}
message WorkspaceSetting {
WorkspaceSettingKey key = 1;
oneof value {
WorkspaceGeneralSetting general = 2;
WorkspaceGeneralSetting general_setting = 2;
WorkspaceMemoRelatedSetting memo_related_setting = 3;
}
}
......@@ -29,3 +32,10 @@ message WorkspaceGeneralSetting {
// additional_style is the additional style.
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
return &apiv2pb.WorkspaceSetting{
Name: fmt.Sprintf("%s%s", WorkspaceSettingNamePrefix, setting.Key.String()),
Value: &apiv2pb.WorkspaceSetting_GeneralSetting{
GeneralSetting: convertWorkspaceGeneralSettingFromStore(setting.GetGeneral()),
GeneralSetting: convertWorkspaceGeneralSettingFromStore(setting.GetGeneralSetting()),
},
}
}
......@@ -66,8 +66,8 @@ func convertWorkspaceSettingToStore(setting *apiv2pb.WorkspaceSetting) *storepb.
settingKeyString, _ := ExtractWorkspaceSettingKeyFromName(setting.Name)
return &storepb.WorkspaceSetting{
Key: storepb.WorkspaceSettingKey(storepb.WorkspaceSettingKey_value[settingKeyString]),
Value: &storepb.WorkspaceSetting_General{
General: convertWorkspaceGeneralSettingToStore(setting.GetGeneralSetting()),
Value: &storepb.WorkspaceSetting_GeneralSetting{
GeneralSetting: convertWorkspaceGeneralSettingToStore(setting.GetGeneralSetting()),
},
}
}
......
......@@ -74,7 +74,7 @@ func (d *DB) UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.Works
ON DUPLICATE KEY UPDATE value = ?`
var valueString string
if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL {
valueBytes, err := protojson.Marshal(upsert.GetGeneral())
valueBytes, err := protojson.Marshal(upsert.GetGeneralSetting())
if err != nil {
return nil, err
}
......@@ -116,7 +116,7 @@ func (d *DB) ListWorkspaceSettingsV1(ctx context.Context, find *store.FindWorksp
if err := protojson.Unmarshal([]byte(valueString), generalSetting); err != nil {
return nil, err
}
workspaceSetting.Value = &storepb.WorkspaceSetting_General{General: generalSetting}
workspaceSetting.Value = &storepb.WorkspaceSetting_GeneralSetting{GeneralSetting: generalSetting}
} else {
// Skip unknown workspace setting key.
continue
......
......@@ -84,7 +84,7 @@ func (d *DB) UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.Works
SET value = EXCLUDED.value`
var valueString string
if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL {
valueBytes, err := protojson.Marshal(upsert.GetGeneral())
valueBytes, err := protojson.Marshal(upsert.GetGeneralSetting())
if err != nil {
return nil, err
}
......@@ -126,7 +126,7 @@ func (d *DB) ListWorkspaceSettingsV1(ctx context.Context, find *store.FindWorksp
if err := protojson.Unmarshal([]byte(valueString), generalSetting); err != nil {
return nil, err
}
workspaceSetting.Value = &storepb.WorkspaceSetting_General{General: generalSetting}
workspaceSetting.Value = &storepb.WorkspaceSetting_GeneralSetting{GeneralSetting: generalSetting}
} else {
// Skip unknown workspace setting key.
continue
......
......@@ -84,7 +84,7 @@ func (d *DB) UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.Works
SET value = EXCLUDED.value`
var valueString string
if upsert.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL {
valueBytes, err := protojson.Marshal(upsert.GetGeneral())
valueBytes, err := protojson.Marshal(upsert.GetGeneralSetting())
if err != nil {
return nil, err
}
......@@ -125,7 +125,7 @@ func (d *DB) ListWorkspaceSettingsV1(ctx context.Context, find *store.FindWorksp
if err := protojson.Unmarshal([]byte(valueString), generalSetting); err != nil {
return nil, err
}
workspaceSetting.Value = &storepb.WorkspaceSetting_General{General: generalSetting}
workspaceSetting.Value = &storepb.WorkspaceSetting_GeneralSetting{GeneralSetting: generalSetting}
} else {
// Skip unknown workspace setting key.
continue
......
......@@ -52,7 +52,7 @@ func (s *Store) MigrateWorkspaceSetting(ctx context.Context) error {
if _, err := s.UpsertWorkspaceSettingV1(ctx, &storepb.WorkspaceSetting{
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
Value: &storepb.WorkspaceSetting_General{General: workspaceGeneralSetting},
Value: &storepb.WorkspaceSetting_GeneralSetting{GeneralSetting: workspaceGeneralSetting},
}); err != nil {
return errors.Wrap(err, "failed to upsert workspace general setting")
}
......
......@@ -123,7 +123,7 @@ func (s *Store) GetWorkspaceGeneralSetting(ctx context.Context) (*storepb.Worksp
workspaceGeneralSetting := &storepb.WorkspaceGeneralSetting{}
if workspaceSetting != nil {
workspaceGeneralSetting = workspaceSetting.GetGeneral()
workspaceGeneralSetting = workspaceSetting.GetGeneralSetting()
}
return workspaceGeneralSetting, nil
}
......@@ -15,8 +15,8 @@ func TestWorkspaceSettingV1Store(t *testing.T) {
ts := NewTestingStore(ctx, t)
workspaceSetting, err := ts.UpsertWorkspaceSettingV1(ctx, &storepb.WorkspaceSetting{
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
Value: &storepb.WorkspaceSetting_General{
General: &storepb.WorkspaceGeneralSetting{
Value: &storepb.WorkspaceSetting_GeneralSetting{
GeneralSetting: &storepb.WorkspaceGeneralSetting{
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