|
|
|
|
@@ -102,7 +102,7 @@ func (b *DBBackend) initSchema(ctx context.Context) error {
|
|
|
|
|
)`,
|
|
|
|
|
`CREATE TABLE IF NOT EXISTS calendar_objects (
|
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
|
calendar_id INTEGER REFERENCES calendars(id) ON DELETE CASCADE,
|
|
|
|
|
calendar_id INTEGER NOT NULL REFERENCES calendars(id) ON DELETE CASCADE,
|
|
|
|
|
path TEXT NOT NULL,
|
|
|
|
|
data TEXT NOT NULL,
|
|
|
|
|
etag TEXT NOT NULL,
|
|
|
|
|
@@ -110,20 +110,20 @@ func (b *DBBackend) initSchema(ctx context.Context) error {
|
|
|
|
|
)`,
|
|
|
|
|
`CREATE TABLE IF NOT EXISTS addressbooks (
|
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
|
owner_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
|
|
|
|
|
owner_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
|
|
|
path TEXT UNIQUE NOT NULL,
|
|
|
|
|
name TEXT,
|
|
|
|
|
description TEXT
|
|
|
|
|
)`,
|
|
|
|
|
`CREATE TABLE IF NOT EXISTS addressbook_access (
|
|
|
|
|
addressbook_id INTEGER REFERENCES addressbooks(id) ON DELETE CASCADE,
|
|
|
|
|
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
|
|
|
|
|
addressbook_id INTEGER NOT NULL REFERENCES addressbooks(id) ON DELETE CASCADE,
|
|
|
|
|
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
|
|
|
mode TEXT NOT NULL,
|
|
|
|
|
PRIMARY KEY (addressbook_id, user_id)
|
|
|
|
|
)`,
|
|
|
|
|
`CREATE TABLE IF NOT EXISTS addressbook_objects (
|
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
|
addressbook_id INTEGER REFERENCES addressbooks(id) ON DELETE CASCADE,
|
|
|
|
|
addressbook_id INTEGER NOT NULL REFERENCES addressbooks(id) ON DELETE CASCADE,
|
|
|
|
|
path TEXT NOT NULL,
|
|
|
|
|
data TEXT NOT NULL,
|
|
|
|
|
etag TEXT NOT NULL,
|
|
|
|
|
@@ -258,6 +258,7 @@ func (b *DBBackend) syncConfig(ctx context.Context, cfg *config.Config) error {
|
|
|
|
|
for _, a := range c.Access {
|
|
|
|
|
if a.ICS != "" {
|
|
|
|
|
pubPath := prefix + fmt.Sprintf("/public/%s/%s.ics", c.Owner, c.ID)
|
|
|
|
|
log.Printf("pp: %s", pubPath)
|
|
|
|
|
b.publicAccess[pubPath] = publicInfo{
|
|
|
|
|
InternalPath: path,
|
|
|
|
|
Mode: a.ICS,
|
|
|
|
|
@@ -768,14 +769,14 @@ func (b *DBBackend) listAggregateObjects(ctx context.Context, aggPath string, ag
|
|
|
|
|
username, _ := b.getUsername(ctx)
|
|
|
|
|
|
|
|
|
|
for _, sourceID := range agg.Sources {
|
|
|
|
|
sourcePath := b.prefix + fmt.Sprintf("/%s/calendars/%s/", agg.Owner, sourceID)
|
|
|
|
|
|
|
|
|
|
var calID int
|
|
|
|
|
var ownerName string
|
|
|
|
|
var sourcePath string
|
|
|
|
|
err := b.pool.QueryRow(ctx, `
|
|
|
|
|
SELECT c.id, u.name FROM calendars c
|
|
|
|
|
SELECT c.id, u.name, c.path FROM calendars c
|
|
|
|
|
JOIN users u ON c.owner_id = u.id
|
|
|
|
|
WHERE c.path = $1`, sourcePath).Scan(&calID, &ownerName)
|
|
|
|
|
WHERE c.name = $1`, sourceID).Scan(&calID, &ownerName, &sourcePath)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
@@ -800,7 +801,7 @@ func (b *DBBackend) listAggregateObjects(ctx context.Context, aggPath string, ag
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, obj := range objs {
|
|
|
|
|
// Prepend source name so Diane knows this is a "[calendar]" event
|
|
|
|
|
// Prepend source name so user knows this is a "[calendar]" event
|
|
|
|
|
for _, child := range obj.Data.Children {
|
|
|
|
|
if child.Name == "VEVENT" || child.Name == "VTODO" {
|
|
|
|
|
descr := child.Props.Get("DESCRIPTION")
|
|
|
|
|
@@ -831,7 +832,7 @@ func (b *DBBackend) GetCalendarObject(ctx context.Context, p string, req *caldav
|
|
|
|
|
fileName := path.Base(p)
|
|
|
|
|
|
|
|
|
|
// Step 1: Check if this is a request for a virtual item in an aggregate
|
|
|
|
|
if agg, ok := b.aggregates[dirPath]; ok {
|
|
|
|
|
if _, ok := b.aggregates[dirPath]; ok {
|
|
|
|
|
|
|
|
|
|
hasAccess := slices.Contains(b.userAggs[username], dirPath)
|
|
|
|
|
if !hasAccess {
|
|
|
|
|
@@ -846,10 +847,10 @@ func (b *DBBackend) GetCalendarObject(ctx context.Context, p string, req *caldav
|
|
|
|
|
sourceID := parts[0]
|
|
|
|
|
realFileName := parts[1]
|
|
|
|
|
|
|
|
|
|
sourcePath := b.prefix + fmt.Sprintf("/%s/calendars/%s/", agg.Owner, sourceID)
|
|
|
|
|
var calID int
|
|
|
|
|
var ownerName string
|
|
|
|
|
err := b.pool.QueryRow(ctx, "SELECT c.id, u.name FROM calendars c JOIN users u ON c.owner_id = u.id WHERE c.path = $1", sourcePath).Scan(&calID, &ownerName)
|
|
|
|
|
var sourcePath string
|
|
|
|
|
err := b.pool.QueryRow(ctx, "SELECT c.id, u.name, c.path FROM calendars c JOIN users u ON c.owner_id = u.id WHERE c.name = $1", sourceID).Scan(&calID, &ownerName, &sourcePath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, webdav.NewHTTPError(http.StatusNotFound, errors.New("source calendar not found"))
|
|
|
|
|
}
|
|
|
|
|
|