working sections version

This commit is contained in:
ston1th 2019-03-27 23:08:59 +01:00
commit 9424084a36
28 changed files with 367 additions and 251 deletions

View file

@ -30,6 +30,20 @@ func (db *DB) GetSections() (secs core.Sections, err error) {
return
}
func (db *DB) GetUserSections(username string) (sections map[string]bool, err error) {
sections = make(map[string]bool)
secs, err := db.GetSections()
if err != nil {
return
}
for _, s := range secs {
if _, ok := core.Contains(username, s.Members); ok {
sections[s.Name] = false
}
}
return
}
func (db *DB) GetSection(section string) (s core.Section, err error) {
err = db.store.Get(sectionPrefix+section, &s)
return
@ -68,11 +82,11 @@ func (db *DB) UpdateSection(section string, members []string, user bool) error {
return db.store.Set(sectionPrefix+section, &core.Section{section, user, m})
}
func (db *DB) DeleteSection(section string, user bool) error {
func (db *DB) DeleteSection(section string) error {
if section == core.WikiSection {
return errors.New("section '" + core.WikiSection + "' cannot be deleted")
}
s, err := db.GetSection(section)
err := db.SectionExists(section)
if err != nil {
return err
}
@ -80,9 +94,6 @@ func (db *DB) DeleteSection(section string, user bool) error {
if err != nil {
return err
}
if !s.User && !user {
return nil
}
section += "/"
var pages []string
db.store.ForEach(func(k string, _ []byte) error {