groupware: accept both '_' and '*' as the 'default account' placeholder

This commit is contained in:
Pascal Bleser
2025-10-14 11:37:18 +02:00
parent f1972e0e23
commit ecc9e6b34f
2 changed files with 12 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net/http"
"slices"
"strconv"
"strings"
"time"
@@ -40,6 +41,10 @@ type Request struct {
session *jmap.Session
}
func isDefaultAccountid(accountId string) bool {
return slices.Contains(defaultAccountIds, accountId)
}
func (r Request) push(typ string, event any) {
r.g.push(r.user, typ, event)
}
@@ -72,7 +77,7 @@ var (
func (r Request) GetAccountIdWithoutFallback() (string, *Error) {
accountId := chi.URLParam(r.r, UriParamAccountId)
if accountId == "" || accountId == defaultAccountId {
if accountId == "" || isDefaultAccountid(accountId) {
r.logger.Error().Err(errNoPrimaryAccountFallback).Msg("failed to determine the accountId")
return "", apiError(r.errorId(), ErrorNonExistingAccount,
withDetail("Failed to determine the account to use"),
@@ -84,7 +89,7 @@ func (r Request) GetAccountIdWithoutFallback() (string, *Error) {
func (r Request) getAccountId(fallback string, err error) (string, *Error) {
accountId := chi.URLParam(r.r, UriParamAccountId)
if accountId == "" || accountId == defaultAccountId {
if accountId == "" || isDefaultAccountid(accountId) {
accountId = fallback
}
if accountId == "" {

View File

@@ -6,9 +6,11 @@ import (
"github.com/go-chi/chi/v5"
)
const (
defaultAccountId = "_"
var (
defaultAccountIds = []string{"_", "*"}
)
const (
UriParamAccountId = "accountid"
UriParamMailboxId = "mailbox"
UriParamEmailId = "emailid"
@@ -56,6 +58,7 @@ func (g *Groupware) Route(r chi.Router) {
r.Get("/", g.Index)
r.Get("/accounts", g.GetAccounts)
r.Route("/accounts/all", func(r chi.Router) {
r.Get("/", g.GetAccounts)
r.Route("/mailboxes", func(r chi.Router) {
r.Get("/", g.GetMailboxesForAllAccounts) // ?role=
r.Get("/changes", g.GetMailboxChangesForAllAccounts)