Skip to content

Commit

Permalink
chore: rename workspace setting service
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Jan 29, 2024
1 parent dd9ee44 commit de8db63
Show file tree
Hide file tree
Showing 28 changed files with 1,537 additions and 189 deletions.
8 changes: 4 additions & 4 deletions api/v1/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *APIV1Service) SignIn(c echo.Context) error {
ctx := c.Request().Context()
signin := &SignIn{}

disablePasswordLoginSystemSetting, err := s.Store.GetSystemSetting(ctx, &store.FindSystemSetting{
disablePasswordLoginSystemSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
Name: SystemSettingDisablePasswordLoginName.String(),
})
if err != nil {
Expand Down Expand Up @@ -186,7 +186,7 @@ func (s *APIV1Service) SignInSSO(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, "Incorrect login credentials, please try again")
}
if user == nil {
allowSignUpSetting, err := s.Store.GetSystemSetting(ctx, &store.FindSystemSetting{
allowSignUpSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
Name: SystemSettingAllowSignUpName.String(),
})
if err != nil {
Expand Down Expand Up @@ -303,7 +303,7 @@ func (s *APIV1Service) SignUp(c echo.Context) error {
// Change the default role to host if there is no host user.
userCreate.Role = store.RoleHost
} else {
allowSignUpSetting, err := s.Store.GetSystemSetting(ctx, &store.FindSystemSetting{
allowSignUpSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
Name: SystemSettingAllowSignUpName.String(),
})
if err != nil {
Expand All @@ -321,7 +321,7 @@ func (s *APIV1Service) SignUp(c echo.Context) error {
return echo.NewHTTPError(http.StatusUnauthorized, "signup is disabled").SetInternal(err)
}

disablePasswordLoginSystemSetting, err := s.Store.GetSystemSetting(ctx, &store.FindSystemSetting{
disablePasswordLoginSystemSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
Name: SystemSettingDisablePasswordLoginName.String(),
})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions api/v1/memo.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (s *APIV1Service) CreateMemo(c echo.Context) error {
}

// Find disable public memos system setting.
disablePublicMemosSystemSetting, err := s.Store.GetSystemSetting(ctx, &store.FindSystemSetting{
disablePublicMemosSystemSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
Name: SystemSettingDisablePublicMemosName.String(),
})
if err != nil {
Expand Down Expand Up @@ -714,7 +714,7 @@ func (s *APIV1Service) UpdateMemo(c echo.Context) error {
visibility := store.Visibility(patchMemoRequest.Visibility.String())
updateMemoMessage.Visibility = &visibility
// Find disable public memos system setting.
disablePublicMemosSystemSetting, err := s.Store.GetSystemSetting(ctx, &store.FindSystemSetting{
disablePublicMemosSystemSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
Name: SystemSettingDisablePublicMemosName.String(),
})
if err != nil {
Expand Down Expand Up @@ -905,7 +905,7 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
}

func (s *APIV1Service) getMemoDisplayWithUpdatedTsSettingValue(ctx context.Context) (bool, error) {
memoDisplayWithUpdatedTsSetting, err := s.Store.GetSystemSetting(ctx, &store.FindSystemSetting{
memoDisplayWithUpdatedTsSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
Name: SystemSettingMemoDisplayWithUpdatedTsName.String(),
})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions api/v1/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (s *APIV1Service) UploadResource(c echo.Context) error {
}

// This is the backend default max upload size limit.
maxUploadSetting := s.Store.GetSystemSettingValueWithDefault(ctx, SystemSettingMaxUploadSizeMiBName.String(), "32")
maxUploadSetting := s.Store.GetWorkspaceSettingWithDefaultValue(ctx, SystemSettingMaxUploadSizeMiBName.String(), "32")
var settingMaxUploadSizeBytes int
if settingMaxUploadSizeMiB, err := strconv.Atoi(maxUploadSetting); err == nil {
settingMaxUploadSizeBytes = settingMaxUploadSizeMiB * MebiByte
Expand Down Expand Up @@ -390,7 +390,7 @@ func convertResourceFromStore(resource *store.Resource) *Resource {
// 2. *LocalStorage*: `create.InternalPath`.
// 3. Others( external service): `create.ExternalLink`.
func SaveResourceBlob(ctx context.Context, s *store.Store, create *store.Resource, r io.Reader) error {
systemSettingStorageServiceID, err := s.GetSystemSetting(ctx, &store.FindSystemSetting{Name: SystemSettingStorageServiceIDName.String()})
systemSettingStorageServiceID, err := s.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{Name: SystemSettingStorageServiceIDName.String()})
if err != nil {
return errors.Wrap(err, "Failed to find SystemSettingStorageServiceIDName")
}
Expand All @@ -413,7 +413,7 @@ func SaveResourceBlob(ctx context.Context, s *store.Store, create *store.Resourc
return nil
} else if storageServiceID == LocalStorage {
// `LocalStorage` means save blob into local disk
systemSettingLocalStoragePath, err := s.GetSystemSetting(ctx, &store.FindSystemSetting{Name: SystemSettingLocalStoragePathName.String()})
systemSettingLocalStoragePath, err := s.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{Name: SystemSettingLocalStoragePathName.String()})
if err != nil {
return errors.Wrap(err, "Failed to find SystemSettingLocalStoragePathName")
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (s *APIV1Service) DeleteStorage(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("storageId"))).SetInternal(err)
}

systemSetting, err := s.Store.GetSystemSetting(ctx, &store.FindSystemSetting{Name: SystemSettingStorageServiceIDName.String()})
systemSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{Name: SystemSettingStorageServiceIDName.String()})
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find storage").SetInternal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s *APIV1Service) GetSystemStatus(c echo.Context) error {
systemStatus.Host = &User{ID: hostUser.ID}
}

systemSettingList, err := s.Store.ListSystemSettings(ctx, &store.FindSystemSetting{})
systemSettingList, err := s.Store.ListWorkspaceSettings(ctx, &store.FindWorkspaceSetting{})
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting list").SetInternal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions api/v1/system_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s *APIV1Service) GetSystemSettingList(c echo.Context) error {
return echo.NewHTTPError(http.StatusUnauthorized, "Unauthorized")
}

list, err := s.Store.ListSystemSettings(ctx, &store.FindSystemSetting{})
list, err := s.Store.ListWorkspaceSettings(ctx, &store.FindWorkspaceSetting{})
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting list").SetInternal(err)
}
Expand Down Expand Up @@ -174,7 +174,7 @@ func (s *APIV1Service) CreateSystemSetting(c echo.Context) error {
}
}

systemSetting, err := s.Store.UpsertSystemSetting(ctx, &store.SystemSetting{
systemSetting, err := s.Store.UpsertWorkspaceSetting(ctx, &store.WorkspaceSetting{
Name: systemSettingUpsert.Name.String(),
Value: systemSettingUpsert.Value,
Description: systemSettingUpsert.Description,
Expand Down Expand Up @@ -289,7 +289,7 @@ func (upsert UpsertSystemSettingRequest) Validate() error {
return nil
}

func convertSystemSettingFromStore(systemSetting *store.SystemSetting) *SystemSetting {
func convertSystemSettingFromStore(systemSetting *store.WorkspaceSetting) *SystemSetting {
return &SystemSetting{
Name: SystemSettingName(systemSetting.Name),
Value: systemSetting.Value,
Expand Down
110 changes: 110 additions & 0 deletions api/v2/apidocs.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,101 @@ consumes:
produces:
- application/json
paths:
/api/v2/auth/signin:
post:
summary: SignIn signs in the user with the given username and password.
operationId: AuthService_SignIn
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v2SignInResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: username
in: query
required: false
type: string
- name: password
in: query
required: false
type: string
tags:
- AuthService
/api/v2/auth/signin/sso:
post:
summary: SignInWithSSO signs in the user with the given SSO code.
operationId: AuthService_SignInWithSSO
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v2SignInWithSSOResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: idpId
in: query
required: false
type: integer
format: int32
- name: code
in: query
required: false
type: string
- name: redirectUri
in: query
required: false
type: string
tags:
- AuthService
/api/v2/auth/signout:
post:
summary: SignOut signs out the user.
operationId: AuthService_SignOut
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v2SignOutResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
tags:
- AuthService
/api/v2/auth/signup:
post:
summary: SignUp signs up the user with the given username and password.
operationId: AuthService_SignUp
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v2SignUpResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: username
in: query
required: false
type: string
- name: password
in: query
required: false
type: string
tags:
- AuthService
/api/v2/auth/status:
post:
summary: GetAuthStatus returns the current auth status of the user.
operationId: AuthService_GetAuthStatus
responses:
"200":
Expand Down Expand Up @@ -1922,6 +2015,23 @@ definitions:
type: object
v2SetMemoResourcesResponse:
type: object
v2SignInResponse:
type: object
properties:
user:
$ref: '#/definitions/v2User'
v2SignInWithSSOResponse:
type: object
properties:
user:
$ref: '#/definitions/v2User'
v2SignOutResponse:
type: object
v2SignUpResponse:
type: object
properties:
user:
$ref: '#/definitions/v2User'
v2StrikethroughNode:
type: object
properties:
Expand Down
4 changes: 2 additions & 2 deletions api/v2/memo_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ func (s *APIV2Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
}

func (s *APIV2Service) getMemoDisplayWithUpdatedTsSettingValue(ctx context.Context) (bool, error) {
memoDisplayWithUpdatedTsSetting, err := s.Store.GetSystemSetting(ctx, &store.FindSystemSetting{
memoDisplayWithUpdatedTsSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
Name: apiv1.SystemSettingMemoDisplayWithUpdatedTsName.String(),
})
if err != nil {
Expand All @@ -684,7 +684,7 @@ func (s *APIV2Service) getMemoDisplayWithUpdatedTsSettingValue(ctx context.Conte
}

func (s *APIV2Service) getDisablePublicMemosSystemSettingValue(ctx context.Context) (bool, error) {
disablePublicMemosSystemSetting, err := s.Store.GetSystemSetting(ctx, &store.FindSystemSetting{
disablePublicMemosSystemSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
Name: apiv1.SystemSettingDisablePublicMemosName.String(),
})
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions api/v2/workspace_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,31 @@ func (s *APIV2Service) UpdateWorkspaceProfile(ctx context.Context, request *apiv
// Update system settings.
for _, field := range request.UpdateMask.Paths {
if field == "allow_registration" {
_, err := s.Store.UpsertSystemSetting(ctx, &store.SystemSetting{
_, err := s.Store.UpsertWorkspaceSetting(ctx, &store.WorkspaceSetting{
Name: "allow-signup",
Value: strconv.FormatBool(request.WorkspaceProfile.AllowRegistration),
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to update allow_registration system setting: %v", err)
}
} else if field == "disable_password_login" {
_, err := s.Store.UpsertSystemSetting(ctx, &store.SystemSetting{
_, err := s.Store.UpsertWorkspaceSetting(ctx, &store.WorkspaceSetting{
Name: "disable-password-login",
Value: strconv.FormatBool(request.WorkspaceProfile.DisablePasswordLogin),
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to update disable_password_login system setting: %v", err)
}
} else if field == "additional_script" {
_, err := s.Store.UpsertSystemSetting(ctx, &store.SystemSetting{
_, err := s.Store.UpsertWorkspaceSetting(ctx, &store.WorkspaceSetting{
Name: "additional-script",
Value: request.WorkspaceProfile.AdditionalScript,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to update additional_script system setting: %v", err)
}
} else if field == "additional_style" {
_, err := s.Store.UpsertSystemSetting(ctx, &store.SystemSetting{
_, err := s.Store.UpsertWorkspaceSetting(ctx, &store.WorkspaceSetting{
Name: "additional-style",
Value: request.WorkspaceProfile.AdditionalStyle,
})
Expand Down
2 changes: 1 addition & 1 deletion internal/jobs/presign_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func signExternalLinks(ctx context.Context, dataStore *store.Store) error {
// Returns error only in case of internal problems (ie: database or configuration issues).
// May return nil client and nil error.
func findObjectStorage(ctx context.Context, dataStore *store.Store) (*s3.Client, error) {
systemSettingStorageServiceID, err := dataStore.GetSystemSetting(ctx, &store.FindSystemSetting{Name: apiv1.SystemSettingStorageServiceIDName.String()})
systemSettingStorageServiceID, err := dataStore.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{Name: apiv1.SystemSettingStorageServiceIDName.String()})
if err != nil {
return nil, errors.Wrap(err, "Failed to find SystemSettingStorageServiceIDName")
}
Expand Down
49 changes: 49 additions & 0 deletions proto/api/v2/auth_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,62 @@ import "google/api/annotations.proto";
option go_package = "gen/api/v2";

service AuthService {
// GetAuthStatus returns the current auth status of the user.
rpc GetAuthStatus(GetAuthStatusRequest) returns (GetAuthStatusResponse) {
option (google.api.http) = {post: "/api/v2/auth/status"};
}
// SignIn signs in the user with the given username and password.
rpc SignIn(SignInRequest) returns (SignInResponse) {
option (google.api.http) = {post: "/api/v2/auth/signin"};
}
// SignInWithSSO signs in the user with the given SSO code.
rpc SignInWithSSO(SignInWithSSORequest) returns (SignInWithSSOResponse) {
option (google.api.http) = {post: "/api/v2/auth/signin/sso"};
}
// SignUp signs up the user with the given username and password.
rpc SignUp(SignUpRequest) returns (SignUpResponse) {
option (google.api.http) = {post: "/api/v2/auth/signup"};
}
// SignOut signs out the user.
rpc SignOut(SignOutRequest) returns (SignOutResponse) {
option (google.api.http) = {post: "/api/v2/auth/signout"};
}
}

message GetAuthStatusRequest {}

message GetAuthStatusResponse {
User user = 1;
}

message SignInRequest {
string username = 1;
string password = 2;
}

message SignInResponse {
User user = 1;
}

message SignInWithSSORequest {
int32 idp_id = 1;
string code = 2;
string redirect_uri = 3;
}

message SignInWithSSOResponse {
User user = 1;
}

message SignUpRequest {
string username = 1;
string password = 2;
}

message SignUpResponse {
User user = 1;
}

message SignOutRequest {}

message SignOutResponse {}
Loading

0 comments on commit de8db63

Please sign in to comment.