first working version
This commit is contained in:
parent
14e0611f06
commit
85f93bae69
32 changed files with 863 additions and 571 deletions
8
pkg/core/const.go
Normal file
8
pkg/core/const.go
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package core
|
||||
|
||||
const (
|
||||
IndexPage = "Index"
|
||||
WikiSection = "wiki"
|
||||
|
||||
IndexURI = WikiSection + "/" + IndexPage
|
||||
)
|
||||
|
|
@ -21,6 +21,18 @@ func ParsePerm(p int) Permission {
|
|||
return Invalid
|
||||
}
|
||||
|
||||
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:
|
||||
|
|
@ -33,7 +45,14 @@ func ReadPerm(username string, p *Page) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func WritePerm(username string, p *Page) bool {
|
||||
func WritePerm(username, section string, p *Page) bool {
|
||||
if section != WikiSection && section != username {
|
||||
return false
|
||||
}
|
||||
return writePerm(username, p)
|
||||
}
|
||||
|
||||
func writePerm(username string, p *Page) bool {
|
||||
switch p.Perm {
|
||||
case Public, Internal:
|
||||
if p.Owner == "" {
|
||||
|
|
|
|||
|
|
@ -3,21 +3,22 @@ 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"`
|
||||
Title string `json:"title"`
|
||||
StoreTitle string `json:"store_title"`
|
||||
Markdown string `json:"markdown"`
|
||||
PageIndex template.HTML `json:"page_index"`
|
||||
HTML template.HTML `json:"html"`
|
||||
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
|
||||
}
|
||||
type Pages []Page
|
||||
|
||||
func (p Pages) Len() int { return len(p) }
|
||||
func (p Pages) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
||||
func (p Pages) Less(i, j int) bool { return p[i].StoreTitle < p[j].StoreTitle }
|
||||
|
||||
type User struct {
|
||||
Username string
|
||||
|
|
@ -25,3 +26,15 @@ type User struct {
|
|||
Admin bool
|
||||
Locked int
|
||||
}
|
||||
|
||||
type Users []User
|
||||
|
||||
func (u Users) Len() int { return len(u) }
|
||||
func (u Users) Swap(i, j int) { u[i], u[j] = u[j], u[i] }
|
||||
func (u Users) Less(i, j int) bool { return u[i].Username < u[j].Username }
|
||||
|
||||
type Result struct {
|
||||
Title string
|
||||
StoreTitle string
|
||||
Text string
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue