coverage~bigbes/sr-ht-dolt3523280ccore/models.go

Coverage
0.0% 0/6 statements
Δ
+0.0
Blob
2e09925
Uncovered L52-L63
1 // Package core holds the pure domain model for dolt.sr.ht: value types,
2 // name/path validation, and the access-control matrix. It performs no I/O and
3 // imports nothing outside the standard library, so every other package can
4 // depend on it freely.
5 package core
6
7 import "time"
8
9 // Visibility mirrors the Postgres `visibility` enum.
10 type Visibility string
11
12 const (
13 VisibilityPublic Visibility = "PUBLIC"
14 VisibilityUnlisted Visibility = "UNLISTED"
15 VisibilityPrivate Visibility = "PRIVATE"
16 )
17
18 // AccessMode mirrors the Postgres `access_mode` enum: an ACL grant is either
19 // read-only (browse + clone) or read-write (+ push).
20 type AccessMode string
21
22 const (
23 AccessRO AccessMode = "RO"
24 AccessRW AccessMode = "RW"
25 )
26
27 // UserType mirrors the Postgres `user_type` enum, itself a mirror of meta's
28 // user type. SUSPENDED users may read but never write.
29 type UserType string
30
31 const (
32 UserTypePending UserType = "PENDING"
33 UserTypeUser UserType = "USER"
34 UserTypeAdmin UserType = "ADMIN"
35 UserTypeSuspended UserType = "SUSPENDED"
36 )
37
38 // Op is an operation whose authorization is decided by Allowed.
39 type Op int
40
41 const (
42 // OpBrowse is a read of repository metadata/contents through the web UI.
43 OpBrowse Op = iota
44 // OpCloneRead is a read over the remotesapi (clone/pull/fetch).
45 OpCloneRead
46 // OpPush is a write over the remotesapi (push).
47 OpPush
48 // OpAdmin is an owner-only administrative action (settings, ACLs, delete).
49 OpAdmin
50 )
51
52 0 func (o Op) String() string {
53 0 switch o {
54 0 case OpBrowse:
55 0 return "browse"
56 0 case OpCloneRead:
57 0 return "clone-read"
58 0 case OpPush:
59 0 return "push"
60 0 case OpAdmin:
61 0 return "admin"
62 0 default:
63 0 return "unknown"
64 }
65 }
66
67 // Repo is a hosted Dolt database. Path is the absolute on-disk NBS store dir.
68 type Repo struct {
69 ID int
70 Name string
71 Description string
72 OwnerID int
73 OwnerName string
74 Path string
75 Visibility Visibility
76 // Created and Updated are the row's timestamps, in UTC. They are read by
77 // the surfaces that publish a database as a record rather than as a page —
78 // /query is the first — and are the zero time for a Repo built in memory
79 // rather than read from the store.
80 Created time.Time
81 Updated time.Time
82 }
83
84 // Caller is the authenticated principal for a request. A nil *Caller is an
85 // anonymous request. Suspended is carried explicitly (rather than derived from
86 // UserType) because the token/cookie resolver decides it, and it gates all
87 // write operations regardless of ACL.
88 type Caller struct {
89 UserID int
90 Username string
91 UserType UserType
92 Suspended bool
93 }