Fixed the permission system.
Added more debug logging. Renamed the label in the Forum Manager and Editor from Hidden to Active. Fixed a bug in compileTemplates() where it only loads visible forums from the forum store possibly causing trouble. Fixed a bug in the /topics/ route where super admin status wasn't being taken into consideration. Dropped down a hotfix for the /topics/ route.
This commit is contained in:
parent
2ef7726080
commit
b955f677a7
@ -78,14 +78,16 @@ func routeTopicCreate(w http.ResponseWriter, r *http.Request, user User, sfid st
|
|||||||
|
|
||||||
// Do a bulk forum fetch, just in case it's the SqlForumStore?
|
// Do a bulk forum fetch, just in case it's the SqlForumStore?
|
||||||
forum := fstore.DirtyGet(ffid)
|
forum := fstore.DirtyGet(ffid)
|
||||||
fcopy := *forum
|
if forum.Name != "" && forum.Active {
|
||||||
if hooks["topic_create_frow_assign"] != nil {
|
fcopy := *forum
|
||||||
// TODO: Add the skip feature to all the other row based hooks?
|
if hooks["topic_create_frow_assign"] != nil {
|
||||||
if runHook("topic_create_frow_assign", &fcopy).(bool) {
|
// TODO: Add the skip feature to all the other row based hooks?
|
||||||
continue
|
if runHook("topic_create_frow_assign", &fcopy).(bool) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
forumList = append(forumList, fcopy)
|
||||||
}
|
}
|
||||||
forumList = append(forumList, fcopy)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctpage := CreateTopicPage{"Create Topic", user, headerVars, forumList, fid}
|
ctpage := CreateTopicPage{"Create Topic", user, headerVars, forumList, fid}
|
||||||
|
@ -234,12 +234,21 @@ INSERT INTO users_groups(`name`,`permissions`,`plugin_perms`,`tag`) VALUES ('Not
|
|||||||
|
|
||||||
INSERT INTO forums(`name`,`active`) VALUES ('Reports',0);
|
INSERT INTO forums(`name`,`active`) VALUES ('Reports',0);
|
||||||
INSERT INTO forums(`name`,`lastTopicTime`,`lastTopicID`,`lastReplyer`,`lastReplyerID`,`lastTopic`) VALUES ('General',UTC_TIMESTAMP(),1,"Admin",1,'Test Topic');
|
INSERT INTO forums(`name`,`lastTopicTime`,`lastTopicID`,`lastReplyer`,`lastReplyerID`,`lastTopic`) VALUES ('General',UTC_TIMESTAMP(),1,"Admin",1,'Test Topic');
|
||||||
|
|
||||||
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (1,1,'{"ViewTopic":true,"CreateReply":true,"CreateTopic":true,"PinTopic":true,"CloseTopic":true}');
|
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (1,1,'{"ViewTopic":true,"CreateReply":true,"CreateTopic":true,"PinTopic":true,"CloseTopic":true}');
|
||||||
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (2,1,'{"ViewTopic":true,"CreateReply":true,"CloseTopic":true}');
|
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (2,1,'{"ViewTopic":true,"CreateReply":true,"CloseTopic":true}');
|
||||||
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (3,1,'{}');
|
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (3,1,'{}');
|
||||||
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (4,1,'{}');
|
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (4,1,'{}');
|
||||||
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (5,1,'{}');
|
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (5,1,'{}');
|
||||||
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (6,1,'{}');
|
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (6,1,'{}');
|
||||||
|
|
||||||
|
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (1,2,'{"ViewTopic":true,"CreateReply":true,"CreateTopic":true,"LikeItem":true,"EditTopic":true,"DeleteTopic":true,"EditReply":true,"DeleteReply":true,"PinTopic":true,"CloseTopic":true}');
|
||||||
|
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (2,2,'{"ViewTopic":true,"CreateReply":true,"CreateTopic":true,"LikeItem":true,"EditTopic":true,"DeleteTopic":true,"EditReply":true,"DeleteReply":true,"PinTopic":true,"CloseTopic":true}');
|
||||||
|
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (3,2,'{"ViewTopic":true,"CreateReply":true,"CreateTopic":true,"LikeItem":true}');
|
||||||
|
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (4,2,'{"ViewTopic":true}');
|
||||||
|
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (5,2,'{"ViewTopic":true}');
|
||||||
|
INSERT INTO forums_permissions(`gid`,`fid`,`permissions`) VALUES (6,2,'{"ViewTopic":true}');
|
||||||
|
|
||||||
INSERT INTO topics(`title`,`content`,`createdAt`,`lastReplyAt`,`lastReplyBy`,`createdBy`,`parentID`)
|
INSERT INTO topics(`title`,`content`,`createdAt`,`lastReplyAt`,`lastReplyBy`,`createdBy`,`parentID`)
|
||||||
VALUES ('Test Topic','A topic automatically generated by the software.',UTC_TIMESTAMP(),UTC_TIMESTAMP(),1,1,2);
|
VALUES ('Test Topic','A topic automatically generated by the software.',UTC_TIMESTAMP(),UTC_TIMESTAMP(),1,1,2);
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ func rebuildForumPermissions(fid int) error {
|
|||||||
if dev.DebugMode {
|
if dev.DebugMode {
|
||||||
log.Print("Loading the forum permissions")
|
log.Print("Loading the forum permissions")
|
||||||
}
|
}
|
||||||
forums, err := fstore.GetAll()
|
fids, err := fstore.GetAllIDs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -350,28 +350,29 @@ func rebuildForumPermissions(fid int) error {
|
|||||||
group.Forums = []ForumPerms{BlankForumPerms}
|
group.Forums = []ForumPerms{BlankForumPerms}
|
||||||
group.CanSee = []int{}
|
group.CanSee = []int{}
|
||||||
|
|
||||||
for ffid := range forums {
|
for _, ffid := range fids {
|
||||||
forumPerm, ok := forumPerms[group.ID][ffid]
|
forumPerm, ok := forumPerms[group.ID][ffid]
|
||||||
if ok {
|
if ok {
|
||||||
//log.Print("Overriding permissions for forum #" + strconv.Itoa(fid))
|
//log.Print("Overriding permissions for forum #" + strconv.Itoa(fid))
|
||||||
group.Forums = append(group.Forums, forumPerm)
|
group.Forums = append(group.Forums, forumPerm)
|
||||||
if forumPerm.Overrides {
|
|
||||||
if forumPerm.ViewTopic {
|
|
||||||
group.CanSee = append(group.CanSee, ffid)
|
|
||||||
}
|
|
||||||
} else if group.Perms.ViewTopic {
|
|
||||||
group.CanSee = append(group.CanSee, ffid)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//log.Print("Inheriting from default for forum #" + strconv.Itoa(fid))
|
//log.Print("Inheriting from default for forum #" + strconv.Itoa(fid))
|
||||||
forumPerm = BlankForumPerms
|
forumPerm = BlankForumPerms
|
||||||
group.Forums = append(group.Forums, forumPerm)
|
group.Forums = append(group.Forums, forumPerm)
|
||||||
}
|
}
|
||||||
|
if forumPerm.Overrides {
|
||||||
|
if forumPerm.ViewTopic {
|
||||||
|
group.CanSee = append(group.CanSee, ffid)
|
||||||
|
}
|
||||||
|
} else if group.Perms.ViewTopic {
|
||||||
|
group.CanSee = append(group.CanSee, ffid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if dev.SuperDebug {
|
if dev.SuperDebug {
|
||||||
log.Printf("group.CanSee %+v\n", group.CanSee)
|
log.Printf("group.CanSee %+v\n", group.CanSee)
|
||||||
log.Printf("group.Forums %+v\n", group.Forums)
|
log.Printf("group.Forums %+v\n", group.Forums)
|
||||||
log.Print("len(group.Forums)", len(group.Forums))
|
log.Print("len(group.CanSee)", len(group.CanSee))
|
||||||
|
log.Print("len(group.Forums)", len(group.Forums)) // This counts blank aka 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -379,10 +380,13 @@ func rebuildForumPermissions(fid int) error {
|
|||||||
|
|
||||||
// ? - We could have buildForumPermissions and rebuildForumPermissions call a third function containing common logic?
|
// ? - We could have buildForumPermissions and rebuildForumPermissions call a third function containing common logic?
|
||||||
func buildForumPermissions() error {
|
func buildForumPermissions() error {
|
||||||
forums, err := fstore.GetAll()
|
fids, err := fstore.GetAllIDs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if dev.SuperDebug {
|
||||||
|
log.Print("fids: ", fids)
|
||||||
|
}
|
||||||
|
|
||||||
rows, err := getForumsPermissionsStmt.Query()
|
rows, err := getForumsPermissionsStmt.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -392,6 +396,9 @@ func buildForumPermissions() error {
|
|||||||
|
|
||||||
if dev.DebugMode {
|
if dev.DebugMode {
|
||||||
log.Print("Adding the forum permissions")
|
log.Print("Adding the forum permissions")
|
||||||
|
if dev.SuperDebug {
|
||||||
|
log.Print("forumPerms[gid][fid]")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Temporarily store the forum perms in a map before transferring it to a much faster and thread-safe slice
|
// Temporarily store the forum perms in a map before transferring it to a much faster and thread-safe slice
|
||||||
forumPerms = make(map[int]map[int]ForumPerms)
|
forumPerms = make(map[int]map[int]ForumPerms)
|
||||||
@ -403,6 +410,10 @@ func buildForumPermissions() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dev.SuperDebug {
|
||||||
|
log.Print("perms: ", string(perms))
|
||||||
|
}
|
||||||
err = json.Unmarshal(perms, &pperms)
|
err = json.Unmarshal(perms, &pperms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -413,11 +424,14 @@ func buildForumPermissions() error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
forumPerms[gid] = make(map[int]ForumPerms)
|
forumPerms[gid] = make(map[int]ForumPerms)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dev.SuperDebug {
|
||||||
|
log.Print("gid: ", gid)
|
||||||
|
log.Print("fid: ", fid)
|
||||||
|
log.Printf("perms: %+v;", pperms)
|
||||||
|
}
|
||||||
forumPerms[gid][fid] = pperms
|
forumPerms[gid][fid] = pperms
|
||||||
}
|
}
|
||||||
if dev.SuperDebug {
|
|
||||||
log.Print("forumPerms ", forumPerms)
|
|
||||||
}
|
|
||||||
|
|
||||||
groups, err := gstore.GetAll()
|
groups, err := gstore.GetAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -430,32 +444,40 @@ func buildForumPermissions() error {
|
|||||||
}
|
}
|
||||||
group.Forums = []ForumPerms{BlankForumPerms}
|
group.Forums = []ForumPerms{BlankForumPerms}
|
||||||
group.CanSee = []int{}
|
group.CanSee = []int{}
|
||||||
for fid := range forums {
|
for _, fid := range fids {
|
||||||
|
if dev.SuperDebug {
|
||||||
|
log.Printf("Forum #%+v\n", fid)
|
||||||
|
}
|
||||||
forumPerm, ok := forumPerms[group.ID][fid]
|
forumPerm, ok := forumPerms[group.ID][fid]
|
||||||
if ok {
|
if ok {
|
||||||
// Override group perms
|
// Override group perms
|
||||||
//log.Print("Overriding permissions for forum #" + strconv.Itoa(fid))
|
//log.Print("Overriding permissions for forum #" + strconv.Itoa(fid))
|
||||||
group.Forums = append(group.Forums, forumPerm)
|
group.Forums = append(group.Forums, forumPerm)
|
||||||
if forumPerm.Overrides {
|
|
||||||
if forumPerm.ViewTopic {
|
|
||||||
group.CanSee = append(group.CanSee, fid)
|
|
||||||
}
|
|
||||||
} else if group.Perms.ViewTopic {
|
|
||||||
group.CanSee = append(group.CanSee, fid)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Inherit from Group
|
// Inherit from Group
|
||||||
// ? - Is this really inheriting from the Group? At-least for CanSee?
|
|
||||||
//log.Print("Inheriting from default for forum #" + strconv.Itoa(fid))
|
//log.Print("Inheriting from default for forum #" + strconv.Itoa(fid))
|
||||||
forumPerm = BlankForumPerms
|
forumPerm = BlankForumPerms
|
||||||
group.Forums = append(group.Forums, forumPerm)
|
group.Forums = append(group.Forums, forumPerm)
|
||||||
}
|
}
|
||||||
|
if forumPerm.Overrides {
|
||||||
|
if forumPerm.ViewTopic {
|
||||||
|
group.CanSee = append(group.CanSee, fid)
|
||||||
|
}
|
||||||
|
} else if group.Perms.ViewTopic {
|
||||||
|
group.CanSee = append(group.CanSee, fid)
|
||||||
|
}
|
||||||
|
|
||||||
|
if dev.SuperDebug {
|
||||||
|
log.Print("group.ID: ", group.ID)
|
||||||
|
log.Printf("forumPerm: %+v\n", forumPerm)
|
||||||
|
log.Print("group.CanSee: ", group.CanSee)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if dev.SuperDebug {
|
if dev.SuperDebug {
|
||||||
log.Printf("group.CanSee %+v\n", group.CanSee)
|
log.Printf("group.CanSee %+v\n", group.CanSee)
|
||||||
log.Printf("group.Forums %+v\n", group.Forums)
|
log.Printf("group.Forums %+v\n", group.Forums)
|
||||||
log.Print("len(group.CanSee)", len(group.CanSee))
|
log.Print("len(group.CanSee)", len(group.CanSee))
|
||||||
log.Print("len(group.Forums)", len(group.Forums))
|
log.Print("len(group.Forums)", len(group.Forums)) // This counts blank aka 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
25
routes.go
25
routes.go
@ -149,6 +149,7 @@ func routeTopics(w http.ResponseWriter, r *http.Request, user User) {
|
|||||||
}
|
}
|
||||||
BuildWidgets("topics", nil, headerVars, r)
|
BuildWidgets("topics", nil, headerVars, r)
|
||||||
|
|
||||||
|
// TODO: Add a function for the qlist stuff
|
||||||
var qlist string
|
var qlist string
|
||||||
var fidList []interface{}
|
var fidList []interface{}
|
||||||
group, err := gstore.Get(user.Group)
|
group, err := gstore.Get(user.Group)
|
||||||
@ -158,12 +159,30 @@ func routeTopics(w http.ResponseWriter, r *http.Request, user User) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, fid := range group.CanSee {
|
var canSee []int
|
||||||
if fstore.DirtyGet(fid).Name != "" {
|
if user.IsSuperAdmin {
|
||||||
|
canSee, err = fstore.GetAllVisibleIDs()
|
||||||
|
if err != nil {
|
||||||
|
InternalError(err, w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
canSee = group.CanSee
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, fid := range canSee {
|
||||||
|
forum := fstore.DirtyGet(fid)
|
||||||
|
if forum.Name != "" && forum.Active {
|
||||||
fidList = append(fidList, strconv.Itoa(fid))
|
fidList = append(fidList, strconv.Itoa(fid))
|
||||||
qlist += "?,"
|
qlist += "?,"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ! Need an inline error not a page level error
|
||||||
|
if qlist == "" {
|
||||||
|
NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
qlist = qlist[0 : len(qlist)-1]
|
qlist = qlist[0 : len(qlist)-1]
|
||||||
|
|
||||||
var topicList []*TopicsRow
|
var topicList []*TopicsRow
|
||||||
@ -400,7 +419,7 @@ func routeForums(w http.ResponseWriter, r *http.Request, user User) {
|
|||||||
for _, fid := range canSee {
|
for _, fid := range canSee {
|
||||||
//log.Print(forums[fid])
|
//log.Print(forums[fid])
|
||||||
var forum = *fstore.DirtyGet(fid)
|
var forum = *fstore.DirtyGet(fid)
|
||||||
if forum.ParentID == 0 {
|
if forum.ParentID == 0 && forum.Name != "" && forum.Active {
|
||||||
if forum.LastTopicID != 0 {
|
if forum.LastTopicID != 0 {
|
||||||
forum.LastTopicTime, err = relativeTime(forum.LastTopicTime)
|
forum.LastTopicTime, err = relativeTime(forum.LastTopicTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -129,7 +129,7 @@ func compileTemplates() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var forumList []Forum
|
var forumList []Forum
|
||||||
forums, err := fstore.GetAllVisible()
|
forums, err := fstore.GetAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ var form_vars = {'perm_preset': ['can_moderate','can_post','read_only','no_acces
|
|||||||
<div class="formitem"><input name="forum_desc" type="text" value="{{.Desc}}" placeholder="Where the general stuff happens" /></div>
|
<div class="formitem"><input name="forum_desc" type="text" value="{{.Desc}}" placeholder="Where the general stuff happens" /></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="formrow">
|
<div class="formrow">
|
||||||
<div class="formitem formlabel"><a>Hidden?</a></div>
|
<div class="formitem formlabel"><a>Active</a></div>
|
||||||
<div class="formitem"><select name="forum_active">
|
<div class="formitem"><select name="forum_active">
|
||||||
<option{{if not .Active}} selected{{end}} value="1">Yes</option>
|
<option{{if not .Active}} selected{{end}} value="1">Yes</option>
|
||||||
<option{{if .Active}} selected{{end}} value="0">No</option>
|
<option{{if .Active}} selected{{end}} value="0">No</option>
|
||||||
|
@ -47,10 +47,10 @@
|
|||||||
<div class="formitem"><input name="forum-desc" type="text" placeholder="Where all the super secret stuff happens" /></div>
|
<div class="formitem"><input name="forum-desc" type="text" placeholder="Where all the super secret stuff happens" /></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="formrow">
|
<div class="formrow">
|
||||||
<div class="formitem formlabel"><a>Hidden?</a></div>
|
<div class="formitem formlabel"><a>Active</a></div>
|
||||||
<div class="formitem"><select name="forum-active">
|
<div class="formitem"><select name="forum-active">
|
||||||
<option value="0">Yes</option>
|
<option value="1">Yes</option>
|
||||||
<option value="1">No</option>
|
<option value="0">No</option>
|
||||||
</select></div>
|
</select></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="formrow">
|
<div class="formrow">
|
||||||
|
@ -176,6 +176,7 @@ func (mus *MemoryUserStore) BulkGetMap(ids []int) (list map[int]*User, err error
|
|||||||
return list, nil
|
return list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Add a function for the qlist stuff
|
||||||
var qlist string
|
var qlist string
|
||||||
var uidList []interface{}
|
var uidList []interface{}
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
|
Loading…
Reference in New Issue
Block a user