mostly finished db pages

This commit is contained in:
ston1th 2018-02-11 19:21:31 +01:00
commit 38f7c31517
10 changed files with 278 additions and 125 deletions

View file

@ -0,0 +1,47 @@
package permission
type Permission int
const (
Invalid Permission = iota
Public
Internal
Private
)
func Parse(p int) Permission {
switch p {
case Public:
return Public
case Internal:
return Internal
case Private:
return Private
}
return Invalid
}
func Read(username string, p *Page) bool {
switch p.Perm {
case Public:
return true
case Internal:
return username != ""
case Private:
return username == p.Owner
}
return false
}
func Write(username string, p *Page) bool {
switch p.Perm {
case Public, Internal:
if p.Owner == "" {
return username != ""
}
return username == p.Owner
case Private:
return username == p.Owner
}
return false
}