working sections version
This commit is contained in:
parent
16ea95bf09
commit
9424084a36
28 changed files with 367 additions and 251 deletions
|
|
@ -21,7 +21,7 @@ var (
|
|||
errDeleteIndexPage = errors.New("db: index page can not be deleted")
|
||||
)
|
||||
|
||||
func (db *DB) GetAllSections(username string) (sections core.SectionPages) {
|
||||
func (db *DB) GetAllSections(username string, admin bool) (sections core.SectionPages) {
|
||||
m := make(map[string]core.UpdatedPages)
|
||||
db.store.ForEach(func(k string, _ []byte) error {
|
||||
if trim, ok := hasTrimPrefix(k, pagePrefix); ok {
|
||||
|
|
@ -39,6 +39,16 @@ func (db *DB) GetAllSections(username string) (sections core.SectionPages) {
|
|||
}
|
||||
return nil
|
||||
})
|
||||
if admin {
|
||||
secs, err := db.GetSections()
|
||||
if err == nil {
|
||||
for _, s := range secs {
|
||||
if _, ok := m[s.Name]; !ok {
|
||||
m[s.Name] = core.UpdatedPages{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for s, p := range m {
|
||||
sort.Sort(p)
|
||||
l := len(p)
|
||||
|
|
@ -51,7 +61,11 @@ func (db *DB) GetAllSections(username string) (sections core.SectionPages) {
|
|||
return
|
||||
}
|
||||
|
||||
func (db *DB) GetAllSectionPages(section, username string) (pages core.Pages, err error) {
|
||||
func (db *DB) GetAllSectionPages(section, username string, admin bool) (pages core.Pages, err error) {
|
||||
err = db.SectionExists(section)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
db.store.ForEach(func(k string, _ []byte) error {
|
||||
if trim, ok := hasTrimPrefix(k, pagePrefix); ok {
|
||||
if !strings.HasPrefix(trim, section+"/") {
|
||||
|
|
@ -67,7 +81,7 @@ func (db *DB) GetAllSectionPages(section, username string) (pages core.Pages, er
|
|||
}
|
||||
return nil
|
||||
})
|
||||
if len(pages) == 0 {
|
||||
if len(pages) == 0 && !admin {
|
||||
err = errPageNotFound
|
||||
return
|
||||
}
|
||||
|
|
@ -128,6 +142,14 @@ func (db *DB) CreatePage(title, section, markdown, username string, p core.Permi
|
|||
if err != store.ErrKeyNotFound {
|
||||
return
|
||||
}
|
||||
s, err := db.GetSection(section)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if _, ok := core.Contains(username, s.Members); !ok {
|
||||
err = errPermissionDenied
|
||||
return
|
||||
}
|
||||
|
||||
page = &core.Page{
|
||||
Title: title,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue