Use LoadAccounts in accounts handler

This commit is contained in:
Benedikt Kulmann
2020-10-24 06:37:29 +02:00
parent 70b47484f5
commit fe0e4303a0
2 changed files with 23 additions and 5 deletions

View File

@@ -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)

View File

@@ -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