// Copyright (C) 2019 Marius Schellenberger package core type Permission int const ( Invalid Permission = iota Public Internal Private ) func ParsePermString(p string) Permission { switch p { case "1": return Public case "2": return Internal case "3": return Private } return Invalid } func ReadPerm(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 WritePerm(username, section string, p *Page) bool { if section != WikiSection && section != username { return false } switch p.Perm { case Public, Internal: if p.Owner == WikiSection { return username != "" } return username == p.Owner case Private: return username == p.Owner } return false }