refine initialization logic again
Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
@@ -14,10 +14,19 @@ import (
|
|||||||
// ListBundles returns all bundles in the dataPath folder that match the given type.
|
// ListBundles returns all bundles in the dataPath folder that match the given type.
|
||||||
func (s *Store) ListBundles(bundleType settingsmsg.Bundle_Type, bundleIDs []string) ([]*settingsmsg.Bundle, error) {
|
func (s *Store) ListBundles(bundleType settingsmsg.Bundle_Type, bundleIDs []string) ([]*settingsmsg.Bundle, error) {
|
||||||
// TODO: this is needed for initialization - we need to find a better way to fix this
|
// TODO: this is needed for initialization - we need to find a better way to fix this
|
||||||
if s.mdc == nil {
|
if s.mdc == nil && len(bundleIDs) == 1 {
|
||||||
return defaultBundle(bundleType, bundleIDs[0]), nil
|
return defaultBundle(bundleType, bundleIDs[0]), nil
|
||||||
}
|
}
|
||||||
//s.Init()
|
s.Init()
|
||||||
|
|
||||||
|
if len(bundleIDs) == 0 {
|
||||||
|
bIDs, err := s.mdc.ReadDir(nil, bundleFolderLocation)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
bundleIDs = bIDs
|
||||||
|
}
|
||||||
var bundles []*settingsmsg.Bundle
|
var bundles []*settingsmsg.Bundle
|
||||||
for _, id := range bundleIDs {
|
for _, id := range bundleIDs {
|
||||||
b, err := s.mdc.SimpleDownload(nil, bundlePath(id))
|
b, err := s.mdc.SimpleDownload(nil, bundlePath(id))
|
||||||
@@ -53,6 +62,7 @@ func (s *Store) ReadBundle(bundleID string) (*settingsmsg.Bundle, error) {
|
|||||||
|
|
||||||
// ReadSetting tries to find a setting by the given id within the dataPath.
|
// ReadSetting tries to find a setting by the given id within the dataPath.
|
||||||
func (s *Store) ReadSetting(settingID string) (*settingsmsg.Setting, error) {
|
func (s *Store) ReadSetting(settingID string) (*settingsmsg.Setting, error) {
|
||||||
|
fmt.Println("ReadSetting not implemented")
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +98,7 @@ func (s *Store) AddSettingToBundle(bundleID string, setting *settingsmsg.Setting
|
|||||||
|
|
||||||
// RemoveSettingFromBundle removes the setting from the bundle with the given ids.
|
// RemoveSettingFromBundle removes the setting from the bundle with the given ids.
|
||||||
func (s *Store) RemoveSettingFromBundle(bundleID string, settingID string) error {
|
func (s *Store) RemoveSettingFromBundle(bundleID string, settingID string) error {
|
||||||
|
fmt.Println("RemoveSettingFromBundle not implemented")
|
||||||
return errors.New("not implemented")
|
return errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,17 @@ package store
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/cs3org/reva/pkg/storage/utils/metadata"
|
"github.com/cs3org/reva/pkg/storage/utils/metadata"
|
||||||
|
"github.com/gofrs/uuid"
|
||||||
olog "github.com/owncloud/ocis/ocis-pkg/log"
|
olog "github.com/owncloud/ocis/ocis-pkg/log"
|
||||||
|
settingsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/settings/v0"
|
||||||
"github.com/owncloud/ocis/settings/pkg/config"
|
"github.com/owncloud/ocis/settings/pkg/config"
|
||||||
"github.com/owncloud/ocis/settings/pkg/settings"
|
"github.com/owncloud/ocis/settings/pkg/settings"
|
||||||
|
"github.com/owncloud/ocis/settings/pkg/store/defaults"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -116,10 +120,41 @@ func (s *Store) initMetadataClient(mdc MetadataClient) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mdc = mdc
|
for _, p := range defaults.GenerateBundlesDefaultRoles() {
|
||||||
if s.initStore != nil {
|
b, err := json.Marshal(p)
|
||||||
s.initStore(s)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = mdc.SimpleUpload(nil, bundlePath(p.Id), b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, p := range defaults.DefaultRoleAssignments() {
|
||||||
|
accountUUID := p.AccountUuid
|
||||||
|
roleID := p.RoleId
|
||||||
|
err = mdc.MakeDirIfNotExist(nil, accountPath(accountUUID))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ass := &settingsmsg.UserRoleAssignment{
|
||||||
|
Id: uuid.Must(uuid.NewV4()).String(),
|
||||||
|
AccountUuid: accountUUID,
|
||||||
|
RoleId: roleID,
|
||||||
|
}
|
||||||
|
b, err := json.Marshal(ass)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = mdc.SimpleUpload(nil, assignmentPath(accountUUID, ass.Id), b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s.mdc = mdc
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user