work in progress
This commit is contained in:
parent
38f7c31517
commit
07ff5ccffb
23 changed files with 228 additions and 240 deletions
47
pkg/core/permission.go
Normal file
47
pkg/core/permission.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package core
|
||||
|
||||
type Permission int
|
||||
|
||||
const (
|
||||
Invalid Permission = iota
|
||||
Public
|
||||
Internal
|
||||
Private
|
||||
)
|
||||
|
||||
func ParsePerm(p int) 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 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
|
||||
}
|
||||
20
pkg/core/types.go
Normal file
20
pkg/core/types.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package core
|
||||
|
||||
import "html/template"
|
||||
|
||||
type Page struct {
|
||||
Title string `json:"title"`
|
||||
Markdown string `json:"markdown"`
|
||||
Index template.HTML `json:"index"`
|
||||
Text template.HTML `json:"text"`
|
||||
Created string `json:"created"`
|
||||
Updated string `json:"updated"`
|
||||
Owner string `json:"owner"`
|
||||
Perm Permission `json:"perm"`
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
Title string
|
||||
StoreTitle string
|
||||
Text string
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue