37 lines
1.3 KiB
Go
37 lines
1.3 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"pageswiki/internal/calendar"
|
|
)
|
|
|
|
// NewCalendarRepository selects the explicit index backend. Calendar files
|
|
// remain canonical; this does not enable native application bootstrap or HA.
|
|
func (s *Store) NewCalendarRepository(ctx context.Context) (*calendar.Repository, error) {
|
|
if s.DocumentRoot == "" {
|
|
return nil, ErrDocumentStoreRequired
|
|
}
|
|
root := filepath.Join(s.DocumentRoot, "calendars")
|
|
var r *calendar.Repository
|
|
var err error
|
|
if s.sqlBackend == storePostgreSQL {
|
|
r, err = calendar.NewPostgreSQL(ctx, root, s.DB)
|
|
} else {
|
|
r, err = calendar.New(root, s.DB)
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
r.PublicAllowed = func(domain string) bool {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
defer cancel()
|
|
var allowed bool
|
|
err := s.DB.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM locality_publication_policies p JOIN domains d ON d.uuid=p.domain_uuid AND d.enabled=1 JOIN campuses campus ON campus.uuid=d.campus_uuid AND campus.enabled=1 JOIN config c ON c.domain_uuid=p.domain_uuid AND c.key='authorization_mode' AND c.value='enforcing' WHERE p.domain_uuid=`+s.sqlParam(1)+` AND p.node_kind='domain' AND p.node_uuid=p.domain_uuid AND p.policy='public')`, domain).Scan(&allowed)
|
|
return err == nil && allowed
|
|
}
|
|
return r, nil
|
|
}
|