mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-05 04:37:14 +00:00
chore: tweak workspace setting definition
This commit is contained in:
@ -26,10 +26,6 @@ type Profile struct {
|
||||
Version string
|
||||
// Metric indicate the metric collection is enabled or not.
|
||||
Metric bool
|
||||
// Pubic is the flag whether the instance is public for others.
|
||||
Public bool
|
||||
// InstanceURL is the URL of the instance.
|
||||
InstanceURL string
|
||||
}
|
||||
|
||||
func (p *Profile) IsDev() bool {
|
||||
|
@ -15,9 +15,8 @@ import (
|
||||
|
||||
func (s *APIV1Service) GetWorkspaceProfile(ctx context.Context, _ *v1pb.GetWorkspaceProfileRequest) (*v1pb.WorkspaceProfile, error) {
|
||||
workspaceProfile := &v1pb.WorkspaceProfile{
|
||||
Mode: s.Profile.Mode,
|
||||
Version: s.Profile.Version,
|
||||
EnableSignup: s.Profile.Public,
|
||||
Mode: s.Profile.Mode,
|
||||
Version: s.Profile.Version,
|
||||
}
|
||||
|
||||
// Load subscription plan from license service.
|
||||
@ -32,16 +31,17 @@ func (s *APIV1Service) GetWorkspaceProfile(ctx context.Context, _ *v1pb.GetWorks
|
||||
workspaceProfile.Owner = fmt.Sprintf("%s%d", UserNamePrefix, owner.Id)
|
||||
}
|
||||
|
||||
workspaceSettingGeneral, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
})
|
||||
workspaceGeneralSetting, err := s.Store.GetWorkspaceGeneralSetting(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get workspace setting")
|
||||
return nil, errors.Wrap(err, "failed to get workspace general setting")
|
||||
}
|
||||
generalSetting := workspaceSettingGeneral.GetGeneral()
|
||||
if generalSetting != nil {
|
||||
workspaceProfile.Branding = generalSetting.GetBranding()
|
||||
workspaceProfile.Branding = workspaceGeneralSetting.GetBranding()
|
||||
|
||||
workspaceSecuritySetting, err := s.Store.GetWorkspaceSecuritySetting(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get workspace security setting")
|
||||
}
|
||||
workspaceProfile.EnableSignup = !workspaceSecuritySetting.DisallowUserRegistration
|
||||
|
||||
return workspaceProfile, nil
|
||||
}
|
||||
@ -89,49 +89,29 @@ func (s *APIV1Service) UpdateWorkspaceSetting(ctx context.Context, request *v1pb
|
||||
|
||||
for _, path := range request.UpdateMask.Paths {
|
||||
if path == "branding" {
|
||||
generalSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
})
|
||||
generalSetting, err := s.Store.GetWorkspaceGeneralSetting(ctx)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to get workspace setting: %v", err)
|
||||
}
|
||||
if generalSetting == nil {
|
||||
generalSetting = &storepb.WorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
Value: &storepb.WorkspaceSetting_General{
|
||||
General: &storepb.WorkspaceSetting_GeneralSetting{},
|
||||
},
|
||||
}
|
||||
}
|
||||
generalSetting.GetGeneral().Branding = request.Setting.Branding
|
||||
generalSetting.Branding = request.Setting.Branding
|
||||
if _, err := s.Store.UpsertWorkspaceSetting(ctx, &storepb.WorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
Value: &storepb.WorkspaceSetting_General{
|
||||
General: generalSetting.GetGeneral(),
|
||||
General: generalSetting,
|
||||
},
|
||||
}); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to update workspace setting: %v", err)
|
||||
}
|
||||
} else if path == "custom_style" {
|
||||
generalSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
})
|
||||
generalSetting, err := s.Store.GetWorkspaceGeneralSetting(ctx)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to get workspace setting: %v", err)
|
||||
}
|
||||
if generalSetting == nil {
|
||||
generalSetting = &storepb.WorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
Value: &storepb.WorkspaceSetting_General{
|
||||
General: &storepb.WorkspaceSetting_GeneralSetting{},
|
||||
},
|
||||
}
|
||||
}
|
||||
generalSetting.GetGeneral().CustomStyle = request.Setting.CustomStyle
|
||||
generalSetting.CustomStyle = request.Setting.CustomStyle
|
||||
if _, err := s.Store.UpsertWorkspaceSetting(ctx, &storepb.WorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
Value: &storepb.WorkspaceSetting_General{
|
||||
General: generalSetting.GetGeneral(),
|
||||
General: generalSetting,
|
||||
},
|
||||
}); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to update workspace setting: %v", err)
|
||||
|
@ -118,7 +118,11 @@ func (s *FrontendService) registerRoutes(e *echo.Echo) {
|
||||
}
|
||||
|
||||
func (s *FrontendService) registerFileRoutes(ctx context.Context, e *echo.Echo) {
|
||||
instanceURL := s.Profile.InstanceURL
|
||||
workspaceGeneralSetting, err := s.Store.GetWorkspaceGeneralSetting(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
instanceURL := workspaceGeneralSetting.InstanceUrl
|
||||
if instanceURL == "" {
|
||||
return
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
|
||||
secret := "slash"
|
||||
if profile.Mode == "prod" {
|
||||
var err error
|
||||
secret, err = s.getSecretSessionName(ctx)
|
||||
secret, err = s.getSecretSession(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -119,20 +119,19 @@ func (s *Server) GetEcho() *echo.Echo {
|
||||
return s.e
|
||||
}
|
||||
|
||||
func (s *Server) getSecretSessionName(ctx context.Context) (string, error) {
|
||||
workspaceSettingGeneral, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
})
|
||||
func (s *Server) getSecretSession(ctx context.Context) (string, error) {
|
||||
workspaceGeneralSetting, err := s.Store.GetWorkspaceGeneralSetting(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if workspaceSettingGeneral == nil || workspaceSettingGeneral.GetGeneral() == nil {
|
||||
tempSecret := uuid.New().String()
|
||||
workspaceSettingGeneral, err = s.Store.UpsertWorkspaceSetting(ctx, &storepb.WorkspaceSetting{
|
||||
secretSession := workspaceGeneralSetting.SecretSession
|
||||
if secretSession == "" {
|
||||
secretSession = uuid.New().String()
|
||||
_, err := s.Store.UpsertWorkspaceSetting(ctx, &storepb.WorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
Value: &storepb.WorkspaceSetting_General{
|
||||
General: &storepb.WorkspaceSetting_GeneralSetting{
|
||||
SecretSession: tempSecret,
|
||||
SecretSession: secretSession,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -140,5 +139,5 @@ func (s *Server) getSecretSessionName(ctx context.Context) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return workspaceSettingGeneral.GetGeneral().SecretSession, nil
|
||||
return secretSession, nil
|
||||
}
|
||||
|
@ -37,18 +37,13 @@ func NewLicenseService(profile *profile.Profile, store *store.Store) *LicenseSer
|
||||
}
|
||||
|
||||
func (s *LicenseService) LoadSubscription(ctx context.Context) (*v1pb.Subscription, error) {
|
||||
workspaceSettingGeneral, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
})
|
||||
workspaceGeneralSetting, err := s.Store.GetWorkspaceGeneralSetting(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get workspace setting")
|
||||
return nil, errors.Wrap(err, "failed to get workspace general setting")
|
||||
}
|
||||
|
||||
subscription := getSubscriptionForFreePlan()
|
||||
licenseKey := ""
|
||||
if workspaceSettingGeneral != nil {
|
||||
licenseKey = workspaceSettingGeneral.GetGeneral().LicenseKey
|
||||
}
|
||||
licenseKey := workspaceGeneralSetting.LicenseKey
|
||||
if licenseKey == "" {
|
||||
return subscription, nil
|
||||
}
|
||||
@ -93,25 +88,17 @@ func (s *LicenseService) UpdateSubscription(ctx context.Context, licenseKey stri
|
||||
}
|
||||
|
||||
func (s *LicenseService) UpdateLicenseKey(ctx context.Context, licenseKey string) error {
|
||||
workspaceSettingGeneral, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
})
|
||||
workspaceGeneralSetting, err := s.Store.GetWorkspaceGeneralSetting(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get workspace setting")
|
||||
return errors.Wrap(err, "failed to get workspace general setting")
|
||||
}
|
||||
if workspaceSettingGeneral == nil || workspaceSettingGeneral.GetGeneral() == nil {
|
||||
workspaceSettingGeneral = &storepb.WorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
Value: &storepb.WorkspaceSetting_General{
|
||||
General: &storepb.WorkspaceSetting_GeneralSetting{
|
||||
LicenseKey: licenseKey,
|
||||
},
|
||||
},
|
||||
}
|
||||
} else {
|
||||
workspaceSettingGeneral.GetGeneral().LicenseKey = licenseKey
|
||||
}
|
||||
_, err = s.Store.UpsertWorkspaceSetting(ctx, workspaceSettingGeneral)
|
||||
workspaceGeneralSetting.LicenseKey = licenseKey
|
||||
_, err = s.Store.UpsertWorkspaceSetting(ctx, &storepb.WorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
Value: &storepb.WorkspaceSetting_General{
|
||||
General: workspaceGeneralSetting,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to upsert workspace setting")
|
||||
}
|
||||
|
Reference in New Issue
Block a user