feat: add security setting section

This commit is contained in:
Steven
2024-08-18 08:43:47 +08:00
parent dba5067d51
commit 7e35d3a319
5 changed files with 89 additions and 6 deletions

View File

@ -61,6 +61,9 @@ func (s *APIV1Service) GetWorkspaceSetting(ctx context.Context, _ *v1pb.GetWorks
generalSetting := v.GetGeneral()
workspaceSetting.Branding = generalSetting.GetBranding()
workspaceSetting.CustomStyle = generalSetting.GetCustomStyle()
} else if v.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SECURITY {
securitySetting := v.GetSecurity()
workspaceSetting.DisallowUserRegistration = securitySetting.GetDisallowUserRegistration()
} else if v.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SHORTCUT_RELATED {
shortcutRelatedSetting := v.GetShortcutRelated()
workspaceSetting.DefaultVisibility = v1pb.Visibility(shortcutRelatedSetting.GetDefaultVisibility())
@ -153,6 +156,20 @@ func (s *APIV1Service) UpdateWorkspaceSetting(ctx context.Context, request *v1pb
}); err != nil {
return nil, status.Errorf(codes.Internal, "failed to update workspace setting: %v", err)
}
} else if path == "disallow_user_registration" {
securitySetting, err := s.Store.GetWorkspaceSecuritySetting(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get workspace setting: %v", err)
}
securitySetting.DisallowUserRegistration = request.Setting.DisallowUserRegistration
if _, err := s.Store.UpsertWorkspaceSetting(ctx, &storepb.WorkspaceSetting{
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SECURITY,
Value: &storepb.WorkspaceSetting_Security{
Security: securitySetting,
},
}); err != nil {
return nil, status.Errorf(codes.Internal, "failed to update workspace setting: %v", err)
}
} else {
return nil, status.Errorf(codes.InvalidArgument, "invalid path: %s", path)
}