diff --git a/common/pages.go b/common/pages.go index aeb0db41..dd456963 100644 --- a/common/pages.go +++ b/common/pages.go @@ -208,6 +208,8 @@ type TopicListPage struct { ForumList []Forum DefaultForum int Sort TopicListSort + CanLock bool + CanMove bool Paginator } @@ -215,6 +217,8 @@ type ForumPage struct { *Header ItemList []*TopicsRow Forum *Forum + CanLock bool + CanMove bool Paginator } diff --git a/common/template_init.go b/common/template_init.go index 28e00654..871390ae 100644 --- a/common/template_init.go +++ b/common/template_init.go @@ -228,12 +228,12 @@ func compileCommons(c *tmpl.CTemplateSet, head, head2 *Header, forumList []Forum var topicsList []*TopicsRow topicsList = append(topicsList, &TopicsRow{1, "topic-title", "Topic Title", "The topic content.", 1, false, false, now, now, user3.ID, 1, 1, "", "::1", 1, 0, 1, 1, 0, "classname", 0, "", user2, "", 0, user3, "General", "/forum/general.2", nil}) - topicListPage := TopicListPage{htitle("Topic List"), topicsList, forumList, Config.DefaultForum, TopicListSort{"lastupdated", false}, Paginator{[]int{1}, 1, 1}} + topicListPage := TopicListPage{htitle("Topic List"), topicsList, forumList, Config.DefaultForum, TopicListSort{"lastupdated", false}, false, false, Paginator{[]int{1}, 1, 1}} o.Add("topics", "c.TopicListPage", topicListPage) o.Add("topics_mini", "c.TopicListPage", topicListPage) forumItem := BlankForum(1, "general-forum.1", "General Forum", "Where the general stuff happens", true, "all", 0, "", 0) - forumPage := ForumPage{htitle("General Forum"), topicsList, forumItem, Paginator{[]int{1}, 1, 1}} + forumPage := ForumPage{htitle("General Forum"), topicsList, forumItem, false, false, Paginator{[]int{1}, 1, 1}} o.Add("forum", "c.ForumPage", forumPage) o.Add("forums", "c.ForumsPage", ForumsPage{htitle("Forum List"), forumList}) @@ -311,10 +311,10 @@ func compileTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName string var topicsList []*TopicsRow topicsList = append(topicsList, &TopicsRow{1, "topic-title", "Topic Title", "The topic content.", 1, false, false, now, now, user3.ID, 1, 1, "", "127.0.0.1", 1, 0, 1, 1, 0, "classname", 0, "", user2, "", 0, user3, "General", "/forum/general.2", nil}) - topicListPage := TopicListPage{htitle("Topic List"), topicsList, forumList, Config.DefaultForum, TopicListSort{"lastupdated", false}, Paginator{[]int{1}, 1, 1}} + topicListPage := TopicListPage{htitle("Topic List"), topicsList, forumList, Config.DefaultForum, TopicListSort{"lastupdated", false}, false, false, Paginator{[]int{1}, 1, 1}} forumItem := BlankForum(1, "general-forum.1", "General Forum", "Where the general stuff happens", true, "all", 0, "", 0) - forumPage := ForumPage{htitle("General Forum"), topicsList, forumItem, Paginator{[]int{1}, 1, 1}} + forumPage := ForumPage{htitle("General Forum"), topicsList, forumItem, false, false, Paginator{[]int{1}, 1, 1}} // Experimental! for _, tmpl := range strings.Split(Dev.ExtraTmpls, ",") { diff --git a/routes/forum.go b/routes/forum.go index eb3bc79a..d7be46bd 100644 --- a/routes/forum.go +++ b/routes/forum.go @@ -6,7 +6,7 @@ import ( "strconv" c "github.com/Azareal/Gosora/common" - "github.com/Azareal/Gosora/common/counters" + co "github.com/Azareal/Gosora/common/counters" p "github.com/Azareal/Gosora/common/phrases" ) @@ -55,7 +55,7 @@ func ViewForum(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header, s } //pageList := c.Paginate(page, lastPage, 5) - pi := c.ForumPage{h, topicList, forum, pagi} + pi := c.ForumPage{h, topicList, forum, u.Perms.CloseTopic, u.Perms.MoveTopic, pagi} tmpl := forum.Tmpl if tmpl == "" { ferr = renderTemplate("forum", w, r, h, pi) @@ -66,6 +66,6 @@ func ViewForum(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header, s ferr = renderTemplate("forum", w, r, h, pi) } } - counters.ForumViewCounter.Bump(forum.ID) + co.ForumViewCounter.Bump(forum.ID) return ferr } diff --git a/routes/topic_list.go b/routes/topic_list.go index 112c82fc..0133187f 100644 --- a/routes/topic_list.go +++ b/routes/topic_list.go @@ -20,7 +20,11 @@ func wsTopicList(topicList []*c.TopicsRow, lastPage int) *c.WsTopicList { } func TopicList(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header) c.RouteError { - skip, rerr := h.Hooks.VhookSkippable("route_topic_list_start", w, r, u, h) + /*skip, rerr := h.Hooks.VhookSkippable("route_topic_list_start", w, r, u, h) + if skip || rerr != nil { + return rerr + }*/ + skip, rerr := c.H_route_topic_list_start_hook(h.Hooks, w, r, u, h) if skip || rerr != nil { return rerr } @@ -28,6 +32,10 @@ func TopicList(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header) c } func TopicListMostViewed(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header) c.RouteError { + skip, rerr := h.Hooks.VhookSkippable("route_topic_list_mostviewed_start", w, r, u, h) + if skip || rerr != nil { + return rerr + } return TopicListCommon(w, r, u, h, "mostviewed", c.TopicListMostViewed) } @@ -71,6 +79,7 @@ func TopicListCommon(w http.ResponseWriter, r *http.Request, user *c.User, h *c. var topicList []*c.TopicsRow var forumList []c.Forum var pagi c.Paginator + var canLock, ccanLock, canMove, ccanMove bool q := r.FormValue("q") if q != "" && c.RepliesSearch != nil { var canSee []int @@ -117,6 +126,7 @@ func TopicListCommon(w http.ResponseWriter, r *http.Request, user *c.User, h *c. if err != nil { return c.InternalError(err, w, r) } + // TODO: Cache emptied map across requests with sync pool reqUserList := make(map[int]bool) for _, t := range tMap { reqUserList[t.CreatedBy] = true @@ -141,16 +151,41 @@ func TopicListCommon(w http.ResponseWriter, r *http.Request, user *c.User, h *c. } // TODO: De-dupe this logic in common/topic_list.go? + //var sb strings.Builder for _, t := range topicList { + //c.BuildTopicURLSb(&sb, c.NameToSlug(t.Title), t.ID) + //t.Link = sb.String() + //sb.Reset() t.Link = c.BuildTopicURL(c.NameToSlug(t.Title), t.ID) // TODO: Pass forum to something like t.Forum and use that instead of these two properties? Could be more flexible. forum := c.Forums.DirtyGet(t.ParentID) t.ForumName = forum.Name t.ForumLink = forum.Link + fp, err := c.FPStore.Get(forum.ID, user.Group) + if err == c.ErrNoRows { + fp = c.BlankForumPerms() + } else if err != nil { + return c.InternalError(err, w, r) + } + if fp.Overrides && !user.IsSuperAdmin { + ccanLock = fp.CloseTopic + ccanMove = fp.MoveTopic + } else { + ccanLock = user.Perms.CloseTopic + ccanMove = user.Perms.MoveTopic + } + if ccanLock { + canLock = true + } + if ccanMove { + canMove = true + } + // TODO: Create a specialised function with a bit less overhead for getting the last page for a post count _, _, lastPage := c.PageOffset(t.PostCount, 1, c.Config.ItemsPerPage) t.LastPage = lastPage + // TODO: Avoid map if either is equal to the current user t.Creator = userList[t.CreatedBy] t.LastUser = userList[t.LastReplyBy] } @@ -166,15 +201,37 @@ func TopicListCommon(w http.ResponseWriter, r *http.Request, user *c.User, h *c. } h.Title = phrases.GetTitlePhrase("topics_search") - pi := c.TopicListPage{h, topicList, forumList, c.Config.DefaultForum, c.TopicListSort{torder, false}, pagi} + pi := c.TopicListPage{h, topicList, forumList, c.Config.DefaultForum, c.TopicListSort{torder, false}, canLock, canMove, pagi} return renderTemplate("topics", w, r, h, pi) } // TODO: Pass a struct back rather than passing back so many variables if user.IsSuperAdmin { topicList, forumList, pagi, err = c.TopicList.GetList(page, tsorder, fids) + canLock, canMove = true, true } else { topicList, forumList, pagi, err = c.TopicList.GetListByGroup(group, page, tsorder, fids) + for _, forum := range forumList { + fp, err := c.FPStore.Get(forum.ID, user.Group) + if err == c.ErrNoRows { + fp = c.BlankForumPerms() + } else if err != nil { + return c.InternalError(err, w, r) + } + if fp.Overrides { + ccanLock = fp.CloseTopic + ccanMove = fp.MoveTopic + } else { + ccanLock = user.Perms.CloseTopic + ccanMove = user.Perms.MoveTopic + } + if ccanLock { + canLock = true + } + if ccanMove { + canMove = true + } + } } if err != nil { return c.InternalError(err, w, r) @@ -190,7 +247,7 @@ func TopicListCommon(w http.ResponseWriter, r *http.Request, user *c.User, h *c. return nil } - pi := c.TopicListPage{h, topicList, forumList, c.Config.DefaultForum, c.TopicListSort{torder, false}, pagi} + pi := c.TopicListPage{h, topicList, forumList, c.Config.DefaultForum, c.TopicListSort{torder, false}, canLock, canMove, pagi} if r.FormValue("i") == "1" { return renderTemplate("topics_mini", w, r, h, pi) } diff --git a/templates/forum.html b/templates/forum.html index 569fb09d..aad56ad1 100644 --- a/templates/forum.html +++ b/templates/forum.html @@ -26,7 +26,7 @@ {{end}} {{if .CurrentUser.Loggedin}} - {{template "topics_mod_floater.html"}} + {{template "topics_mod_floater.html" .}} {{if .CurrentUser.Perms.CreateTopic}}
diff --git a/templates/topics_inner.html b/templates/topics_inner.html index e17cd463..22a2a9f5 100644 --- a/templates/topics_inner.html +++ b/templates/topics_inner.html @@ -30,7 +30,7 @@
{{if .CurrentUser.Loggedin}} - {{template "topics_mod_floater.html"}} + {{template "topics_mod_floater.html" .}} {{if .ForumList}} {{/** TODO: Have a seperate forum list for moving topics? Maybe an AJAX forum search compatible with plugin_guilds? **/}} diff --git a/templates/topics_mod_floater.html b/templates/topics_mod_floater.html index f8bdfc47..c9ed277c 100644 --- a/templates/topics_mod_floater.html +++ b/templates/topics_mod_floater.html @@ -7,8 +7,8 @@