The default forum permissions should now cascade properly from groups to forums without overrides.

Added the generated template files to the .gitignore file.
Added the GetAllMap method to the ForumPermsStore.
Fixed several editors.
This commit is contained in:
Azareal 2018-04-24 04:47:39 +01:00
parent 15420d4d89
commit d6f6c362f7
4 changed files with 32 additions and 19 deletions

1
.gitignore vendored
View File

@ -23,3 +23,4 @@ out/*
config/config.go config/config.go
Gosora Gosora
Install Install
template_*.go

View File

@ -12,6 +12,7 @@ var FPStore ForumPermsStore
type ForumPermsStore interface { type ForumPermsStore interface {
Init() error Init() error
GetAllMap() (bigMap map[int]map[int]*ForumPerms)
Get(fid int, gid int) (fperms *ForumPerms, err error) Get(fid int, gid int) (fperms *ForumPerms, err error)
GetCopy(fid int, gid int) (fperms ForumPerms, err error) GetCopy(fid int, gid int) (fperms ForumPerms, err error)
ReloadAll() error ReloadAll() error
@ -134,12 +135,11 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error {
var forumPerm *ForumPerms var forumPerm *ForumPerms
if !ok { if !ok {
forumPerm = BlankForumPerms() continue
} else { }
forumPerm, ok = forumPerms[group.ID] forumPerm, ok = forumPerms[group.ID]
if !ok { if !ok {
forumPerm = BlankForumPerms() continue
}
} }
if forumPerm.Overrides { if forumPerm.Overrides {
@ -149,7 +149,6 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error {
} else if group.Perms.ViewTopic { } else if group.Perms.ViewTopic {
group.CanSee = append(group.CanSee, fid) group.CanSee = append(group.CanSee, fid)
} }
DebugDetail("group.ID: ", group.ID) DebugDetail("group.ID: ", group.ID)
DebugDetailf("forumPerm: %+v\n", forumPerm) DebugDetailf("forumPerm: %+v\n", forumPerm)
DebugDetail("group.CanSee: ", group.CanSee) DebugDetail("group.CanSee: ", group.CanSee)
@ -159,6 +158,22 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error {
return nil return nil
} }
// ! Throughput on this might be bad due to the excessive locking
func (fps *MemoryForumPermsStore) GetAllMap() (bigMap map[int]map[int]*ForumPerms) {
bigMap = make(map[int]map[int]*ForumPerms)
fps.evenLock.RLock()
for fid, subMap := range fps.evenForums {
bigMap[fid] = subMap
}
fps.evenLock.RUnlock()
fps.oddLock.RLock()
for fid, subMap := range fps.oddForums {
bigMap[fid] = subMap
}
fps.oddLock.RUnlock()
return bigMap
}
// TODO: Add a hook here and have plugin_guilds use it // TODO: Add a hook here and have plugin_guilds use it
// TODO: Check if the forum exists? // TODO: Check if the forum exists?
// TODO: Fix the races // TODO: Fix the races

View File

@ -2,7 +2,6 @@ package common
import ( import (
"html" "html"
"log"
"net" "net"
"net/http" "net/http"
"strconv" "strconv"
@ -37,10 +36,8 @@ func simpleForumUserCheck(w http.ResponseWriter, r *http.Request, user *User, fi
} }
fperms, err := FPStore.Get(fid, user.Group) fperms, err := FPStore.Get(fid, user.Group)
if err != nil { if err != nil && err != ErrNoRows {
// TODO: Refactor this return headerLite, InternalError(err, w, r)
log.Printf("Unable to get the forum perms for Group #%d for User #%d", user.Group, user.ID)
return nil, PreError("Something weird happened", w, r)
} }
cascadeForumPerms(fperms, user) cascadeForumPerms(fperms, user)
return headerLite, nil return headerLite, nil
@ -64,10 +61,8 @@ func forumUserCheck(w http.ResponseWriter, r *http.Request, user *User, fid int)
} }
fperms, err := FPStore.Get(fid, user.Group) fperms, err := FPStore.Get(fid, user.Group)
if err != nil { if err != nil && err != ErrNoRows {
// TODO: Refactor this return header, InternalError(err, w, r)
log.Printf("Unable to get the forum perms for Group #%d for User #%d", user.Group, user.ID)
return nil, PreError("Something weird happened", w, r)
} }
cascadeForumPerms(fperms, user) cascadeForumPerms(fperms, user)
return header, rerr return header, rerr

View File

@ -332,7 +332,9 @@ func routePanelForumsEdit(w http.ResponseWriter, r *http.Request, user common.Us
continue continue
} }
forumPerms, err := common.FPStore.Get(fid, group.ID) forumPerms, err := common.FPStore.Get(fid, group.ID)
if err != nil { if err == ErrNoRows {
forumPerms = common.BlankForumPerms()
} else if err != nil {
return common.InternalError(err, w, r) return common.InternalError(err, w, r)
} }
gplist = append(gplist, common.GroupForumPermPreset{group, common.ForumPermsToGroupForumPreset(forumPerms)}) gplist = append(gplist, common.GroupForumPermPreset{group, common.ForumPermsToGroupForumPreset(forumPerms)})
@ -479,7 +481,7 @@ func routePanelForumsEditPermsAdvance(w http.ResponseWriter, r *http.Request, us
forumPerms, err := common.FPStore.Get(fid, gid) forumPerms, err := common.FPStore.Get(fid, gid)
if err == ErrNoRows { if err == ErrNoRows {
return common.LocalError("The requested group doesn't exist.", w, r, user) forumPerms = common.BlankForumPerms()
} else if err != nil { } else if err != nil {
return common.InternalError(err, w, r) return common.InternalError(err, w, r)
} }
@ -544,7 +546,7 @@ func routePanelForumsEditPermsAdvanceSubmit(w http.ResponseWriter, r *http.Reque
forumPerms, err := common.FPStore.GetCopy(fid, gid) forumPerms, err := common.FPStore.GetCopy(fid, gid)
if err == ErrNoRows { if err == ErrNoRows {
return common.LocalError("The requested group doesn't exist.", w, r, user) forumPerms = *common.BlankForumPerms()
} else if err != nil { } else if err != nil {
return common.InternalError(err, w, r) return common.InternalError(err, w, r)
} }