Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
49 lines
1.8 KiB
Go
49 lines
1.8 KiB
Go
package calendar
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
// PersonalLocal excludes shared, public and imported calendars. In particular,
|
|
// a task integration must never load external calendar event contents.
|
|
func (c Calendar) PersonalLocal(actor string) bool {
|
|
return actor != "" && c.Owner == actor && c.Source == nil && !c.Public && len(c.Members) == 0
|
|
}
|
|
|
|
// ReadPersonalLocalIndex permits a bounded metadata projection against the
|
|
// refreshed cache. The callback must not call back into this repository.
|
|
func (r *Repository) ReadPersonalLocalIndex(ctx context.Context, domain, id, actor string, read func(Calendar) error) error {
|
|
c, _, unlock, err := r.lockedWithGuard(ctx, domain, id, actor, func(c Calendar) bool { return c.PersonalLocal(actor) })
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer unlock()
|
|
return read(c)
|
|
}
|
|
|
|
// TaskBlock gets a current event, or creates it if absent and a draft is supplied.
|
|
// Retries NEVER overwrite an event moved/edited in the calendar. Metadata policy
|
|
// is checked under the same lock as snapshot access and the eventual commit.
|
|
func (r *Repository) TaskBlock(ctx context.Context, domain, id, actor, uid string, draft *Event) (Calendar, Event, error) {
|
|
c, dir, unlock, err := r.lockedWithGuard(ctx, domain, id, actor, func(c Calendar) bool { return c.PersonalLocal(actor) })
|
|
if err != nil {
|
|
return Calendar{}, Event{}, err
|
|
}
|
|
defer unlock()
|
|
var data string
|
|
err = r.DB.QueryRowContext(ctx, `SELECT data FROM calendar_event_cache WHERE domain=? AND calendar=? AND uid=?`, domain, id, uid).Scan(&data)
|
|
if err == nil {
|
|
event, e := Parse(data)
|
|
return c, event, e
|
|
}
|
|
if err != sql.ErrNoRows {
|
|
return c, Event{}, err
|
|
}
|
|
if draft == nil {
|
|
return c, Event{}, ErrMissing
|
|
}
|
|
event, err := r.changeLocked(ctx, domain, actor, uid, "*", draft, c, dir)
|
|
return c, event, err
|
|
}
|