oficina / mapa Public

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

Plain git — no account needed to clone.

Download

Download this file

1package mapa
2
3import (
4 "context"
5 "errors"
6
7 "gorm.io/gorm"
8)
9
10// MayRead is Mapa's read rule, the decision S2 answers (§8), and the
11// seam slice 1 item 6 wires to the suite contract: a team page is
12// readable by every admitted member; a private page by its owner, and
13// nobody else. The person is checked before any revision (doctrine
14// §6.6).
15//
16// **Ownership survives removal** (gate 9, under doctrine gate 5's
17// reading, until Paul rules on doctrine §14): a private page's owner may
18// read it whether or not they are still on the admission list. In the
19// lone shape that means: off MAPA_OWNERS, a person cannot sign in to
20// Mapa, but S2 asked about them by name still answers for their own
21// pages. Mapa deletes nothing of theirs.
22func (store *Store) MayRead(ctx context.Context, address string,
23 pageID int64, admitted func(string) bool) (bool, error) {
24 var page Page
25 err := store.database.WithContext(ctx).Where("id = ? AND gone = ?",
26 pageID, false).First(&page).Error
27 if errors.Is(err, gorm.ErrRecordNotFound) {
28 return false, nil
29 }
30 if err != nil {
31 return false, err
32 }
33 if page.Rung == RungTeam {
34 return admitted(address), nil
35 }
36 viewer, err := store.Viewer(ctx, address, nil)
37 if err != nil {
38 return false, err
39 }
40 return viewer.MemberID != 0 && viewer.MemberID == page.OwnerID, nil
41}
42