~bigbes/sr-ht-dolt

ref: 9660c7204a2b9500e56c7bb2ff47316d50d5fc99 sr-ht-dolt/core/models.go -rw-r--r-- 2.2 KiB
9660c720 — Eugene Blikh pages: read forms through FormValues 9 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Package core holds the pure domain model for dolt.sr.ht: value types,
// name/path validation, and the access-control matrix. It performs no I/O and
// imports nothing outside the standard library, so every other package can
// depend on it freely.
package core

// Visibility mirrors the Postgres `visibility` enum.
type Visibility string

const (
	VisibilityPublic   Visibility = "PUBLIC"
	VisibilityUnlisted Visibility = "UNLISTED"
	VisibilityPrivate  Visibility = "PRIVATE"
)

// AccessMode mirrors the Postgres `access_mode` enum: an ACL grant is either
// read-only (browse + clone) or read-write (+ push).
type AccessMode string

const (
	AccessRO AccessMode = "RO"
	AccessRW AccessMode = "RW"
)

// UserType mirrors the Postgres `user_type` enum, itself a mirror of meta's
// user type. SUSPENDED users may read but never write.
type UserType string

const (
	UserTypePending   UserType = "PENDING"
	UserTypeUser      UserType = "USER"
	UserTypeAdmin     UserType = "ADMIN"
	UserTypeSuspended UserType = "SUSPENDED"
)

// Op is an operation whose authorization is decided by Allowed.
type Op int

const (
	// OpBrowse is a read of repository metadata/contents through the web UI.
	OpBrowse Op = iota
	// OpCloneRead is a read over the remotesapi (clone/pull/fetch).
	OpCloneRead
	// OpPush is a write over the remotesapi (push).
	OpPush
	// OpAdmin is an owner-only administrative action (settings, ACLs, delete).
	OpAdmin
)

func (o Op) String() string {
	switch o {
	case OpBrowse:
		return "browse"
	case OpCloneRead:
		return "clone-read"
	case OpPush:
		return "push"
	case OpAdmin:
		return "admin"
	default:
		return "unknown"
	}
}

// Repo is a hosted Dolt database. Path is the absolute on-disk NBS store dir.
type Repo struct {
	ID          int
	Name        string
	Description string
	OwnerID     int
	OwnerName   string
	Path        string
	Visibility  Visibility
}

// Caller is the authenticated principal for a request. A nil *Caller is an
// anonymous request. Suspended is carried explicitly (rather than derived from
// UserType) because the token/cookie resolver decides it, and it gates all
// write operations regardless of ACL.
type Caller struct {
	UserID    int
	Username  string
	UserType  UserType
	Suspended bool
}