From a486571c94de622f1216b3ef0f643484eff9b1df Mon Sep 17 00:00:00 2001 From: Pascal Bleser Date: Tue, 9 Dec 2025 14:33:29 +0100 Subject: [PATCH] groupware: shift some attributes of the Groupware object around, in defaults and config sub-structures --- .../pkg/groupware/groupware_api_calendars.go | 2 +- .../pkg/groupware/groupware_api_contacts.go | 2 +- .../pkg/groupware/groupware_api_emails.go | 26 ++--- .../pkg/groupware/groupware_api_mailbox.go | 4 +- .../pkg/groupware/groupware_framework.go | 95 ++++++++++--------- .../groupware/pkg/groupware/groupware_test.go | 2 +- 6 files changed, 70 insertions(+), 61 deletions(-) diff --git a/services/groupware/pkg/groupware/groupware_api_calendars.go b/services/groupware/pkg/groupware/groupware_api_calendars.go index 755d96c3e6..8524066d26 100644 --- a/services/groupware/pkg/groupware/groupware_api_calendars.go +++ b/services/groupware/pkg/groupware/groupware_api_calendars.go @@ -121,7 +121,7 @@ func (g *Groupware) GetEventsInCalendar(w http.ResponseWriter, r *http.Request) l = l.Uint(QueryParamOffset, offset) } - limit, ok, err := req.parseUIntParam(QueryParamLimit, g.defaultContactLimit) + limit, ok, err := req.parseUIntParam(QueryParamLimit, g.defaults.contactLimit) if err != nil { return errorResponse(single(accountId), err) } diff --git a/services/groupware/pkg/groupware/groupware_api_contacts.go b/services/groupware/pkg/groupware/groupware_api_contacts.go index 71592c8012..9cebd7ed58 100644 --- a/services/groupware/pkg/groupware/groupware_api_contacts.go +++ b/services/groupware/pkg/groupware/groupware_api_contacts.go @@ -121,7 +121,7 @@ func (g *Groupware) GetContactsInAddressbook(w http.ResponseWriter, r *http.Requ l = l.Uint(QueryParamOffset, offset) } - limit, ok, err := req.parseUIntParam(QueryParamLimit, g.defaultContactLimit) + limit, ok, err := req.parseUIntParam(QueryParamLimit, g.defaults.contactLimit) if err != nil { return errorResponse(single(accountId), err) } diff --git a/services/groupware/pkg/groupware/groupware_api_emails.go b/services/groupware/pkg/groupware/groupware_api_emails.go index 5b592fc070..454831f9ff 100644 --- a/services/groupware/pkg/groupware/groupware_api_emails.go +++ b/services/groupware/pkg/groupware/groupware_api_emails.go @@ -79,7 +79,7 @@ func (g *Groupware) GetAllEmailsInMailbox(w http.ResponseWriter, r *http.Request logger := log.From(req.logger.With().Str(HeaderSince, log.SafeString(since)).Str(logAccountId, log.SafeString(accountId))) - changes, sessionState, state, lang, jerr := g.jmap.GetMailboxChanges(accountId, req.session, req.ctx, logger, req.language(), mailboxId, since, true, g.maxBodyValueBytes, maxChanges) + changes, sessionState, state, lang, jerr := g.jmap.GetMailboxChanges(accountId, req.session, req.ctx, logger, req.language(), mailboxId, since, true, g.config.maxBodyValueBytes, maxChanges) if jerr != nil { return req.errorResponseFromJmap(single(accountId), jerr) } @@ -108,7 +108,7 @@ func (g *Groupware) GetAllEmailsInMailbox(w http.ResponseWriter, r *http.Request l = l.Int(QueryParamOffset, offset) } - limit, ok, err := req.parseUIntParam(QueryParamLimit, g.defaultEmailLimit) + limit, ok, err := req.parseUIntParam(QueryParamLimit, g.defaults.emailLimit) if err != nil { return errorResponse(single(accountId), err) } @@ -122,7 +122,7 @@ func (g *Groupware) GetAllEmailsInMailbox(w http.ResponseWriter, r *http.Request fetchBodies := false withThreads := true - emails, sessionState, state, lang, jerr := g.jmap.GetAllEmailsInMailbox(accountId, req.session, req.ctx, logger, req.language(), mailboxId, offset, limit, collapseThreads, fetchBodies, g.maxBodyValueBytes, withThreads) + emails, sessionState, state, lang, jerr := g.jmap.GetAllEmailsInMailbox(accountId, req.session, req.ctx, logger, req.language(), mailboxId, offset, limit, collapseThreads, fetchBodies, g.config.maxBodyValueBytes, withThreads) if jerr != nil { return req.errorResponseFromJmap(single(accountId), jerr) } @@ -209,7 +209,7 @@ func (g *Groupware) GetEmailsById(w http.ResponseWriter, r *http.Request) { if len(ids) == 1 { logger := log.From(l.Str("id", log.SafeString(id))) - emails, _, sessionState, state, lang, jerr := g.jmap.GetEmails(accountId, req.session, req.ctx, logger, req.language(), ids, true, g.maxBodyValueBytes, markAsSeen, true) + emails, _, sessionState, state, lang, jerr := g.jmap.GetEmails(accountId, req.session, req.ctx, logger, req.language(), ids, true, g.config.maxBodyValueBytes, markAsSeen, true) if jerr != nil { return req.errorResponseFromJmap(single(accountId), jerr) } @@ -225,7 +225,7 @@ func (g *Groupware) GetEmailsById(w http.ResponseWriter, r *http.Request) { } else { logger := log.From(l.Array("ids", log.SafeStringArray(ids))) - emails, _, sessionState, state, lang, jerr := g.jmap.GetEmails(accountId, req.session, req.ctx, logger, req.language(), ids, true, g.maxBodyValueBytes, markAsSeen, false) + emails, _, sessionState, state, lang, jerr := g.jmap.GetEmails(accountId, req.session, req.ctx, logger, req.language(), ids, true, g.config.maxBodyValueBytes, markAsSeen, false) if jerr != nil { return req.errorResponseFromJmap(single(accountId), jerr) } @@ -388,7 +388,7 @@ func (g *Groupware) getEmailsSince(w http.ResponseWriter, r *http.Request, since logger := log.From(l) - changes, sessionState, state, lang, jerr := g.jmap.GetEmailsSince(accountId, req.session, req.ctx, logger, req.language(), since, true, g.maxBodyValueBytes, maxChanges) + changes, sessionState, state, lang, jerr := g.jmap.GetEmailsSince(accountId, req.session, req.ctx, logger, req.language(), since, true, g.config.maxBodyValueBytes, maxChanges) if jerr != nil { return req.errorResponseFromJmap(single(accountId), jerr) } @@ -460,7 +460,7 @@ func (g *Groupware) buildFilter(req Request) (bool, jmap.EmailFilterElement, boo l = l.Int(QueryParamOffset, offset) } - limit, ok, err := req.parseUIntParam(QueryParamLimit, g.defaultEmailLimit) + limit, ok, err := req.parseUIntParam(QueryParamLimit, g.defaults.emailLimit) if err != nil { return false, nil, snippets, 0, 0, nil, err } @@ -611,7 +611,7 @@ func (g *Groupware) GetEmails(w http.ResponseWriter, r *http.Request) { fetchBodies := false - resultsByAccount, sessionState, state, lang, jerr := g.jmap.QueryEmailsWithSnippets(single(accountId), filter, req.session, req.ctx, logger, req.language(), offset, limit, fetchBodies, g.maxBodyValueBytes) + resultsByAccount, sessionState, state, lang, jerr := g.jmap.QueryEmailsWithSnippets(single(accountId), filter, req.session, req.ctx, logger, req.language(), offset, limit, fetchBodies, g.config.maxBodyValueBytes) if jerr != nil { return req.errorResponseFromJmap(single(accountId), jerr) } @@ -1364,7 +1364,7 @@ func (g *Groupware) RelatedToEmail(w http.ResponseWriter, r *http.Request) { reqId := req.GetRequestId() getEmailsBefore := time.Now() - emails, _, sessionState, state, lang, jerr := g.jmap.GetEmails(accountId, req.session, req.ctx, logger, req.language(), []string{id}, true, g.maxBodyValueBytes, false, false) + emails, _, sessionState, state, lang, jerr := g.jmap.GetEmails(accountId, req.session, req.ctx, logger, req.language(), []string{id}, true, g.config.maxBodyValueBytes, false, false) getEmailsDuration := time.Since(getEmailsBefore) if jerr != nil { return req.errorResponseFromJmap(single(accountId), jerr) @@ -1389,7 +1389,7 @@ func (g *Groupware) RelatedToEmail(w http.ResponseWriter, r *http.Request) { g.job(logger, RelationTypeSameSender, func(jobId uint64, l *log.Logger) { before := time.Now() - resultsByAccountId, _, _, lang, jerr := g.jmap.QueryEmails(single(accountId), filter, req.session, bgctx, l, req.language(), 0, limit, false, g.maxBodyValueBytes) + resultsByAccountId, _, _, lang, jerr := g.jmap.QueryEmails(single(accountId), filter, req.session, bgctx, l, req.language(), 0, limit, false, g.config.maxBodyValueBytes) if results, ok := resultsByAccountId[accountId]; ok { duration := time.Since(before) if jerr != nil { @@ -1410,7 +1410,7 @@ func (g *Groupware) RelatedToEmail(w http.ResponseWriter, r *http.Request) { g.job(logger, RelationTypeSameThread, func(jobId uint64, l *log.Logger) { before := time.Now() - emails, _, _, _, jerr := g.jmap.EmailsInThread(accountId, email.ThreadId, req.session, bgctx, l, req.language(), false, g.maxBodyValueBytes) + emails, _, _, _, jerr := g.jmap.EmailsInThread(accountId, email.ThreadId, req.session, bgctx, l, req.language(), false, g.config.maxBodyValueBytes) duration := time.Since(before) if jerr != nil { req.observeJmapError(jerr) @@ -1819,7 +1819,7 @@ var sanitizableMediaTypes = []string{ } func (req *Request) sanitizeEmail(source jmap.Email) (jmap.Email, *Error) { - if !req.g.sanitize { + if !req.g.config.sanitize { return source, nil } memory := map[string]int{} @@ -1867,7 +1867,7 @@ func (req *Request) sanitizeEmail(source jmap.Email) (jmap.Email, *Error) { } func (req *Request) sanitizeEmails(source []jmap.Email) ([]jmap.Email, *Error) { - if !req.g.sanitize { + if !req.g.config.sanitize { return source, nil } result := make([]jmap.Email, len(source)) diff --git a/services/groupware/pkg/groupware/groupware_api_mailbox.go b/services/groupware/pkg/groupware/groupware_api_mailbox.go index 2e0ce731d3..f918681b26 100644 --- a/services/groupware/pkg/groupware/groupware_api_mailbox.go +++ b/services/groupware/pkg/groupware/groupware_api_mailbox.go @@ -267,7 +267,7 @@ func (g *Groupware) GetMailboxChanges(w http.ResponseWriter, r *http.Request) { logger := log.From(l) - changes, sessionState, state, lang, jerr := g.jmap.GetMailboxChanges(accountId, req.session, req.ctx, logger, req.language(), mailboxId, sinceState, true, g.maxBodyValueBytes, maxChanges) + changes, sessionState, state, lang, jerr := g.jmap.GetMailboxChanges(accountId, req.session, req.ctx, logger, req.language(), mailboxId, sinceState, true, g.config.maxBodyValueBytes, maxChanges) if jerr != nil { return req.errorResponseFromJmap(single(accountId), jerr) } @@ -320,7 +320,7 @@ func (g *Groupware) GetMailboxChangesForAllAccounts(w http.ResponseWriter, r *ht logger := log.From(l) - changesByAccountId, sessionState, state, lang, jerr := g.jmap.GetMailboxChangesForMultipleAccounts(allAccountIds, req.session, req.ctx, logger, req.language(), sinceStateMap, true, g.maxBodyValueBytes, maxChanges) + changesByAccountId, sessionState, state, lang, jerr := g.jmap.GetMailboxChangesForMultipleAccounts(allAccountIds, req.session, req.ctx, logger, req.language(), sinceStateMap, true, g.config.maxBodyValueBytes, maxChanges) if jerr != nil { return req.errorResponseFromJmap(allAccountIds, jerr) } diff --git a/services/groupware/pkg/groupware/groupware_framework.go b/services/groupware/pkg/groupware/groupware_framework.go index 455b1598bb..aaf5cce3b7 100644 --- a/services/groupware/pkg/groupware/groupware_framework.go +++ b/services/groupware/pkg/groupware/groupware_framework.go @@ -30,29 +30,26 @@ import ( "github.com/opencloud-eu/opencloud/services/groupware/pkg/metrics" ) +// Logging property keys. const ( - logUsername = "username" - logUserId = "user-id" - logSessionState = "session-state" - logAccountId = "account-id" - logBlobAccountId = "blob-account-id" // if the blob accountId is needed as well - logErrorId = "error-id" - logErrorCode = "code" - logErrorStatus = "status" - logErrorSourceHeader = "source-header" - logErrorSourceParameter = "source-parameter" - logErrorSourcePointer = "source-pointer" - logInvalidQueryParameter = "error-query-param" - logInvalidPathParameter = "error-path-param" - logFolderId = "folder-id" - logIdentityId = "identity-id" - logQuery = "query" - logEmailId = "email-id" - logJobDescription = "job" - logJobId = "job-id" - logStreamId = "stream-id" - logPath = "path" - logMethod = "method" + logUsername = "username" + logUserId = "user-id" + logSessionState = "session-state" + logAccountId = "account-id" + logBlobAccountId = "blob-account-id" + logErrorId = "error-id" + logErrorCode = "code" + logErrorStatus = "status" + logErrorSourceHeader = "source-header" + logErrorSourceParameter = "source-parameter" + logErrorSourcePointer = "source-pointer" + logIdentityId = "identity-id" + logEmailId = "email-id" + logJobDescription = "job" + logJobId = "job-id" + logStreamId = "stream-id" + logPath = "path" + logMethod = "method" ) // Minimalistic representation of a user, containing only the attributes that are @@ -80,6 +77,16 @@ type Job struct { job func(uint64, *log.Logger) } +type groupwareConfig struct { + maxBodyValueBytes uint + sanitize bool +} + +type groupwareDefaults struct { + emailLimit uint + contactLimit uint +} + type Groupware struct { mux *chi.Mux metrics *metrics.Metrics @@ -88,12 +95,10 @@ type Groupware struct { // unfortunately, the sse implementation does not provide such a function. // Key: the stream ID, which is the username // Value: the timestamp of the creation of the stream - streams cmap.ConcurrentMap - logger *log.Logger - defaultEmailLimit uint - defaultContactLimit uint - maxBodyValueBytes uint - sanitize bool + streams cmap.ConcurrentMap + logger *log.Logger + defaults groupwareDefaults + config groupwareConfig // Caches successful and failed Sessions by the username. sessionCache sessionCache jmap *jmap.Client @@ -354,21 +359,25 @@ func NewGroupware(config *config.Config, logger *log.Logger, mux *chi.Mux, prome } g := &Groupware{ - mux: mux, - metrics: m, - sseServer: sseServer, - streams: cmap.New(), - logger: logger, - sessionCache: sessionCache, - userProvider: userProvider, - jmap: &jmapClient, - defaultEmailLimit: defaultEmailLimit, - defaultContactLimit: defaultContactLimit, - maxBodyValueBytes: maxBodyValueBytes, - sanitize: sanitize, - eventChannel: eventChannel, - jobsChannel: jobsChannel, - jobCounter: atomic.Uint64{}, + mux: mux, + metrics: m, + sseServer: sseServer, + streams: cmap.New(), + logger: logger, + sessionCache: sessionCache, + userProvider: userProvider, + jmap: &jmapClient, + defaults: groupwareDefaults{ + emailLimit: defaultEmailLimit, + contactLimit: defaultContactLimit, + }, + config: groupwareConfig{ + maxBodyValueBytes: maxBodyValueBytes, + sanitize: sanitize, + }, + eventChannel: eventChannel, + jobsChannel: jobsChannel, + jobCounter: atomic.Uint64{}, } for w := 1; w <= workerPoolSize; w++ { diff --git a/services/groupware/pkg/groupware/groupware_test.go b/services/groupware/pkg/groupware/groupware_test.go index b78ee96b0a..6125e9b664 100644 --- a/services/groupware/pkg/groupware/groupware_test.go +++ b/services/groupware/pkg/groupware/groupware_test.go @@ -34,7 +34,7 @@ func TestSanitizeEmail(t *testing.T) { }, } - g := &Groupware{sanitize: true} + g := &Groupware{config: groupwareConfig{sanitize: true}} req := Request{g: g} safe, err := req.sanitizeEmail(email)