chore: update workspace service

This commit is contained in:
Steven
2024-03-21 21:39:34 +08:00
parent 1d83c68cb5
commit 18d16abdb5
16 changed files with 121 additions and 89 deletions

View File

@@ -1857,9 +1857,10 @@ GetActivity returns the activity with the given id.
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| owner | string | | No |
| version | string | | No |
| mode | string | mode is the instance mode (e.g. "prod", "dev" or "demo"). | No |
| allowRegistration | boolean | allow_registration is whether the registration is allowed. | No |
| disablePasswordLogin | boolean | allow_password_login is whether the password login is allowed. | No |
| disallowSignup | boolean | disallow_signup is whether the signup is disallowed. | No |
| disablePasswordLogin | boolean | disable_password_login is whether the password login is disabled. | No |
| additionalScript | string | additional_script is the additional script. | No |
| additionalStyle | string | additional_style is the additional style. | No |

View File

@@ -2346,18 +2346,23 @@ definitions:
v2WorkspaceProfile:
type: object
properties:
owner:
type: string
title: |-
The name of intance owner.
Format: "users/{id}"
version:
type: string
title: version is the current version of instance
mode:
type: string
description: mode is the instance mode (e.g. "prod", "dev" or "demo").
allowRegistration:
disallowSignup:
type: boolean
description: allow_registration is whether the registration is allowed.
description: disallow_signup is whether the signup is disallowed.
disablePasswordLogin:
type: boolean
description: allow_password_login is whether the password login is allowed.
description: disable_password_login is whether the password login is disabled.
additionalScript:
type: string
description: additional_script is the additional script.

View File

@@ -3,15 +3,56 @@ package v2
import (
"context"
"github.com/pkg/errors"
apiv2pb "github.com/usememos/memos/proto/gen/api/v2"
"github.com/usememos/memos/store"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (s *APIV2Service) GetWorkspaceProfile(_ context.Context, _ *apiv2pb.GetWorkspaceProfileRequest) (*apiv2pb.GetWorkspaceProfileResponse, error) {
var owner *apiv2pb.User = nil
func (s *APIV2Service) GetWorkspaceProfile(ctx context.Context, _ *apiv2pb.GetWorkspaceProfileRequest) (*apiv2pb.GetWorkspaceProfileResponse, error) {
workspaceProfile := &apiv2pb.WorkspaceProfile{
Version: s.Profile.Version,
Mode: s.Profile.Mode,
}
owner, err := s.GetInstanceOwner(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get instance owner: %v", err)
}
if owner != nil {
workspaceProfile.Owner = owner.Name
}
generalSetting, err := s.Store.GetWorkspaceGeneralSetting(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get workspace general setting: %v", err)
}
workspaceProfile.DisallowSignup = generalSetting.DisallowSignup
workspaceProfile.DisablePasswordLogin = generalSetting.DisallowPasswordLogin
workspaceProfile.AdditionalStyle = generalSetting.AdditionalStyle
workspaceProfile.AdditionalScript = generalSetting.AdditionalScript
return &apiv2pb.GetWorkspaceProfileResponse{
WorkspaceProfile: workspaceProfile,
}, nil
}
func (s *APIV2Service) GetInstanceOwner(ctx context.Context) (*apiv2pb.User, error) {
if owner != nil {
return owner, nil
}
hostUserType := store.RoleHost
user, err := s.Store.GetUser(ctx, &store.FindUser{
Role: &hostUserType,
})
if err != nil {
return nil, errors.Wrapf(err, "failed to find owner")
}
if user == nil {
return nil, errors.New("owner not found")
}
owner = convertUserFromStore(user)
return owner, nil
}