Commit 8e11826d authored by Steven's avatar Steven

chore: update workspace setting service

parent e6d0c00c
...@@ -185,15 +185,22 @@ func (s *APIV1Service) UploadResource(c echo.Context) error { ...@@ -185,15 +185,22 @@ func (s *APIV1Service) UploadResource(c echo.Context) error {
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session") return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
} }
// This is the backend default max upload size limit. maxUploadSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{Name: SystemSettingMaxUploadSizeMiBName.String()})
maxUploadSetting := s.Store.GetWorkspaceSettingWithDefaultValue(ctx, SystemSettingMaxUploadSizeMiBName.String(), "32") if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to get max upload size").SetInternal(err)
}
var settingMaxUploadSizeBytes int var settingMaxUploadSizeBytes int
if settingMaxUploadSizeMiB, err := strconv.Atoi(maxUploadSetting); err == nil { if maxUploadSetting != nil {
if settingMaxUploadSizeMiB, err := strconv.Atoi(maxUploadSetting.Value); err == nil {
settingMaxUploadSizeBytes = settingMaxUploadSizeMiB * MebiByte settingMaxUploadSizeBytes = settingMaxUploadSizeMiB * MebiByte
} else { } else {
log.Warn("Failed to parse max upload size", zap.Error(err)) log.Warn("Failed to parse max upload size", zap.Error(err))
settingMaxUploadSizeBytes = 0 settingMaxUploadSizeBytes = 0
} }
} else {
// Default to 32 MiB.
settingMaxUploadSizeBytes = 32 * MebiByte
}
file, err := c.FormFile("file") file, err := c.FormFile("file")
if err != nil { if err != nil {
......
...@@ -4,6 +4,7 @@ import "strings" ...@@ -4,6 +4,7 @@ import "strings"
var authenticationAllowlistMethods = map[string]bool{ var authenticationAllowlistMethods = map[string]bool{
"/memos.api.v2.WorkspaceService/GetWorkspaceProfile": true, "/memos.api.v2.WorkspaceService/GetWorkspaceProfile": true,
"/memos.api.v2.WorkspaceService/GetWorkspaceSetting": true,
"/memos.api.v2.AuthService/GetAuthStatus": true, "/memos.api.v2.AuthService/GetAuthStatus": true,
"/memos.api.v2.AuthService/SignIn": true, "/memos.api.v2.AuthService/SignIn": true,
"/memos.api.v2.AuthService/SignInWithSSO": true, "/memos.api.v2.AuthService/SignInWithSSO": true,
......
...@@ -12,6 +12,7 @@ tags: ...@@ -12,6 +12,7 @@ tags:
- name: TagService - name: TagService
- name: WebhookService - name: WebhookService
- name: WorkspaceService - name: WorkspaceService
- name: WorkspaceSettingService
consumes: consumes:
- application/json - application/json
produces: produces:
...@@ -1115,27 +1116,65 @@ paths: ...@@ -1115,27 +1116,65 @@ paths:
$ref: '#/definitions/googlerpcStatus' $ref: '#/definitions/googlerpcStatus'
tags: tags:
- WorkspaceService - WorkspaceService
/api/v2/workspace/{name}:
get:
summary: GetWorkspaceSetting returns the setting by name.
operationId: WorkspaceSettingService_GetWorkspaceSetting
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v2GetWorkspaceSettingResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: |-
The resource name of the workspace setting.
Format: settings/{setting}
in: path
required: true
type: string
pattern: settings/[^/]+
tags:
- WorkspaceSettingService
/api/v2/workspace/{setting.name}:
patch: patch:
summary: UpdateWorkspaceProfile updates the workspace profile. summary: SetWorkspaceSetting updates the setting.
operationId: WorkspaceService_UpdateWorkspaceProfile operationId: WorkspaceSettingService_SetWorkspaceSetting
responses: responses:
"200": "200":
description: A successful response. description: A successful response.
schema: schema:
$ref: '#/definitions/v2UpdateWorkspaceProfileResponse' $ref: '#/definitions/v2SetWorkspaceSettingResponse'
default: default:
description: An unexpected error response. description: An unexpected error response.
schema: schema:
$ref: '#/definitions/googlerpcStatus' $ref: '#/definitions/googlerpcStatus'
parameters: parameters:
- name: workspaceProfile - name: setting.name
description: System info is the updated data. description: |-
name is the name of the setting.
Format: settings/{setting}
in: path
required: true
type: string
pattern: settings/[^/]+
- name: setting
description: setting is the setting to update.
in: body in: body
required: true required: true
schema: schema:
$ref: '#/definitions/v2WorkspaceProfile' type: object
properties:
generalSetting:
$ref: '#/definitions/apiv2WorkspaceGeneralSetting'
description: general_setting is the general setting of workspace.
title: setting is the setting to update.
tags: tags:
- WorkspaceService - WorkspaceSettingService
/api/v2/{inbox.name}: /api/v2/{inbox.name}:
patch: patch:
summary: UpdateInbox updates an inbox. summary: UpdateInbox updates an inbox.
...@@ -1611,6 +1650,35 @@ definitions: ...@@ -1611,6 +1650,35 @@ definitions:
type: string type: string
url: url:
type: string type: string
apiv2WorkspaceGeneralSetting:
type: object
properties:
instanceUrl:
type: string
description: instance_url is the instance URL.
disallowSignup:
type: boolean
description: disallow_signup is the flag to disallow signup.
disallowPasswordLogin:
type: boolean
description: disallow_password_login is the flag to disallow password login.
additionalScript:
type: string
description: additional_script is the additional script.
additionalStyle:
type: string
description: additional_style is the additional style.
apiv2WorkspaceSetting:
type: object
properties:
name:
type: string
title: |-
name is the name of the setting.
Format: settings/{setting}
generalSetting:
$ref: '#/definitions/apiv2WorkspaceGeneralSetting'
description: general_setting is the general setting of workspace.
googlerpcStatus: googlerpcStatus:
type: object type: object
properties: properties:
...@@ -1784,6 +1852,11 @@ definitions: ...@@ -1784,6 +1852,11 @@ definitions:
properties: properties:
workspaceProfile: workspaceProfile:
$ref: '#/definitions/v2WorkspaceProfile' $ref: '#/definitions/v2WorkspaceProfile'
v2GetWorkspaceSettingResponse:
type: object
properties:
setting:
$ref: '#/definitions/apiv2WorkspaceSetting'
v2Inbox: v2Inbox:
type: object type: object
properties: properties:
...@@ -2024,6 +2097,11 @@ definitions: ...@@ -2024,6 +2097,11 @@ definitions:
type: object type: object
v2SetMemoResourcesResponse: v2SetMemoResourcesResponse:
type: object type: object
v2SetWorkspaceSettingResponse:
type: object
properties:
setting:
$ref: '#/definitions/apiv2WorkspaceSetting'
v2SignInResponse: v2SignInResponse:
type: object type: object
properties: properties:
...@@ -2081,11 +2159,6 @@ definitions: ...@@ -2081,11 +2159,6 @@ definitions:
properties: properties:
webhook: webhook:
$ref: '#/definitions/apiv2Webhook' $ref: '#/definitions/apiv2Webhook'
v2UpdateWorkspaceProfileResponse:
type: object
properties:
workspaceProfile:
$ref: '#/definitions/v2WorkspaceProfile'
v2UpsertMemoReactionResponse: v2UpsertMemoReactionResponse:
type: object type: object
properties: properties:
...@@ -2158,13 +2231,19 @@ definitions: ...@@ -2158,13 +2231,19 @@ definitions:
properties: properties:
version: version:
type: string type: string
title: version is the current version of instance
mode: mode:
type: string type: string
description: mode is the instance mode (e.g. "prod", "dev" or "demo").
allowRegistration: allowRegistration:
type: boolean type: boolean
description: allow_registration is whether the registration is allowed.
disablePasswordLogin: disablePasswordLogin:
type: boolean type: boolean
description: allow_password_login is whether the password login is allowed.
additionalScript: additionalScript:
type: string type: string
description: additional_script is the additional script.
additionalStyle: additionalStyle:
type: string type: string
description: additional_style is the additional style.
...@@ -255,7 +255,7 @@ func (s *APIV2Service) buildAccessTokenCookie(ctx context.Context, accessToken s ...@@ -255,7 +255,7 @@ func (s *APIV2Service) buildAccessTokenCookie(ctx context.Context, accessToken s
if err != nil { if err != nil {
return "", errors.Wrap(err, "failed to get workspace setting") return "", errors.Wrap(err, "failed to get workspace setting")
} }
if workspaceGeneralSetting.InstanceUrl != "" && strings.HasPrefix(workspaceGeneralSetting.InstanceUrl, "https://") { if strings.HasPrefix(workspaceGeneralSetting.InstanceUrl, "https://") {
attrs = append(attrs, "SameSite=None") attrs = append(attrs, "SameSite=None")
attrs = append(attrs, "Secure") attrs = append(attrs, "Secure")
} else { } else {
......
...@@ -248,7 +248,6 @@ func (s *APIV2Service) UpdateMemo(ctx context.Context, request *apiv2pb.UpdateMe ...@@ -248,7 +248,6 @@ func (s *APIV2Service) UpdateMemo(ctx context.Context, request *apiv2pb.UpdateMe
update.Visibility = &visibility update.Visibility = &visibility
} else if path == "row_status" { } else if path == "row_status" {
rowStatus := convertRowStatusToStore(request.Memo.RowStatus) rowStatus := convertRowStatusToStore(request.Memo.RowStatus)
println("rowStatus", rowStatus)
update.RowStatus = &rowStatus update.RowStatus = &rowStatus
} else if path == "created_ts" { } else if path == "created_ts" {
createdTs := request.Memo.CreateTime.AsTime().Unix() createdTs := request.Memo.CreateTime.AsTime().Unix()
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
) )
const ( const (
WorkspaceSettingNamePrefix = "settings/"
UserNamePrefix = "users/" UserNamePrefix = "users/"
InboxNamePrefix = "inboxes/" InboxNamePrefix = "inboxes/"
) )
...@@ -34,6 +35,14 @@ func GetNameParentTokens(name string, tokenPrefixes ...string) ([]string, error) ...@@ -34,6 +35,14 @@ func GetNameParentTokens(name string, tokenPrefixes ...string) ([]string, error)
return tokens, nil return tokens, nil
} }
func ExtractWorkspaceSettingKeyFromName(name string) (string, error) {
tokens, err := GetNameParentTokens(name, WorkspaceSettingNamePrefix)
if err != nil {
return "", err
}
return tokens[0], nil
}
// ExtractUsernameFromName returns the username from a resource name. // ExtractUsernameFromName returns the username from a resource name.
func ExtractUsernameFromName(name string) (string, error) { func ExtractUsernameFromName(name string) (string, error) {
tokens, err := GetNameParentTokens(name, UserNamePrefix) tokens, err := GetNameParentTokens(name, UserNamePrefix)
......
...@@ -22,6 +22,7 @@ import ( ...@@ -22,6 +22,7 @@ import (
type APIV2Service struct { type APIV2Service struct {
apiv2pb.UnimplementedWorkspaceServiceServer apiv2pb.UnimplementedWorkspaceServiceServer
apiv2pb.UnimplementedWorkspaceSettingServiceServer
apiv2pb.UnimplementedAuthServiceServer apiv2pb.UnimplementedAuthServiceServer
apiv2pb.UnimplementedUserServiceServer apiv2pb.UnimplementedUserServiceServer
apiv2pb.UnimplementedMemoServiceServer apiv2pb.UnimplementedMemoServiceServer
...@@ -56,6 +57,7 @@ func NewAPIV2Service(secret string, profile *profile.Profile, store *store.Store ...@@ -56,6 +57,7 @@ func NewAPIV2Service(secret string, profile *profile.Profile, store *store.Store
} }
apiv2pb.RegisterWorkspaceServiceServer(grpcServer, apiv2Service) apiv2pb.RegisterWorkspaceServiceServer(grpcServer, apiv2Service)
apiv2pb.RegisterWorkspaceSettingServiceServer(grpcServer, apiv2Service)
apiv2pb.RegisterAuthServiceServer(grpcServer, apiv2Service) apiv2pb.RegisterAuthServiceServer(grpcServer, apiv2Service)
apiv2pb.RegisterUserServiceServer(grpcServer, apiv2Service) apiv2pb.RegisterUserServiceServer(grpcServer, apiv2Service)
apiv2pb.RegisterMemoServiceServer(grpcServer, apiv2Service) apiv2pb.RegisterMemoServiceServer(grpcServer, apiv2Service)
...@@ -90,6 +92,9 @@ func (s *APIV2Service) RegisterGateway(ctx context.Context, e *echo.Echo) error ...@@ -90,6 +92,9 @@ func (s *APIV2Service) RegisterGateway(ctx context.Context, e *echo.Echo) error
if err := apiv2pb.RegisterWorkspaceServiceHandler(context.Background(), gwMux, conn); err != nil { if err := apiv2pb.RegisterWorkspaceServiceHandler(context.Background(), gwMux, conn); err != nil {
return err return err
} }
if err := apiv2pb.RegisterWorkspaceSettingServiceHandler(context.Background(), gwMux, conn); err != nil {
return err
}
if err := apiv2pb.RegisterAuthServiceHandler(context.Background(), gwMux, conn); err != nil { if err := apiv2pb.RegisterAuthServiceHandler(context.Background(), gwMux, conn); err != nil {
return err return err
} }
......
...@@ -2,109 +2,16 @@ package v2 ...@@ -2,109 +2,16 @@ package v2
import ( import (
"context" "context"
"strconv"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"github.com/pkg/errors"
apiv2pb "github.com/usememos/memos/proto/gen/api/v2" apiv2pb "github.com/usememos/memos/proto/gen/api/v2"
storepb "github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/store"
) )
func (s *APIV2Service) GetWorkspaceProfile(_ context.Context, _ *apiv2pb.GetWorkspaceProfileRequest) (*apiv2pb.GetWorkspaceProfileResponse, error) { func (s *APIV2Service) GetWorkspaceProfile(ctx context.Context, _ *apiv2pb.GetWorkspaceProfileRequest) (*apiv2pb.GetWorkspaceProfileResponse, error) {
workspaceProfile := &apiv2pb.WorkspaceProfile{ workspaceProfile := &apiv2pb.WorkspaceProfile{
Version: s.Profile.Version, Version: s.Profile.Version,
Mode: s.Profile.Mode, Mode: s.Profile.Mode,
} }
response := &apiv2pb.GetWorkspaceProfileResponse{ return &apiv2pb.GetWorkspaceProfileResponse{
WorkspaceProfile: workspaceProfile, WorkspaceProfile: workspaceProfile,
}
return response, nil
}
func (s *APIV2Service) UpdateWorkspaceProfile(ctx context.Context, request *apiv2pb.UpdateWorkspaceProfileRequest) (*apiv2pb.UpdateWorkspaceProfileResponse, error) {
user, err := getCurrentUser(ctx, s.Store)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get current user: %v", err)
}
if user.Role != store.RoleHost {
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
}
if request.UpdateMask == nil || len(request.UpdateMask.Paths) == 0 {
return nil, status.Errorf(codes.InvalidArgument, "update mask is required")
}
// Update system settings.
for _, field := range request.UpdateMask.Paths {
if field == "allow_registration" {
_, 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" {
if s.Profile.Mode == "demo" {
return nil, status.Errorf(codes.PermissionDenied, "disabling password login is not allowed in demo mode")
}
_, 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" {
if s.Profile.Mode == "demo" {
return nil, status.Errorf(codes.PermissionDenied, "additional script is not allowed in demo mode")
}
_, 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" {
if s.Profile.Mode == "demo" {
return nil, status.Errorf(codes.PermissionDenied, "additional style is not allowed in demo mode")
}
_, err := s.Store.UpsertWorkspaceSetting(ctx, &store.WorkspaceSetting{
Name: "additional-style",
Value: request.WorkspaceProfile.AdditionalStyle,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to update additional_style system setting: %v", err)
}
}
}
workspaceProfileMessage, err := s.GetWorkspaceProfile(ctx, &apiv2pb.GetWorkspaceProfileRequest{})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get system info: %v", err)
}
return &apiv2pb.UpdateWorkspaceProfileResponse{
WorkspaceProfile: workspaceProfileMessage.WorkspaceProfile,
}, nil }, nil
} }
func (s *APIV2Service) GetWorkspaceGeneralSetting(ctx context.Context) (*storepb.WorkspaceGeneralSetting, error) {
workspaceSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
Name: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL.String(),
})
if err != nil {
return nil, errors.Wrap(err, "failed to get workspace setting")
}
workspaceGeneralSetting := &storepb.WorkspaceGeneralSetting{}
if workspaceSetting != nil {
if err := proto.Unmarshal([]byte(workspaceSetting.Value), workspaceGeneralSetting); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal workspace setting")
}
}
return workspaceGeneralSetting, nil
}
package v2
import (
"context"
"fmt"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
apiv2pb "github.com/usememos/memos/proto/gen/api/v2"
storepb "github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/store"
)
func (s *APIV2Service) GetWorkspaceSetting(ctx context.Context, request *apiv2pb.GetWorkspaceSettingRequest) (*apiv2pb.GetWorkspaceSettingResponse, error) {
settingKeyString, err := ExtractWorkspaceSettingKeyFromName(request.Name)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid workspace setting name: %v", err)
}
settingKey := storepb.WorkspaceSettingKey(storepb.WorkspaceSettingKey_value[settingKeyString])
workspaceSetting, err := s.Store.GetWorkspaceSettingV1(ctx, &store.FindWorkspaceSettingV1{
Key: settingKey,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get workspace setting: %v", err)
}
if workspaceSetting == nil {
return nil, status.Errorf(codes.NotFound, "workspace setting not found")
}
return &apiv2pb.GetWorkspaceSettingResponse{
Setting: convertWorkspaceSettingFromStore(workspaceSetting),
}, nil
}
func (s *APIV2Service) SetWorkspaceSetting(ctx context.Context, request *apiv2pb.SetWorkspaceSettingRequest) (*apiv2pb.SetWorkspaceSettingResponse, error) {
user, err := getCurrentUser(ctx, s.Store)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get current user: %v", err)
}
if user.Role != store.RoleHost {
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
}
if _, err := s.Store.UpsertWorkspaceSettingV1(ctx, convertWorkspaceSettingToStore(request.Setting)); err != nil {
return nil, status.Errorf(codes.Internal, "failed to upsert workspace setting: %v", err)
}
return &apiv2pb.SetWorkspaceSettingResponse{}, nil
}
func (s *APIV2Service) GetWorkspaceGeneralSetting(ctx context.Context) (*storepb.WorkspaceGeneralSetting, error) {
workspaceSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
Name: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL.String(),
})
if err != nil {
return nil, errors.Wrap(err, "failed to get workspace setting")
}
workspaceGeneralSetting := &storepb.WorkspaceGeneralSetting{}
if workspaceSetting != nil {
if err := proto.Unmarshal([]byte(workspaceSetting.Value), workspaceGeneralSetting); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal workspace setting")
}
}
return workspaceGeneralSetting, nil
}
func convertWorkspaceSettingFromStore(setting *storepb.WorkspaceSetting) *apiv2pb.WorkspaceSetting {
return &apiv2pb.WorkspaceSetting{
Name: fmt.Sprintf("%s%s", WorkspaceSettingNamePrefix, setting.Key.String()),
Value: &apiv2pb.WorkspaceSetting_GeneralSetting{
GeneralSetting: convertWorkspaceGeneralSettingFromStore(setting.GetGeneral()),
},
}
}
func convertWorkspaceSettingToStore(setting *apiv2pb.WorkspaceSetting) *storepb.WorkspaceSetting {
settingKeyString, _ := ExtractWorkspaceSettingKeyFromName(setting.Name)
return &storepb.WorkspaceSetting{
Key: storepb.WorkspaceSettingKey(storepb.WorkspaceSettingKey_value[settingKeyString]),
Value: &storepb.WorkspaceSetting_General{
General: convertWorkspaceGeneralSettingToStore(setting.GetGeneralSetting()),
},
}
}
func convertWorkspaceGeneralSettingFromStore(setting *storepb.WorkspaceGeneralSetting) *apiv2pb.WorkspaceGeneralSetting {
if setting == nil {
return nil
}
return &apiv2pb.WorkspaceGeneralSetting{
InstanceUrl: setting.InstanceUrl,
DisallowSignup: setting.DisallowSignup,
DisallowPasswordLogin: setting.DisallowPasswordLogin,
AdditionalScript: setting.AdditionalScript,
AdditionalStyle: setting.AdditionalStyle,
}
}
func convertWorkspaceGeneralSettingToStore(setting *apiv2pb.WorkspaceGeneralSetting) *storepb.WorkspaceGeneralSetting {
if setting == nil {
return nil
}
return &storepb.WorkspaceGeneralSetting{
InstanceUrl: setting.InstanceUrl,
DisallowSignup: setting.DisallowSignup,
DisallowPasswordLogin: setting.DisallowPasswordLogin,
AdditionalScript: setting.AdditionalScript,
AdditionalStyle: setting.AdditionalStyle,
}
}
...@@ -41,6 +41,7 @@ var ( ...@@ -41,6 +41,7 @@ var (
data string data string
driver string driver string
dsn string dsn string
serveFrontend bool
enableMetric bool enableMetric bool
rootCmd = &cobra.Command{ rootCmd = &cobra.Command{
...@@ -117,6 +118,7 @@ func init() { ...@@ -117,6 +118,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&data, "data", "d", "", "data directory") rootCmd.PersistentFlags().StringVarP(&data, "data", "d", "", "data directory")
rootCmd.PersistentFlags().StringVarP(&driver, "driver", "", "", "database driver") rootCmd.PersistentFlags().StringVarP(&driver, "driver", "", "", "database driver")
rootCmd.PersistentFlags().StringVarP(&dsn, "dsn", "", "", "database source name(aka. DSN)") rootCmd.PersistentFlags().StringVarP(&dsn, "dsn", "", "", "database source name(aka. DSN)")
rootCmd.PersistentFlags().BoolVarP(&serveFrontend, "frontend", "", true, "serve frontend files")
rootCmd.PersistentFlags().BoolVarP(&enableMetric, "metric", "", true, "allow metric collection") rootCmd.PersistentFlags().BoolVarP(&enableMetric, "metric", "", true, "allow metric collection")
err := viper.BindPFlag("mode", rootCmd.PersistentFlags().Lookup("mode")) err := viper.BindPFlag("mode", rootCmd.PersistentFlags().Lookup("mode"))
...@@ -143,6 +145,10 @@ func init() { ...@@ -143,6 +145,10 @@ func init() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
err = viper.BindPFlag("frontend", rootCmd.PersistentFlags().Lookup("frontend"))
if err != nil {
panic(err)
}
err = viper.BindPFlag("metric", rootCmd.PersistentFlags().Lookup("metric")) err = viper.BindPFlag("metric", rootCmd.PersistentFlags().Lookup("metric"))
if err != nil { if err != nil {
panic(err) panic(err)
...@@ -152,6 +158,7 @@ func init() { ...@@ -152,6 +158,7 @@ func init() {
viper.SetDefault("driver", "sqlite") viper.SetDefault("driver", "sqlite")
viper.SetDefault("addr", "") viper.SetDefault("addr", "")
viper.SetDefault("port", 8081) viper.SetDefault("port", 8081)
viper.SetDefault("frontend", true)
viper.SetDefault("metric", true) viper.SetDefault("metric", true)
viper.SetEnvPrefix("memos") viper.SetEnvPrefix("memos")
} }
...@@ -165,17 +172,18 @@ func initConfig() { ...@@ -165,17 +172,18 @@ func initConfig() {
return return
} }
println("---") fmt.Printf(`---
println("Server profile") Server profile
println("data:", profile.Data) data: %s
println("dsn:", profile.DSN) dsn: %s
println("addr:", profile.Addr) addr: %s
println("port:", profile.Port) port: %d
println("mode:", profile.Mode) mode: %s
println("driver:", profile.Driver) driver: %s
println("version:", profile.Version) version: %s
println("metric:", profile.Metric) metric: %t
println("---") ---
`, profile.Data, profile.DSN, profile.Addr, profile.Port, profile.Mode, profile.Driver, profile.Version, profile.Metric)
} }
func printGreetings() { func printGreetings() {
...@@ -185,11 +193,12 @@ func printGreetings() { ...@@ -185,11 +193,12 @@ func printGreetings() {
} else { } else {
fmt.Printf("Version %s has been started on address '%s' and port %d\n", profile.Version, profile.Addr, profile.Port) fmt.Printf("Version %s has been started on address '%s' and port %d\n", profile.Version, profile.Addr, profile.Port)
} }
println("---") fmt.Printf(`---
println("See more in:") See more in:
fmt.Printf("👉Website: %s\n", "https://usememos.com") 👉Website: %s
fmt.Printf("👉GitHub: %s\n", "https://github.com/usememos/memos") 👉GitHub: %s
println("---") ---
`, "https://usememos.com", "https://github.com/usememos/memos")
} }
func main() { func main() {
......
...@@ -3,8 +3,6 @@ syntax = "proto3"; ...@@ -3,8 +3,6 @@ syntax = "proto3";
package memos.api.v2; package memos.api.v2;
import "google/api/annotations.proto"; import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/protobuf/field_mask.proto";
option go_package = "gen/api/v2"; option go_package = "gen/api/v2";
...@@ -13,22 +11,20 @@ service WorkspaceService { ...@@ -13,22 +11,20 @@ service WorkspaceService {
rpc GetWorkspaceProfile(GetWorkspaceProfileRequest) returns (GetWorkspaceProfileResponse) { rpc GetWorkspaceProfile(GetWorkspaceProfileRequest) returns (GetWorkspaceProfileResponse) {
option (google.api.http) = {get: "/api/v2/workspace/profile"}; option (google.api.http) = {get: "/api/v2/workspace/profile"};
} }
// UpdateWorkspaceProfile updates the workspace profile.
rpc UpdateWorkspaceProfile(UpdateWorkspaceProfileRequest) returns (UpdateWorkspaceProfileResponse) {
option (google.api.http) = {
patch: "/api/v2/workspace/profile",
body: "workspace_profile"
};
option (google.api.method_signature) = "workspace_profile,update_mask";
}
} }
message WorkspaceProfile { message WorkspaceProfile {
// version is the current version of instance
string version = 1; string version = 1;
// mode is the instance mode (e.g. "prod", "dev" or "demo").
string mode = 2; string mode = 2;
// allow_registration is whether the registration is allowed.
bool allow_registration = 3; bool allow_registration = 3;
// allow_password_login is whether the password login is allowed.
bool disable_password_login = 4; bool disable_password_login = 4;
// additional_script is the additional script.
string additional_script = 5; string additional_script = 5;
// additional_style is the additional style.
string additional_style = 6; string additional_style = 6;
} }
...@@ -37,13 +33,3 @@ message GetWorkspaceProfileRequest {} ...@@ -37,13 +33,3 @@ message GetWorkspaceProfileRequest {}
message GetWorkspaceProfileResponse { message GetWorkspaceProfileResponse {
WorkspaceProfile workspace_profile = 1; WorkspaceProfile workspace_profile = 1;
} }
message UpdateWorkspaceProfileRequest {
// System info is the updated data.
WorkspaceProfile workspace_profile = 1;
google.protobuf.FieldMask update_mask = 2;
}
message UpdateWorkspaceProfileResponse {
WorkspaceProfile workspace_profile = 1;
}
syntax = "proto3";
package memos.api.v2;
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
option go_package = "gen/api/v2";
service WorkspaceSettingService {
// GetWorkspaceSetting returns the setting by name.
rpc GetWorkspaceSetting(GetWorkspaceSettingRequest) returns (GetWorkspaceSettingResponse) {
option (google.api.http) = {get: "/api/v2/workspace/{name=settings/*}"};
option (google.api.method_signature) = "name";
}
// SetWorkspaceSetting updates the setting.
rpc SetWorkspaceSetting(SetWorkspaceSettingRequest) returns (SetWorkspaceSettingResponse) {
option (google.api.http) = {
patch: "/api/v2/workspace/{setting.name=settings/*}",
body: "setting"
};
option (google.api.method_signature) = "setting";
}
}
message GetWorkspaceSettingRequest {
// The resource name of the workspace setting.
// Format: settings/{setting}
string name = 1 [(google.api.field_behavior) = REQUIRED];
}
message GetWorkspaceSettingResponse {
WorkspaceSetting setting = 1;
}
message SetWorkspaceSettingRequest {
// setting is the setting to update.
WorkspaceSetting setting = 1;
}
message SetWorkspaceSettingResponse {
WorkspaceSetting setting = 1;
}
message WorkspaceSetting {
// name is the name of the setting.
// Format: settings/{setting}
string name = 1;
oneof value {
// general_setting is the general setting of workspace.
WorkspaceGeneralSetting general_setting = 2;
}
}
message WorkspaceGeneralSetting {
// instance_url is the instance URL.
string instance_url = 1;
// disallow_signup is the flag to disallow signup.
bool disallow_signup = 2;
// disallow_password_login is the flag to disallow password login.
bool disallow_password_login = 3;
// additional_script is the additional script.
string additional_script = 5;
// additional_style is the additional style.
string additional_style = 6;
}
...@@ -179,12 +179,20 @@ ...@@ -179,12 +179,20 @@
- [api/v2/workspace_service.proto](#api_v2_workspace_service-proto) - [api/v2/workspace_service.proto](#api_v2_workspace_service-proto)
- [GetWorkspaceProfileRequest](#memos-api-v2-GetWorkspaceProfileRequest) - [GetWorkspaceProfileRequest](#memos-api-v2-GetWorkspaceProfileRequest)
- [GetWorkspaceProfileResponse](#memos-api-v2-GetWorkspaceProfileResponse) - [GetWorkspaceProfileResponse](#memos-api-v2-GetWorkspaceProfileResponse)
- [UpdateWorkspaceProfileRequest](#memos-api-v2-UpdateWorkspaceProfileRequest)
- [UpdateWorkspaceProfileResponse](#memos-api-v2-UpdateWorkspaceProfileResponse)
- [WorkspaceProfile](#memos-api-v2-WorkspaceProfile) - [WorkspaceProfile](#memos-api-v2-WorkspaceProfile)
- [WorkspaceService](#memos-api-v2-WorkspaceService) - [WorkspaceService](#memos-api-v2-WorkspaceService)
- [api/v2/workspace_setting_service.proto](#api_v2_workspace_setting_service-proto)
- [GetWorkspaceSettingRequest](#memos-api-v2-GetWorkspaceSettingRequest)
- [GetWorkspaceSettingResponse](#memos-api-v2-GetWorkspaceSettingResponse)
- [SetWorkspaceSettingRequest](#memos-api-v2-SetWorkspaceSettingRequest)
- [SetWorkspaceSettingResponse](#memos-api-v2-SetWorkspaceSettingResponse)
- [WorkspaceGeneralSetting](#memos-api-v2-WorkspaceGeneralSetting)
- [WorkspaceSetting](#memos-api-v2-WorkspaceSetting)
- [WorkspaceSettingService](#memos-api-v2-WorkspaceSettingService)
- [Scalar Value Types](#scalar-value-types) - [Scalar Value Types](#scalar-value-types)
...@@ -2472,72 +2480,162 @@ Used internally for obfuscating the page token. ...@@ -2472,72 +2480,162 @@ Used internally for obfuscating the page token.
<a name="memos-api-v2-UpdateWorkspaceProfileRequest"></a> <a name="memos-api-v2-WorkspaceProfile"></a>
### UpdateWorkspaceProfileRequest ### WorkspaceProfile
| Field | Type | Label | Description | | Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- | | ----- | ---- | ----- | ----------- |
| workspace_profile | [WorkspaceProfile](#memos-api-v2-WorkspaceProfile) | | System info is the updated data. | | version | [string](#string) | | version is the current version of instance |
| update_mask | [google.protobuf.FieldMask](#google-protobuf-FieldMask) | | | | mode | [string](#string) | | mode is the instance mode (e.g. &#34;prod&#34;, &#34;dev&#34; or &#34;demo&#34;). |
| allow_registration | [bool](#bool) | | allow_registration is whether the registration is allowed. |
| disable_password_login | [bool](#bool) | | allow_password_login is whether the password login is allowed. |
| additional_script | [string](#string) | | additional_script is the additional script. |
| additional_style | [string](#string) | | additional_style is the additional style. |
<a name="memos-api-v2-WorkspaceService"></a>
### WorkspaceService
| Method Name | Request Type | Response Type | Description |
| ----------- | ------------ | ------------- | ------------|
| GetWorkspaceProfile | [GetWorkspaceProfileRequest](#memos-api-v2-GetWorkspaceProfileRequest) | [GetWorkspaceProfileResponse](#memos-api-v2-GetWorkspaceProfileResponse) | GetWorkspaceProfile returns the workspace profile. |
<a name="memos-api-v2-UpdateWorkspaceProfileResponse"></a> <a name="api_v2_workspace_setting_service-proto"></a>
<p align="right"><a href="#top">Top</a></p>
## api/v2/workspace_setting_service.proto
### UpdateWorkspaceProfileResponse
<a name="memos-api-v2-GetWorkspaceSettingRequest"></a>
### GetWorkspaceSettingRequest
| Field | Type | Label | Description | | Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- | | ----- | ---- | ----- | ----------- |
| workspace_profile | [WorkspaceProfile](#memos-api-v2-WorkspaceProfile) | | | | name | [string](#string) | | The resource name of the workspace setting. Format: settings/{setting} |
<a name="memos-api-v2-WorkspaceProfile"></a> <a name="memos-api-v2-GetWorkspaceSettingResponse"></a>
### WorkspaceProfile ### GetWorkspaceSettingResponse
| Field | Type | Label | Description | | Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- | | ----- | ---- | ----- | ----------- |
| version | [string](#string) | | | | setting | [WorkspaceSetting](#memos-api-v2-WorkspaceSetting) | | |
| mode | [string](#string) | | |
| allow_registration | [bool](#bool) | | |
| disable_password_login | [bool](#bool) | | |
| additional_script | [string](#string) | | |
| additional_style | [string](#string) | | |
<a name="memos-api-v2-SetWorkspaceSettingRequest"></a>
### SetWorkspaceSettingRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| setting | [WorkspaceSetting](#memos-api-v2-WorkspaceSetting) | | setting is the setting to update. |
<a name="memos-api-v2-WorkspaceService"></a>
### WorkspaceService
<a name="memos-api-v2-SetWorkspaceSettingResponse"></a>
### SetWorkspaceSettingResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| setting | [WorkspaceSetting](#memos-api-v2-WorkspaceSetting) | | |
<a name="memos-api-v2-WorkspaceGeneralSetting"></a>
### WorkspaceGeneralSetting
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| instance_url | [string](#string) | | instance_url is the instance URL. |
| disallow_signup | [bool](#bool) | | disallow_signup is the flag to disallow signup. |
| disallow_password_login | [bool](#bool) | | disallow_password_login is the flag to disallow password login. |
| additional_script | [string](#string) | | additional_script is the additional script. |
| additional_style | [string](#string) | | additional_style is the additional style. |
<a name="memos-api-v2-WorkspaceSetting"></a>
### WorkspaceSetting
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | name is the name of the setting. Format: settings/{setting} |
| general_setting | [WorkspaceGeneralSetting](#memos-api-v2-WorkspaceGeneralSetting) | | general_setting is the general setting of workspace. |
<a name="memos-api-v2-WorkspaceSettingService"></a>
### WorkspaceSettingService
| Method Name | Request Type | Response Type | Description | | Method Name | Request Type | Response Type | Description |
| ----------- | ------------ | ------------- | ------------| | ----------- | ------------ | ------------- | ------------|
| GetWorkspaceProfile | [GetWorkspaceProfileRequest](#memos-api-v2-GetWorkspaceProfileRequest) | [GetWorkspaceProfileResponse](#memos-api-v2-GetWorkspaceProfileResponse) | GetWorkspaceProfile returns the workspace profile. | | GetWorkspaceSetting | [GetWorkspaceSettingRequest](#memos-api-v2-GetWorkspaceSettingRequest) | [GetWorkspaceSettingResponse](#memos-api-v2-GetWorkspaceSettingResponse) | GetWorkspaceSetting returns the setting by name. |
| UpdateWorkspaceProfile | [UpdateWorkspaceProfileRequest](#memos-api-v2-UpdateWorkspaceProfileRequest) | [UpdateWorkspaceProfileResponse](#memos-api-v2-UpdateWorkspaceProfileResponse) | UpdateWorkspaceProfile updates the workspace profile. | | SetWorkspaceSetting | [SetWorkspaceSettingRequest](#memos-api-v2-SetWorkspaceSettingRequest) | [SetWorkspaceSettingResponse](#memos-api-v2-SetWorkspaceSettingResponse) | SetWorkspaceSetting updates the setting. |
......
This diff is collapsed.
This diff is collapsed.
...@@ -49,72 +49,6 @@ func local_request_WorkspaceService_GetWorkspaceProfile_0(ctx context.Context, m ...@@ -49,72 +49,6 @@ func local_request_WorkspaceService_GetWorkspaceProfile_0(ctx context.Context, m
} }
var (
filter_WorkspaceService_UpdateWorkspaceProfile_0 = &utilities.DoubleArray{Encoding: map[string]int{"workspace_profile": 0, "workspaceProfile": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}}
)
func request_WorkspaceService_UpdateWorkspaceProfile_0(ctx context.Context, marshaler runtime.Marshaler, client WorkspaceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq UpdateWorkspaceProfileRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.WorkspaceProfile); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if protoReq.UpdateMask == nil || len(protoReq.UpdateMask.GetPaths()) == 0 {
if fieldMask, err := runtime.FieldMaskFromRequestBody(newReader(), protoReq.WorkspaceProfile); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
} else {
protoReq.UpdateMask = fieldMask
}
}
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_WorkspaceService_UpdateWorkspaceProfile_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.UpdateWorkspaceProfile(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_WorkspaceService_UpdateWorkspaceProfile_0(ctx context.Context, marshaler runtime.Marshaler, server WorkspaceServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq UpdateWorkspaceProfileRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.WorkspaceProfile); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if protoReq.UpdateMask == nil || len(protoReq.UpdateMask.GetPaths()) == 0 {
if fieldMask, err := runtime.FieldMaskFromRequestBody(newReader(), protoReq.WorkspaceProfile); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
} else {
protoReq.UpdateMask = fieldMask
}
}
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_WorkspaceService_UpdateWorkspaceProfile_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.UpdateWorkspaceProfile(ctx, &protoReq)
return msg, metadata, err
}
// RegisterWorkspaceServiceHandlerServer registers the http handlers for service WorkspaceService to "mux". // RegisterWorkspaceServiceHandlerServer registers the http handlers for service WorkspaceService to "mux".
// UnaryRPC :call WorkspaceServiceServer directly. // UnaryRPC :call WorkspaceServiceServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
...@@ -146,31 +80,6 @@ func RegisterWorkspaceServiceHandlerServer(ctx context.Context, mux *runtime.Ser ...@@ -146,31 +80,6 @@ func RegisterWorkspaceServiceHandlerServer(ctx context.Context, mux *runtime.Ser
}) })
mux.Handle("PATCH", pattern_WorkspaceService_UpdateWorkspaceProfile_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v2.WorkspaceService/UpdateWorkspaceProfile", runtime.WithHTTPPathPattern("/api/v2/workspace/profile"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_WorkspaceService_UpdateWorkspaceProfile_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_WorkspaceService_UpdateWorkspaceProfile_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil return nil
} }
...@@ -234,39 +143,13 @@ func RegisterWorkspaceServiceHandlerClient(ctx context.Context, mux *runtime.Ser ...@@ -234,39 +143,13 @@ func RegisterWorkspaceServiceHandlerClient(ctx context.Context, mux *runtime.Ser
}) })
mux.Handle("PATCH", pattern_WorkspaceService_UpdateWorkspaceProfile_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/memos.api.v2.WorkspaceService/UpdateWorkspaceProfile", runtime.WithHTTPPathPattern("/api/v2/workspace/profile"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_WorkspaceService_UpdateWorkspaceProfile_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_WorkspaceService_UpdateWorkspaceProfile_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil return nil
} }
var ( var (
pattern_WorkspaceService_GetWorkspaceProfile_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"api", "v2", "workspace", "profile"}, "")) pattern_WorkspaceService_GetWorkspaceProfile_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"api", "v2", "workspace", "profile"}, ""))
pattern_WorkspaceService_UpdateWorkspaceProfile_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"api", "v2", "workspace", "profile"}, ""))
) )
var ( var (
forward_WorkspaceService_GetWorkspaceProfile_0 = runtime.ForwardResponseMessage forward_WorkspaceService_GetWorkspaceProfile_0 = runtime.ForwardResponseMessage
forward_WorkspaceService_UpdateWorkspaceProfile_0 = runtime.ForwardResponseMessage
) )
...@@ -20,7 +20,6 @@ const _ = grpc.SupportPackageIsVersion7 ...@@ -20,7 +20,6 @@ const _ = grpc.SupportPackageIsVersion7
const ( const (
WorkspaceService_GetWorkspaceProfile_FullMethodName = "/memos.api.v2.WorkspaceService/GetWorkspaceProfile" WorkspaceService_GetWorkspaceProfile_FullMethodName = "/memos.api.v2.WorkspaceService/GetWorkspaceProfile"
WorkspaceService_UpdateWorkspaceProfile_FullMethodName = "/memos.api.v2.WorkspaceService/UpdateWorkspaceProfile"
) )
// WorkspaceServiceClient is the client API for WorkspaceService service. // WorkspaceServiceClient is the client API for WorkspaceService service.
...@@ -29,8 +28,6 @@ const ( ...@@ -29,8 +28,6 @@ const (
type WorkspaceServiceClient interface { type WorkspaceServiceClient interface {
// GetWorkspaceProfile returns the workspace profile. // GetWorkspaceProfile returns the workspace profile.
GetWorkspaceProfile(ctx context.Context, in *GetWorkspaceProfileRequest, opts ...grpc.CallOption) (*GetWorkspaceProfileResponse, error) GetWorkspaceProfile(ctx context.Context, in *GetWorkspaceProfileRequest, opts ...grpc.CallOption) (*GetWorkspaceProfileResponse, error)
// UpdateWorkspaceProfile updates the workspace profile.
UpdateWorkspaceProfile(ctx context.Context, in *UpdateWorkspaceProfileRequest, opts ...grpc.CallOption) (*UpdateWorkspaceProfileResponse, error)
} }
type workspaceServiceClient struct { type workspaceServiceClient struct {
...@@ -50,23 +47,12 @@ func (c *workspaceServiceClient) GetWorkspaceProfile(ctx context.Context, in *Ge ...@@ -50,23 +47,12 @@ func (c *workspaceServiceClient) GetWorkspaceProfile(ctx context.Context, in *Ge
return out, nil return out, nil
} }
func (c *workspaceServiceClient) UpdateWorkspaceProfile(ctx context.Context, in *UpdateWorkspaceProfileRequest, opts ...grpc.CallOption) (*UpdateWorkspaceProfileResponse, error) {
out := new(UpdateWorkspaceProfileResponse)
err := c.cc.Invoke(ctx, WorkspaceService_UpdateWorkspaceProfile_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// WorkspaceServiceServer is the server API for WorkspaceService service. // WorkspaceServiceServer is the server API for WorkspaceService service.
// All implementations must embed UnimplementedWorkspaceServiceServer // All implementations must embed UnimplementedWorkspaceServiceServer
// for forward compatibility // for forward compatibility
type WorkspaceServiceServer interface { type WorkspaceServiceServer interface {
// GetWorkspaceProfile returns the workspace profile. // GetWorkspaceProfile returns the workspace profile.
GetWorkspaceProfile(context.Context, *GetWorkspaceProfileRequest) (*GetWorkspaceProfileResponse, error) GetWorkspaceProfile(context.Context, *GetWorkspaceProfileRequest) (*GetWorkspaceProfileResponse, error)
// UpdateWorkspaceProfile updates the workspace profile.
UpdateWorkspaceProfile(context.Context, *UpdateWorkspaceProfileRequest) (*UpdateWorkspaceProfileResponse, error)
mustEmbedUnimplementedWorkspaceServiceServer() mustEmbedUnimplementedWorkspaceServiceServer()
} }
...@@ -77,9 +63,6 @@ type UnimplementedWorkspaceServiceServer struct { ...@@ -77,9 +63,6 @@ type UnimplementedWorkspaceServiceServer struct {
func (UnimplementedWorkspaceServiceServer) GetWorkspaceProfile(context.Context, *GetWorkspaceProfileRequest) (*GetWorkspaceProfileResponse, error) { func (UnimplementedWorkspaceServiceServer) GetWorkspaceProfile(context.Context, *GetWorkspaceProfileRequest) (*GetWorkspaceProfileResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetWorkspaceProfile not implemented") return nil, status.Errorf(codes.Unimplemented, "method GetWorkspaceProfile not implemented")
} }
func (UnimplementedWorkspaceServiceServer) UpdateWorkspaceProfile(context.Context, *UpdateWorkspaceProfileRequest) (*UpdateWorkspaceProfileResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateWorkspaceProfile not implemented")
}
func (UnimplementedWorkspaceServiceServer) mustEmbedUnimplementedWorkspaceServiceServer() {} func (UnimplementedWorkspaceServiceServer) mustEmbedUnimplementedWorkspaceServiceServer() {}
// UnsafeWorkspaceServiceServer may be embedded to opt out of forward compatibility for this service. // UnsafeWorkspaceServiceServer may be embedded to opt out of forward compatibility for this service.
...@@ -111,24 +94,6 @@ func _WorkspaceService_GetWorkspaceProfile_Handler(srv interface{}, ctx context. ...@@ -111,24 +94,6 @@ func _WorkspaceService_GetWorkspaceProfile_Handler(srv interface{}, ctx context.
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _WorkspaceService_UpdateWorkspaceProfile_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateWorkspaceProfileRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(WorkspaceServiceServer).UpdateWorkspaceProfile(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: WorkspaceService_UpdateWorkspaceProfile_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WorkspaceServiceServer).UpdateWorkspaceProfile(ctx, req.(*UpdateWorkspaceProfileRequest))
}
return interceptor(ctx, in, info, handler)
}
// WorkspaceService_ServiceDesc is the grpc.ServiceDesc for WorkspaceService service. // WorkspaceService_ServiceDesc is the grpc.ServiceDesc for WorkspaceService service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
...@@ -140,10 +105,6 @@ var WorkspaceService_ServiceDesc = grpc.ServiceDesc{ ...@@ -140,10 +105,6 @@ var WorkspaceService_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetWorkspaceProfile", MethodName: "GetWorkspaceProfile",
Handler: _WorkspaceService_GetWorkspaceProfile_Handler, Handler: _WorkspaceService_GetWorkspaceProfile_Handler,
}, },
{
MethodName: "UpdateWorkspaceProfile",
Handler: _WorkspaceService_UpdateWorkspaceProfile_Handler,
},
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},
Metadata: "api/v2/workspace_service.proto", Metadata: "api/v2/workspace_service.proto",
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -6,13 +6,26 @@ option go_package = "gen/store"; ...@@ -6,13 +6,26 @@ option go_package = "gen/store";
enum WorkspaceSettingKey { enum WorkspaceSettingKey {
WORKSPACE_SETTING_KEY_UNSPECIFIED = 0; WORKSPACE_SETTING_KEY_UNSPECIFIED = 0;
// WORKSPACE_SETTING_GENERAL is the key for general settings.
WORKSPACE_SETTING_GENERAL = 1; WORKSPACE_SETTING_GENERAL = 1;
} }
message WorkspaceSetting {
WorkspaceSettingKey key = 1;
oneof value {
WorkspaceGeneralSetting general = 2;
}
}
message WorkspaceGeneralSetting { message WorkspaceGeneralSetting {
// instance_url is the instance URL.
string instance_url = 1; string instance_url = 1;
// disallow_signup is the flag to disallow signup.
bool disallow_signup = 2; bool disallow_signup = 2;
// disallow_password_login is the flag to disallow password login.
bool disallow_password_login = 3; bool disallow_password_login = 3;
// additional_script is the additional script.
string additional_script = 5;
// additional_style is the additional style.
string additional_style = 6;
} }
...@@ -29,7 +29,12 @@ func NewTelegramHandler(store *store.Store) *TelegramHandler { ...@@ -29,7 +29,12 @@ func NewTelegramHandler(store *store.Store) *TelegramHandler {
} }
func (t *TelegramHandler) BotToken(ctx context.Context) string { func (t *TelegramHandler) BotToken(ctx context.Context) string {
return t.store.GetWorkspaceSettingWithDefaultValue(ctx, apiv1.SystemSettingTelegramBotTokenName.String(), "") if setting, err := t.store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
Name: apiv1.SystemSettingTelegramBotTokenName.String(),
}); err == nil && setting != nil {
return setting.Value
}
return ""
} }
const ( const (
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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