Skip to content

Commit

Permalink
get predefined default profile
Browse files Browse the repository at this point in the history
  • Loading branch information
2403905 committed Dec 17, 2024
1 parent d205228 commit 783ed78
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 35 deletions.
28 changes: 11 additions & 17 deletions services/settings/pkg/service/v0/servicedecorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package svc

import (
"context"
"net/http"
"strings"

settingsmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0"
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
"github.com/owncloud/ocis/v2/services/settings/pkg/config"
"github.com/owncloud/ocis/v2/services/settings/pkg/settings"
"github.com/owncloud/ocis/v2/services/settings/pkg/store/defaults"
merrors "go-micro.dev/v4/errors"
)

var _defaultLanguage = "en"
Expand Down Expand Up @@ -54,9 +52,7 @@ func (s *defaultLanguageDecorator) ListValues(ctx context.Context, req *settings
}
defaultValueList := getDefaultValueList()
for _, v := range res.Values {
if _, ok := defaultValueList[v.GetValue().GetSettingId()]; ok {
delete(defaultValueList, v.GetValue().GetSettingId())
}
delete(defaultValueList, v.GetValue().GetSettingId())
}

// Ensure the default values for profile settings
Expand Down Expand Up @@ -112,15 +108,11 @@ func (s *defaultLanguageDecorator) withDefaultProfileValue(ctx context.Context,

func (s *defaultLanguageDecorator) withDefaultProfileValueList(ctx context.Context,
accountUUID string, requested map[string]*settingsmsg.ValueWithIdentifier) map[string]*settingsmsg.ValueWithIdentifier {
req := &settingssvc.GetBundleRequest{BundleId: defaults.BundleUUIDProfile}
resp := &settingssvc.GetBundleResponse{}
if err := s.GetBundle(ctx, req, resp); err != nil {
if merr, ok := merrors.As(err); ok && merr.Code != http.StatusNotFound {
return requested
}
}

for _, setting := range resp.GetBundle().GetSettings() {
// we use the default profile bundle instead of s.GetBundle(ctx, req, resp)
bundle := defaults.GenerateDefaultProfileBundle()

for _, setting := range bundle.GetSettings() {
if v, ok := requested[setting.GetId()]; ok && v == nil {
if setting.GetId() == defaults.SettingUUIDProfileLanguage {
requested[setting.GetId()] = s.withDefaultLanguageSetting(accountUUID)
Expand All @@ -129,12 +121,12 @@ func (s *defaultLanguageDecorator) withDefaultProfileValueList(ctx context.Conte

newVal := &settingsmsg.ValueWithIdentifier{
Identifier: &settingsmsg.Identifier{
Extension: resp.GetBundle().GetExtension(),
Bundle: resp.GetBundle().GetName(),
Extension: bundle.GetExtension(),
Bundle: bundle.GetName(),
Setting: setting.GetName(),
},
Value: &settingsmsg.Value{
BundleId: resp.GetBundle().GetId(),
BundleId: bundle.GetId(),
SettingId: setting.GetId(),
AccountUuid: accountUUID,
Resource: setting.GetResource(),
Expand Down Expand Up @@ -177,7 +169,9 @@ func multiChoiceCollectionToValue(collection *settingsmsg.MultiChoiceCollection)

func getDefaultValueList() map[string]*settingsmsg.ValueWithIdentifier {
return map[string]*settingsmsg.ValueWithIdentifier{
defaults.SettingUUIDProfileLanguage: nil,
// specific profile settings should be handled individually
defaults.SettingUUIDProfileLanguage: nil,
// all other profile settings that populated from the bundle based on type
defaults.SettingUUIDProfileEventShareCreated: nil,
defaults.SettingUUIDProfileEventShareRemoved: nil,
defaults.SettingUUIDProfileEventShareExpired: nil,
Expand Down
30 changes: 12 additions & 18 deletions services/settings/pkg/store/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func GenerateBundlesDefaultRoles() []*settingsmsg.Bundle {
}
}

// GenerateDefaultProfileBundle return the default profile bundle.
func GenerateDefaultProfileBundle() *settingsmsg.Bundle {
return generateBundleProfileRequest()
}

// ServiceAccountBundle returns the service account bundle
func ServiceAccountBundle() *settingsmsg.Bundle {
return &settingsmsg.Bundle{
Expand Down Expand Up @@ -469,26 +474,27 @@ var sendEmailOptions = settingsmsg.Setting_SingleChoiceValue{
{
Value: &settingsmsg.ListOptionValue{
Option: &settingsmsg.ListOptionValue_StringValue{
StringValue: "daily",
StringValue: "instant",
},
},
DisplayValue: "Daily",
DisplayValue: "Instant",
Default: true,
},
{
Value: &settingsmsg.ListOptionValue{
Option: &settingsmsg.ListOptionValue_StringValue{
StringValue: "weekly",
StringValue: "daily",
},
},
DisplayValue: "Weekly",
DisplayValue: "Daily",
},
{
Value: &settingsmsg.ListOptionValue{
Option: &settingsmsg.ListOptionValue_StringValue{
StringValue: "instant",
StringValue: "weekly",
},
},
DisplayValue: "Instant",
DisplayValue: "Weekly",
},
{
Value: &settingsmsg.ListOptionValue{
Expand All @@ -513,18 +519,6 @@ var optionInAppTrue = settingsmsg.MultiChoiceCollectionOption{
},
},
}
var optionInAppFalseDisabled = settingsmsg.MultiChoiceCollectionOption{
Key: "in-app",
Attribute: "disabled",
DisplayValue: "In-App",
Value: &settingsmsg.MultiChoiceCollectionOptionValue{
Option: &settingsmsg.MultiChoiceCollectionOptionValue_BoolValue{
BoolValue: &settingsmsg.Bool{
Default: false,
},
},
},
}

var optionMailTrue = settingsmsg.MultiChoiceCollectionOption{
Key: "mail",
Expand Down

0 comments on commit 783ed78

Please sign in to comment.