oficina / slides Public

Clone
git clone https://amadan.net/oficina/slides

Plain git — no account needed to clone.

Download

Download this file

1package slides
2
3import (
4 "context"
5 "errors"
6 "os"
7 "time"
8
9 "amadan.net/oficina/home/connect"
10 "amadan.net/oficina/home/connect/linkstore"
11 "amadan.net/oficina/home/dashboard"
12)
13
14func (a *app) configureDashboard(c *connect.DecodedCredentials) error {
15 team := os.Getenv("OFICINA_DASHBOARD_TEAM")
16 if team == "" {
17 return nil
18 }
19 h, e := dashboard.NewProvider(dashboard.ProviderConfig{DB: a.db.Writer(), Origin: a.cfg.Origin, Issuer: c.Issuer, Directory: c.Directory, Keys: c.Keys, Team: team, Kind: "documents", Resolve: func(ctx context.Context, subject string) (int64, error) {
20 p, e := a.home.Resolve(ctx, subject)
21 if errors.Is(e, linkstore.ErrStorage) {
22 return 0, dashboard.ErrUnavailable
23 }
24 return p.ID, e
25 }, Read: a.dashboardDocuments})
26 if e != nil {
27 return e
28 }
29 a.dashboard = h
30 return nil
31}
32func (a *app) dashboardDocuments(ctx context.Context, id int64, subject string, _ time.Time) (dashboard.Response, error) {
33 var viewer User
34 if e := a.db.G.WithContext(ctx).First(&viewer, id).Error; e != nil {
35 return dashboard.Response{}, e
36 }
37 if a.team != nil {
38 // The roster's standing for the verified subject that asked
39 // (Resolve found a link or a Home-only user for it; identity
40 // only), never anything stored (team_access.go).
41 viewer.team = &teamAccess{Access: a.team.Access(ctx, subject)}
42 }
43 var rows []Deck
44 if e := a.visibleDecks(ctx, viewer).Order("decks.updated_at DESC, decks.id DESC").Limit(dashboard.MaxItems + 1).Find(&rows).Error; e != nil {
45 return dashboard.Response{}, e
46 }
47 // Unknown standing is unavailable, not a short list: the feed is read
48 // on another origin, by a reader who never sees the deck list's
49 // partial notice (teammode-package.md §4, condition 3). Asked after
50 // listing, as the deck list does, because a lease can lapse during it.
51 if a.teamPartial(viewer) {
52 return dashboard.Response{}, dashboard.ErrUnavailable
53 }
54 out := dashboard.Response{Truncated: len(rows) > dashboard.MaxItems}
55 if out.Truncated {
56 rows = rows[:dashboard.MaxItems]
57 }
58 for _, d := range rows {
59 out.Items = append(out.Items, dashboard.Item{ID: d.Sqid, Title: d.Title, URL: a.cfg.Origin + "/d/" + d.Sqid, Updated: d.UpdatedAt})
60 }
61 return out, nil
62}
63