internal/policy/snippets.go

32a5f76e5b270097b63a5bba9a43557cf50ad63d
gitbay/internal/policy/snippets.go history · blame · raw

17 lines · 531 bytes

 1package policy
 2
 3import "gitbay.org/gitbay/internal/store"
 4
 5// CanReadSnippet: anyone for public and unlisted, the owner and admins
 6// for private. Anonymous readers have user.ID 0.
 7func CanReadSnippet(user store.User, sn store.Snippet) bool {
 8	if sn.Visibility != "private" {
 9		return true
10	}
11	return user.ID != 0 && (user.ID == sn.OwnerID || user.IsAdmin)
12}
13
14// CanWriteSnippet: the owner and admins.
15func CanWriteSnippet(user store.User, sn store.Snippet) bool {
16	return user.ID != 0 && (user.ID == sn.OwnerID || user.IsAdmin)
17}