internal/policy/snippets.go

v1.40.0
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}