mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-28 16:48:30 -05:00
* add endpoints for Mailboxes:
- PATCH mailboxes/{id}
- DELETE mailboxes/{id}
- POST mailboxes
* refactor the pkg/jmap and groupware framework to systematically
return a jmap.State out-of-band of the per-method payloads, since
they are almost always present in JMAP responses, which lead to the
artificial creation of a lot of composed struct types just to also
return the State; on the downside, it adds yet another return
parameter
76 lines
2.5 KiB
Go
76 lines
2.5 KiB
Go
package jmap
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/opencloud-eu/opencloud/pkg/log"
|
|
"github.com/opencloud-eu/opencloud/pkg/structs"
|
|
)
|
|
|
|
type AccountBootstrapResult struct {
|
|
Identities []Identity `json:"identities,omitempty"`
|
|
Quotas []Quota `json:"quotas,omitempty"`
|
|
}
|
|
|
|
func (j *Client) GetBootstrap(accountIds []string, session *Session, ctx context.Context, logger *log.Logger, acceptLanguage string) (map[string]AccountBootstrapResult, SessionState, State, Language, Error) {
|
|
uniqueAccountIds := structs.Uniq(accountIds)
|
|
|
|
logger = j.logger("GetBootstrap", session, logger)
|
|
|
|
calls := make([]Invocation, len(uniqueAccountIds)*2)
|
|
for i, accountId := range uniqueAccountIds {
|
|
calls[i*2+0] = invocation(CommandIdentityGet, IdentityGetCommand{AccountId: accountId}, mcid(accountId, "I"))
|
|
calls[i*2+1] = invocation(CommandQuotaGet, QuotaGetCommand{AccountId: accountId}, mcid(accountId, "Q"))
|
|
}
|
|
|
|
cmd, err := j.request(session, logger, calls...)
|
|
if err != nil {
|
|
return nil, "", "", "", err
|
|
}
|
|
return command(j.api, logger, ctx, session, j.onSessionOutdated, cmd, acceptLanguage, func(body *Response) (map[string]AccountBootstrapResult, State, Error) {
|
|
identityPerAccount := map[string][]Identity{}
|
|
quotaPerAccount := map[string][]Quota{}
|
|
identityStatesPerAccount := map[string]State{}
|
|
quotaStatesPerAccount := map[string]State{}
|
|
for _, accountId := range uniqueAccountIds {
|
|
var identityResponse IdentityGetResponse
|
|
err = retrieveResponseMatchParameters(logger, body, CommandIdentityGet, mcid(accountId, "I"), &identityResponse)
|
|
if err != nil {
|
|
return nil, "", err
|
|
} else {
|
|
identityPerAccount[accountId] = identityResponse.List
|
|
identityStatesPerAccount[accountId] = identityResponse.State
|
|
}
|
|
|
|
var quotaResponse QuotaGetResponse
|
|
err = retrieveResponseMatchParameters(logger, body, CommandQuotaGet, mcid(accountId, "Q"), "aResponse)
|
|
if err != nil {
|
|
return nil, "", err
|
|
} else {
|
|
quotaPerAccount[accountId] = quotaResponse.List
|
|
quotaStatesPerAccount[accountId] = quotaResponse.State
|
|
}
|
|
}
|
|
|
|
result := map[string]AccountBootstrapResult{}
|
|
for accountId, value := range identityPerAccount {
|
|
r, ok := result[accountId]
|
|
if !ok {
|
|
r = AccountBootstrapResult{}
|
|
}
|
|
r.Identities = value
|
|
result[accountId] = r
|
|
}
|
|
for accountId, value := range quotaPerAccount {
|
|
r, ok := result[accountId]
|
|
if !ok {
|
|
r = AccountBootstrapResult{}
|
|
}
|
|
r.Quotas = value
|
|
result[accountId] = r
|
|
}
|
|
|
|
return result, squashStateMaps(identityStatesPerAccount, quotaStatesPerAccount), nil
|
|
})
|
|
}
|