diff --git a/pkg/config/enum.go b/pkg/config/enum.go index f4a8284..8036be4 100644 --- a/pkg/config/enum.go +++ b/pkg/config/enum.go @@ -99,6 +99,7 @@ var ( {"report.photo", "Report a problematic photo"}, {"report.message", "Report a direct message conversation"}, {"report.comment", "Report a forum post or comment"}, + {"report.forum", "Report a forum or community"}, }, }, } diff --git a/pkg/controller/admin/feedback.go b/pkg/controller/admin/feedback.go index c9b5542..1820ea1 100644 --- a/pkg/controller/admin/feedback.go +++ b/pkg/controller/admin/feedback.go @@ -102,6 +102,15 @@ func Feedback() http.HandlerFunc { return } } + case "forums": + // Get this forum. + forum, err := models.GetForum(fb.TableID) + if err != nil { + session.FlashError(w, r, "Couldn't get comment ID %d: %s", fb.TableID, err) + } else { + templates.Redirect(w, fmt.Sprintf("/f/%s", forum.Fragment)) + return + } default: session.FlashError(w, r, "Couldn't visit TableID %s/%d: not a supported TableName", fb.TableName, fb.TableID) } diff --git a/pkg/controller/forum/browse.go b/pkg/controller/forum/browse.go index 18d814a..fdbde91 100644 --- a/pkg/controller/forum/browse.go +++ b/pkg/controller/forum/browse.go @@ -18,6 +18,8 @@ func Explore() http.HandlerFunc { var sortWhitelist = []string{ "title asc", "title desc", + "created_at desc", + "created_at asc", } return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/pkg/controller/forum/subscribe.go b/pkg/controller/forum/subscribe.go index 9c7998e..66f52e5 100644 --- a/pkg/controller/forum/subscribe.go +++ b/pkg/controller/forum/subscribe.go @@ -35,14 +35,14 @@ func Subscribe() http.HandlerFunc { return } - // Is it a private forum? - if forum.Private && !currentUser.IsAdmin { - templates.NotFoundPage(w, r) - return - } - switch intent { case "follow": + // Is it a private forum? + if forum.Private && !currentUser.IsAdmin { + templates.NotFoundPage(w, r) + return + } + _, err := models.CreateForumMembership(currentUser, forum) if err != nil { session.FlashError(w, r, "Couldn't follow this forum: %s", err) diff --git a/pkg/controller/index/contact.go b/pkg/controller/index/contact.go index 705f57b..90b637e 100644 --- a/pkg/controller/index/contact.go +++ b/pkg/controller/index/contact.go @@ -83,6 +83,15 @@ func Contact() http.HandlerFunc { } else { log.Error("/contact: couldn't produce table label for comment %d: %s", tableID, err) } + case "report.forum": + tableName = "forums" + + // Find this forum. + if forum, err := models.GetForum(uint64(tableID)); err == nil { + tableLabel = fmt.Sprintf(`The forum "%s" (/f/%s)`, forum.Title, forum.Fragment) + } else { + log.Error("/contact: couldn't produce table label for comment %d: %s", tableID, err) + } } } diff --git a/pkg/models/forum.go b/pkg/models/forum.go index 3db2b8a..3ccb0d6 100644 --- a/pkg/models/forum.go +++ b/pkg/models/forum.go @@ -104,9 +104,24 @@ func PaginateForums(user *User, categories []string, search *Search, subscribed wheres = append(wheres, "explicit = false") } - // Hide private forums except for admins. + // Hide private forums except for admins and approved users. if !user.IsAdmin { - wheres = append(wheres, "private is not true") + wheres = append(wheres, ` + ( + private IS NOT TRUE + OR EXISTS ( + SELECT 1 + FROM forum_memberships + WHERE forum_id = forums.id + AND user_id = ? + AND ( + is_moderator IS TRUE + OR approved IS TRUE + ) + ) + )`, + ) + placeholders = append(placeholders, user.ID) } // Followed forums only? (for the My List category on home page) diff --git a/pkg/models/forum_recent.go b/pkg/models/forum_recent.go index e997acd..4d4758a 100644 --- a/pkg/models/forum_recent.go +++ b/pkg/models/forum_recent.go @@ -49,7 +49,22 @@ func PaginateRecentPosts(user *User, categories []string, subscribed, allComment // Private forums. if !user.IsAdmin { - wheres = append(wheres, "forums.private is not true") + wheres = append(wheres, ` + ( + forums.private IS NOT TRUE + OR EXISTS ( + SELECT 1 + FROM forum_memberships + WHERE forum_id = forums.id + AND user_id = ? + AND ( + is_moderator IS TRUE + OR approved IS TRUE + ) + ) + )`, + ) + placeholders = append(placeholders, user.ID) } // Forums I follow? diff --git a/web/templates/account/dashboard.html b/web/templates/account/dashboard.html index a97cb46..4e0fbc9 100644 --- a/web/templates/account/dashboard.html +++ b/web/templates/account/dashboard.html @@ -595,7 +595,7 @@ Your certification photo was rejected! {{else if eq .Type "forum_moderator"}} - + You have been appointed as a moderator for the forum {{$Body.Forum.Title}}! diff --git a/web/templates/forum/board_index.html b/web/templates/forum/board_index.html index b7abbe6..dd9aed2 100644 --- a/web/templates/forum/board_index.html +++ b/web/templates/forum/board_index.html @@ -197,9 +197,9 @@
- +
- Created: {{.Forum.CreatedAt.Format "Jan _2 2006"}} + Created on: {{.Forum.CreatedAt.Format "Jan _2 2006"}}
{{if .Forum.Explicit}} @@ -231,7 +231,7 @@
- + {{template "avatar-16x16" .Forum.Owner}} @@ -249,6 +249,14 @@ {{end}} + +
diff --git a/web/templates/forum/index.html b/web/templates/forum/index.html index aa35f58..2ac741b 100644 --- a/web/templates/forum/index.html +++ b/web/templates/forum/index.html @@ -87,6 +87,7 @@