Skip to content

Commit

Permalink
feat: support set global Default memo visibility (#3989)
Browse files Browse the repository at this point in the history
* feat: support set global Default memo visibility

* feat: Move to WorkspaceMemoRelatedSetting

* fix: goimports check failure

* chore: change item name to default_visibility

* fix: goimports check failure
  • Loading branch information
wjsoj authored Oct 8, 2024
1 parent dc15e8f commit 1f9d657
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 73 deletions.
2 changes: 2 additions & 0 deletions proto/api/v1/workspace_setting_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ message WorkspaceMemoRelatedSetting {
bool enable_comment = 7;
// enable_location enables setting location for memo.
bool enable_location = 8;
// default_visibility set the global memos default visibility.
string default_visibility = 9;
}

message GetWorkspaceSettingRequest {
Expand Down
102 changes: 57 additions & 45 deletions proto/gen/api/v1/workspace_setting_service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions proto/gen/apidocs.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,9 @@ definitions:
enableLocation:
type: boolean
description: enable_location enables setting location for memo.
defaultVisibility:
type: string
description: default_visibility set the global memos default visibility.
apiv1WorkspaceSetting:
type: object
properties:
Expand Down
52 changes: 32 additions & 20 deletions proto/gen/store/workspace_setting.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions proto/store/workspace_setting.proto
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@ message WorkspaceMemoRelatedSetting {
bool enable_comment = 7;
// enable_location enables setting location for memo.
bool enable_location = 8;
// default_visibility set the global memos default visibility.
string default_visibility = 9;
}
16 changes: 13 additions & 3 deletions server/router/api/v1/user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,15 @@ func (s *APIV1Service) DeleteUser(ctx context.Context, request *v1pb.DeleteUserR
return &emptypb.Empty{}, nil
}

func getDefaultUserSetting() *v1pb.UserSetting {
func getDefaultUserSetting(workspaceMemoRelatedSetting *storepb.WorkspaceMemoRelatedSetting) *v1pb.UserSetting {
defaultVisibility := "PRIVATE"
if workspaceMemoRelatedSetting.DefaultVisibility != "" {
defaultVisibility = workspaceMemoRelatedSetting.DefaultVisibility
}
return &v1pb.UserSetting{
Locale: "en",
Appearance: "system",
MemoVisibility: "PRIVATE",
MemoVisibility: defaultVisibility,
}
}

Expand All @@ -289,13 +293,19 @@ func (s *APIV1Service) GetUserSetting(ctx context.Context, _ *v1pb.GetUserSettin
return nil, status.Errorf(codes.Internal, "failed to get current user: %v", err)
}

workspaceMemoRelatedSetting, err := s.Store.GetWorkspaceMemoRelatedSetting(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get workspace general setting: %v", err)
}

userSettings, err := s.Store.ListUserSettings(ctx, &store.FindUserSetting{
UserID: &user.ID,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list user settings: %v", err)
}
userSettingMessage := getDefaultUserSetting()
// getDefaultUserSetting By workspaceSetting
userSettingMessage := getDefaultUserSetting(workspaceMemoRelatedSetting)
for _, setting := range userSettings {
if setting.Key == storepb.UserSettingKey_LOCALE {
userSettingMessage.Locale = setting.GetLocale()
Expand Down
2 changes: 2 additions & 0 deletions server/router/api/v1/workspace_setting_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func convertWorkspaceMemoRelatedSettingFromStore(setting *storepb.WorkspaceMemoR
EnableLinkPreview: setting.EnableLinkPreview,
EnableComment: setting.EnableComment,
EnableLocation: setting.EnableLocation,
DefaultVisibility: setting.DefaultVisibility,
}
}

Expand All @@ -248,5 +249,6 @@ func convertWorkspaceMemoRelatedSettingToStore(setting *v1pb.WorkspaceMemoRelate
EnableLinkPreview: setting.EnableLinkPreview,
EnableComment: setting.EnableComment,
EnableLocation: setting.EnableLocation,
DefaultVisibility: setting.DefaultVisibility,
}
}
Loading

0 comments on commit 1f9d657

Please sign in to comment.