mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-06-22 14:59:12 -04:00
Merge pull request #59 from owncloud/fix-entity-indexing
Refactor indexing of new entities into own function
This commit is contained in:
6
changelog/unreleased/fix-indexing.md
Normal file
6
changelog/unreleased/fix-indexing.md
Normal file
@@ -0,0 +1,6 @@
|
||||
Change: Fix index update on create/update
|
||||
|
||||
We fixed a bug in creating/updating accounts and groups, that caused new entities not to show up in list queries.
|
||||
|
||||
https://github.com/owncloud/ocis-accounts/issues/57
|
||||
https://github.com/owncloud/ocis-accounts/pull/59
|
||||
@@ -41,23 +41,28 @@ func (s Service) indexAccounts(path string) (err error) {
|
||||
return
|
||||
}
|
||||
for _, file := range list {
|
||||
a := &proto.BleveAccount{
|
||||
BleveType: "account",
|
||||
}
|
||||
if err = s.loadAccount(file.Name(), &a.Account); err != nil {
|
||||
s.log.Error().Err(err).Str("account", file.Name()).Msg("could not load account")
|
||||
continue
|
||||
}
|
||||
s.log.Debug().Interface("account", a).Msg("found account")
|
||||
if err = s.index.Index(a.Id, a); err != nil {
|
||||
s.log.Error().Err(err).Interface("account", a).Msg("could not index account")
|
||||
continue
|
||||
}
|
||||
_ = s.indexAccount(file.Name())
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s Service) indexAccount(id string) error {
|
||||
a := &proto.BleveAccount{
|
||||
BleveType: "account",
|
||||
}
|
||||
if err := s.loadAccount(id, &a.Account); err != nil {
|
||||
s.log.Error().Err(err).Str("account", id).Msg("could not load account")
|
||||
return err
|
||||
}
|
||||
s.log.Debug().Interface("account", a).Msg("found account")
|
||||
if err := s.index.Index(a.Id, a); err != nil {
|
||||
s.log.Error().Err(err).Interface("account", a).Msg("could not index account")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// an auth request is currently hardcoded and has to match this regex
|
||||
// login eq \"teddy\" and password eq \"F&1!b90t111!\"
|
||||
var authQuery = regexp.MustCompile(`^login eq '(.*)' and password eq '(.*)'$`) // TODO how is ' escaped in the password?
|
||||
@@ -272,7 +277,6 @@ func (s Service) CreateAccount(c context.Context, in *proto.CreateAccountRequest
|
||||
if id, err = cleanupID(in.Account.Id); err != nil {
|
||||
return merrors.InternalServerError(s.id, "could not clean up account id: %v", err.Error())
|
||||
}
|
||||
path := filepath.Join(s.Config.Server.AccountsDataPath, "accounts", id)
|
||||
|
||||
if in.Account.PasswordProfile != nil && in.Account.PasswordProfile.Password != "" {
|
||||
// encrypt password
|
||||
@@ -290,8 +294,7 @@ func (s Service) CreateAccount(c context.Context, in *proto.CreateAccountRequest
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.index.Index(id, in.Account); err != nil {
|
||||
s.log.Error().Err(err).Str("id", id).Str("path", path).Interface("account", loggableAccount(in.Account)).Msg("could not index new account")
|
||||
if err = s.indexAccount(in.Account.Id); err != nil {
|
||||
return merrors.InternalServerError(s.id, "could not index new account: %v", err.Error())
|
||||
}
|
||||
|
||||
@@ -373,7 +376,7 @@ func (s Service) UpdateAccount(c context.Context, in *proto.UpdateAccountRequest
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.index.Index(id, out); err != nil {
|
||||
if err = s.indexAccount(id); err != nil {
|
||||
s.log.Error().Err(err).Str("id", id).Str("path", path).Interface("account", loggableAccount(out)).Msg("could not index new account")
|
||||
return merrors.InternalServerError(s.id, "could not index updated account: %v", err.Error())
|
||||
}
|
||||
|
||||
@@ -29,23 +29,28 @@ func (s Service) indexGroups(path string) (err error) {
|
||||
return
|
||||
}
|
||||
for _, file := range list {
|
||||
g := &proto.BleveGroup{
|
||||
BleveType: "group",
|
||||
}
|
||||
if err = s.loadGroup(file.Name(), &g.Group); err != nil {
|
||||
s.log.Error().Err(err).Str("group", file.Name()).Msg("could not load group")
|
||||
continue
|
||||
}
|
||||
s.log.Debug().Interface("group", g).Msg("found group")
|
||||
if err = s.index.Index(g.Id, g); err != nil {
|
||||
s.log.Error().Err(err).Interface("group", g).Msg("could not index group")
|
||||
continue
|
||||
}
|
||||
_ = s.indexGroup(file.Name())
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s Service) indexGroup(id string) error {
|
||||
g := &proto.BleveGroup{
|
||||
BleveType: "group",
|
||||
}
|
||||
if err := s.loadGroup(id, &g.Group); err != nil {
|
||||
s.log.Error().Err(err).Str("group", id).Msg("could not load group")
|
||||
return err
|
||||
}
|
||||
s.log.Debug().Interface("group", g).Msg("found group")
|
||||
if err := s.index.Index(g.Id, g); err != nil {
|
||||
s.log.Error().Err(err).Interface("group", g).Msg("could not index group")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s Service) loadGroup(id string, g *proto.Group) (err error) {
|
||||
path := filepath.Join(s.Config.Server.AccountsDataPath, "groups", id)
|
||||
|
||||
@@ -205,7 +210,6 @@ func (s Service) CreateGroup(c context.Context, in *proto.CreateGroupRequest, ou
|
||||
if id, err = cleanupID(in.Group.Id); err != nil {
|
||||
return merrors.InternalServerError(s.id, "could not clean up account id: %v", err.Error())
|
||||
}
|
||||
path := filepath.Join(s.Config.Server.AccountsDataPath, "groups", id)
|
||||
|
||||
// extract member id
|
||||
s.deflateMembers(in.Group)
|
||||
@@ -215,8 +219,7 @@ func (s Service) CreateGroup(c context.Context, in *proto.CreateGroupRequest, ou
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.index.Index(id, in.Group); err != nil {
|
||||
s.log.Error().Err(err).Str("id", id).Str("path", path).Interface("group", in.Group).Msg("could not index new group")
|
||||
if err = s.indexGroup(id); err != nil {
|
||||
return merrors.InternalServerError(s.id, "could not index new group: %v", err.Error())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user