Files
opencloud/services/groupware/pkg/groupware/groupware_api_account.go
Pascal Bleser 62cace14fe docs(groupware): OpenAPI improvements
* refactor some pkg/jmap and groupware methods to make more sense from
   an API point-of-view

 * add path parameter documentation, but automate it by injecting their
   definition into the OpenAPI YAML tree that is extracted from the
   source code using go-swagger as it is too cumbersome, repetitive and
   error-prine to document them in the source code; wrote a TypeScript
   file apidoc-process.ts to do so

 * add generating an offline HTML file for the OpenAPI documentation
   using redocly, and injecting a favicon into the resulting HTML; wrote
   a TypeScript file apidoc-postprocess-html.ts to do so
2025-12-09 09:15:37 +01:00

127 lines
3.3 KiB
Go

package groupware
import (
"net/http"
"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.
// swagger:response GetAccountResponse200
type SwaggerGetAccountResponse struct {
// in: body
Body struct {
*jmap.SessionAccount
}
}
// swagger:route GET /groupware/accounts/{account} account account
// Get attributes of a given account.
//
// responses:
//
// 200: GetAccountResponse200
// 400: ErrorResponse400
// 404: ErrorResponse404
// 500: ErrorResponse500
func (g *Groupware) GetAccount(w http.ResponseWriter, r *http.Request) {
g.respond(w, r, func(req Request) Response {
account, err := req.GetAccountForMail()
if err != nil {
return errorResponse(err)
}
return response(account, req.session.State)
})
}
// When the request succeeds.
// swagger:response GetAccountsResponse200
type SwaggerGetAccountsResponse struct {
// in: body
Body map[string]jmap.SessionAccount
}
// swagger:route GET /groupware/accounts account accounts
// Get the list of all of the user's accounts.
//
// responses:
//
// 200: GetAccountsResponse200
// 400: ErrorResponse400
// 404: ErrorResponse404
// 500: ErrorResponse500
func (g *Groupware) GetAccounts(w http.ResponseWriter, r *http.Request) {
g.respond(w, r, func(req Request) Response {
return response(req.session.Accounts, req.session.State)
})
}
type AccountBootstrapResponse struct {
// The API version.
Version string `json:"version"`
// A list of capabilities of this API version.
Capabilities []string `json:"capabilities"`
// API limits.
Limits IndexLimits `json:"limits"`
// Accounts that are available to the user.
//
// The key of the mapis the identifier.
Accounts map[string]IndexAccount `json:"accounts"`
// Primary accounts for usage types.
PrimaryAccounts IndexPrimaryAccounts `json:"primaryAccounts"`
// Mailboxes.
Mailboxes map[string][]jmap.Mailbox `json:"mailboxes"`
}
// When the request suceeds.
// swagger:response GetAccountBootstrapResponse200
type SwaggerAccountBootstrapResponse struct {
// in: body
Body struct {
*AccountBootstrapResponse
}
}
// swagger:route GET /groupware/accounts/{account}/bootstrap account accountbootstrap
// Get account bootstrapping.
//
// responses:
//
// 200: GetAccountBootstrapResponse200
// 400: ErrorResponse400
// 404: ErrorResponse404
// 500: ErrorResponse500
func (g *Groupware) GetAccountBootstrap(w http.ResponseWriter, r *http.Request) {
g.respond(w, r, func(req Request) Response {
mailAccountId, err := req.GetAccountIdForMail()
if err != nil {
return errorResponse(err)
}
logger := log.From(req.logger.With().Str(logAccountId, mailAccountId))
accountIds := structs.Keys(req.session.Accounts)
resp, sessionState, jerr := g.jmap.GetIdentitiesAndMailboxes(mailAccountId, accountIds, req.session, req.ctx, logger)
if jerr != nil {
return req.errorResponseFromJmap(jerr)
}
return response(AccountBootstrapResponse{
Version: Version,
Capabilities: Capabilities,
Limits: buildIndexLimits(req.session),
Accounts: buildIndexAccount(req.session, resp.Identities),
PrimaryAccounts: buildIndexPrimaryAccounts(req.session),
Mailboxes: map[string][]jmap.Mailbox{
mailAccountId: resp.Mailboxes,
},
}, sessionState)
})
}