diff --git a/accounts/pkg/service/v0/accounts.go b/accounts/pkg/service/v0/accounts.go index bb3dfb4f14..45021bbe8e 100644 --- a/accounts/pkg/service/v0/accounts.go +++ b/accounts/pkg/service/v0/accounts.go @@ -146,6 +146,26 @@ func (s Service) ListAccounts(ctx context.Context, in *proto.ListAccountsRequest return nil } + if in.Query == "" { + err = s.repo.LoadAccounts(ctx, &out.Accounts) + if err != nil { + s.log.Err(err).Msg("failed to load all accounts from storage") + return merrors.InternalServerError(s.id, "failed to load all accounts") + } + for i := range out.Accounts { + a := out.Accounts[i] + + // TODO add groups only if requested + // if in.FieldMask ... + s.expandMemberOf(a) + + if a.PasswordProfile != nil { + a.PasswordProfile.Password = "" + } + } + return nil + } + searchResults, err := s.findAccountsByQuery(ctx, in.Query) out.Accounts = make([]*proto.Account, 0, len(searchResults)) @@ -180,10 +200,6 @@ func (s Service) findAccountsByQuery(ctx context.Context, query string) ([]strin var searchResults []string var err error - if query == "" { - return s.index.FindByPartial(&proto.Account{}, "Mail", "*") - } - // TODO: more explicit queries have to be on top var onPremOrMailQuery = regexp.MustCompile(`^on_premises_sam_account_name eq '(.*)' or mail eq '(.*)'$`) match := onPremOrMailQuery.FindStringSubmatch(query) diff --git a/changelog/unreleased/accounts-index-rebuild.md b/changelog/unreleased/accounts-index-rebuild.md index 4b5d0b9096..bce22a26e0 100644 --- a/changelog/unreleased/accounts-index-rebuild.md +++ b/changelog/unreleased/accounts-index-rebuild.md @@ -2,6 +2,8 @@ Change: Rebuild index command for accounts Tags: accounts -The index for the accounts service can now be rebuilt by running the cli command `./bin/ocis accounts rebuild`. It deletes all configured indices and rebuilds them from the documents found on storage. +The index for the accounts service can now be rebuilt by running the cli command `./bin/ocis accounts rebuild`. +It deletes all configured indices and rebuilds them from the documents found on storage. For this we also introduced +a `LoadAccounts` and `LoadGroups` function on storage for loading all existing documents. https://github.com/owncloud/ocis/pull/748