Files
tajniak81andClaude Opus 5.5 f1963f1391 Add Confluence import, a Slack app per workspace, and GitHub, Linear and Figma link previews
Link previews: link cards for GitHub issues, pull requests and
repositories, Linear issues and Figma files are read through the
services' APIs and show a status pill (Open, Merged, In Progress…) and a
line of details. Public items need nothing; a workspace's tokens, set by
its admins under Workspace settings → Integrations and checked with each
service before being sealed, reach private ones and Linear.
GET /link-preview takes the workspace; the link card stores kind,
status, state and meta.

Slack: each workspace connects its own Slack app, made from a manifest
the settings page fills in. Docwell posts chosen page and comment events
to a channel (edits at most every 30 minutes per page), previews links
to Docwell pages posted in Slack, and answers /docwell with a search as
the member whose email matches the Slack user, shown only to them. Only
pages every member can open are posted or previewed. Requests from Slack
are signature-checked; the webhook dispatcher gained listeners so Slack
follows the same events.

Confluence: a space's HTML export imports with its page tree (from
index.html, else breadcrumbs), links between pages, pictures and
attachments. Panels become callouts, code macros code blocks with their
language, expand macros toggles, task lists to-dos.

New collection workspace_integrations (schema snapshot regenerated),
OpenAPI and generated Go, TypeScript and Dart types, strings in all five
languages, the user guide, and a rebuilt mobile editor bundle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 20:42:11 +01:00

111 lines
3.3 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-or-later
package directory
import (
"context"
"strings"
"unicode/utf8"
"docwell/server/internal/access"
"docwell/server/internal/apperr"
"docwell/server/internal/convert"
"docwell/server/internal/store/pocketbase"
)
// ---- What chat integrations (Slack) need from the directory ------------------
// ChatPage is a page as a chat app may show it: only pages every member of
// the workspace can open (see OpenToMembers).
type ChatPage struct {
ID string
Workspace string
Title string
Icon string
SpaceName string
URL string
// Excerpt is the start of the page's text, one line.
Excerpt string
}
// OpenToMembers returns the page when everyone in workspace wsID can open
// it: it is not deleted, its space is open (not private, not a journal),
// and neither it nor a page above it is restricted. Anything else is
// reported as not shared, so a chat channel never shows what some members
// of the workspace could not read.
func (s *Service) OpenToMembers(ctx context.Context, wsID, pageID string) (ChatPage, bool) {
if !validID(pageID) {
return ChatPage{}, false
}
p, err := s.getPage(ctx, pageID)
if err != nil || p.Workspace != wsID || p.DeletedAt != "" {
return ChatPage{}, false
}
sp, err := pocketbase.Get[spaceRecord](ctx, s.pb, "spaces", p.Space)
if err != nil || sp.Visibility != "open" || sp.JournalOwner != "" {
return ChatPage{}, false
}
// The chain up to the space root; a cycle or a missing parent stops it.
seen := map[string]bool{}
for cur := p; ; {
if cur.Restricted {
return ChatPage{}, false
}
if cur.Parent == "" || seen[cur.Parent] {
break
}
seen[cur.ID] = true
next, err := s.getPage(ctx, cur.Parent)
if err != nil {
return ChatPage{}, false
}
cur = next
}
out := ChatPage{
ID: p.ID, Workspace: p.Workspace, Title: p.Title, Icon: p.Icon, SpaceName: sp.Name,
URL: strings.TrimRight(s.mailer.WebURL, "/") + "/p/" + p.ID,
}
if doc, err := s.docs.Content(ctx, p.ID); err == nil {
if node, err := convert.Parse(doc); err == nil {
out.Excerpt = chatExcerpt(convert.Markdown(node, convert.Options{}), 240)
}
}
return out, true
}
// chatExcerpt is the start of Markdown as one line of plain-ish text.
func chatExcerpt(md string, n int) string {
var parts []string
for _, line := range strings.Split(md, "\n") {
line = strings.TrimSpace(strings.TrimLeft(strings.TrimSpace(line), "#>*-+ "))
if line != "" && !strings.HasPrefix(line, "```") && !strings.HasPrefix(line, "|") {
parts = append(parts, line)
}
if len(parts) > 6 {
break
}
}
s := strings.Join(strings.Fields(strings.Join(parts, " ")), " ")
if utf8.RuneCountInString(s) <= n {
return s
}
return strings.TrimSpace(string([]rune(s)[:n-1])) + "…"
}
// MemberByEmail is the member of workspace wsID with this email, as a caller
// for work done on their behalf (a search from a chat app).
func (s *Service) MemberByEmail(ctx context.Context, wsID, email string) (access.Caller, error) {
u, err := s.findUserByEmail(ctx, email)
if err != nil {
return access.Caller{}, err
}
if u.Status == "disabled" {
return access.Caller{}, apperr.Forbidden("the account is disabled")
}
c := u.Caller()
if _, err := s.WorkspaceRole(ctx, c, wsID); err != nil {
return access.Caller{}, err
}
return c, nil
}