groupware: add /quota for all accounts

This commit is contained in:
Pascal Bleser
2025-10-06 16:14:24 +02:00
parent 8ed33d9d7d
commit 2eaae9f979
3 changed files with 74 additions and 13 deletions
@@ -5,6 +5,7 @@ import (
"github.com/opencloud-eu/opencloud/pkg/jmap"
"github.com/opencloud-eu/opencloud/pkg/log"
"github.com/opencloud-eu/opencloud/pkg/structs"
)
// When the request succeeds.
@@ -14,7 +15,7 @@ type SwaggerGetQuotaResponse200 struct {
Body []jmap.Quota
}
// swagger:route GET /groupware/accounts/{account}/quota quota getquota
// swagger:route GET /groupware/accounts/{account}/quota quota get_quota
// Get quota limits.
//
// responses:
@@ -30,10 +31,57 @@ func (g *Groupware) GetQuota(w http.ResponseWriter, r *http.Request) {
}
logger := log.From(req.logger.With().Str(logAccountId, accountId))
res, sessionState, lang, jerr := g.jmap.GetQuotas(accountId, req.session, req.ctx, logger, req.language())
res, sessionState, lang, jerr := g.jmap.GetQuotas([]string{accountId}, req.session, req.ctx, logger, req.language())
if jerr != nil {
return req.errorResponseFromJmap(jerr)
}
return etagResponse(res.List, sessionState, res.State, lang)
for _, v := range res {
return etagResponse(v.List, sessionState, v.State, lang)
}
return notFoundResponse(sessionState)
})
}
type AccountQuota struct {
Quotas []jmap.Quota `json:"quotas,omitempty"`
State jmap.State `json:"state"`
}
// When the request succeeds.
// swagger:response GetQuotaForAllAccountsResponse200
type SwaggerGetQuotaForAllAccountsResponse200 struct {
// in: body
Body map[string]AccountQuota
}
// swagger:route GET /groupware/accounts/all/quota quota get_quota_for_all_accounts
// Get quota limits for all accounts.
//
// responses:
//
// 200: GetQuotaForAllAccountsResponse200
// 400: ErrorResponse400
// 500: ErrorResponse500
func (g *Groupware) GetQuotaForAllAccounts(w http.ResponseWriter, r *http.Request) {
g.respond(w, r, func(req Request) Response {
accountIds := structs.Keys(req.session.Accounts)
if len(accountIds) < 1 {
return noContentResponse("")
}
logger := log.From(req.logger.With().Array(logAccountId, log.SafeStringArray(accountIds)))
res, sessionState, lang, jerr := g.jmap.GetQuotas(accountIds, req.session, req.ctx, logger, req.language())
if jerr != nil {
return req.errorResponseFromJmap(jerr)
}
result := make(map[string]AccountQuota, len(res))
for accountId, accountQuotas := range res {
result[accountId] = AccountQuota{
State: accountQuotas.State,
Quotas: accountQuotas.List,
}
}
return response(result, sessionState, lang)
})
}
@@ -65,6 +65,7 @@ func (g *Groupware) Route(r chi.Router) {
r.Route("/emails", func(r chi.Router) {
r.Get("/latest/summary", g.GetLatestEmailsSummaryForAllAccounts)
})
r.Get("/quota", g.GetQuotaForAllAccounts)
})
r.Route("/accounts/{accountid}", func(r chi.Router) {
r.Get("/", g.GetAccount)