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
Gosora
Install
template_*.go

View File

@ -12,6 +12,7 @@ var FPStore ForumPermsStore
type ForumPermsStore interface {
Init() error
GetAllMap() (bigMap map[int]map[int]*ForumPerms)
Get(fid int, gid int) (fperms *ForumPerms, err error)
GetCopy(fid int, gid int) (fperms ForumPerms, err error)
ReloadAll() error
@ -134,12 +135,11 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error {
var forumPerm *ForumPerms
if !ok {
forumPerm = BlankForumPerms()
} else {
forumPerm, ok = forumPerms[group.ID]
if !ok {
forumPerm = BlankForumPerms()
}
continue
}
forumPerm, ok = forumPerms[group.ID]
if !ok {
continue
}
if forumPerm.Overrides {
@ -149,7 +149,6 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error {
} else if group.Perms.ViewTopic {
group.CanSee = append(group.CanSee, fid)
}
DebugDetail("group.ID: ", group.ID)
DebugDetailf("forumPerm: %+v\n", forumPerm)
DebugDetail("group.CanSee: ", group.CanSee)
@ -159,6 +158,22 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error {
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: Check if the forum exists?
// TODO: Fix the races

View File

@ -2,7 +2,6 @@ package common
import (
"html"
"log"
"net"
"net/http"
"strconv"
@ -37,10 +36,8 @@ func simpleForumUserCheck(w http.ResponseWriter, r *http.Request, user *User, fi
}
fperms, err := FPStore.Get(fid, user.Group)
if err != nil {
// TODO: Refactor this
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)
if err != nil && err != ErrNoRows {
return headerLite, InternalError(err, w, r)
}
cascadeForumPerms(fperms, user)
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)
if err != nil {
// TODO: Refactor this
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)
if err != nil && err != ErrNoRows {
return header, InternalError(err, w, r)
}
cascadeForumPerms(fperms, user)
return header, rerr

View File

@ -332,7 +332,9 @@ func routePanelForumsEdit(w http.ResponseWriter, r *http.Request, user common.Us
continue
}
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)
}
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)
if err == ErrNoRows {
return common.LocalError("The requested group doesn't exist.", w, r, user)
forumPerms = common.BlankForumPerms()
} else if err != nil {
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)
if err == ErrNoRows {
return common.LocalError("The requested group doesn't exist.", w, r, user)
forumPerms = *common.BlankForumPerms()
} else if err != nil {
return common.InternalError(err, w, r)
}