Testing feature flags

This commit is contained in:
Noah Petherbridge 2024-08-23 22:53:40 -07:00
parent 6c4b1965c1
commit 81ab9d29b0
6 changed files with 40 additions and 6 deletions

View File

@ -124,7 +124,7 @@ const (
ThreadViewDebounceCooldown = 1 * time.Hour
// Enable user-owned forums (feature flag)
UserForumsEnabled = true
UserForumsEnabled = false
)
// User-Owned Forums: Quota settings for how many forums a user can own.

View File

@ -25,6 +25,8 @@ func Search() http.HandlerFunc {
searchTerm = r.FormValue("q")
byUsername = r.FormValue("username")
postType = r.FormValue("type")
inForum = r.FormValue("in")
categories = []string{}
sort = r.FormValue("sort")
sortOK bool
)
@ -45,6 +47,14 @@ func Search() http.HandlerFunc {
postType = "all"
}
// In forums
switch inForum {
case "official":
categories = config.ForumCategories
case "community":
categories = []string{""}
}
// Get the current user.
currentUser, err := session.CurrentUser(r)
if err != nil {
@ -80,7 +90,7 @@ func Search() http.HandlerFunc {
)
pager.ParsePage(r)
posts, err := models.SearchForum(currentUser, search, filters, pager)
posts, err := models.SearchForum(currentUser, categories, search, filters, pager)
if err != nil {
session.FlashError(w, r, "Couldn't search the forums: %s", err)
templates.Redirect(w, "/")
@ -109,6 +119,7 @@ func Search() http.HandlerFunc {
"SearchTerm": searchTerm,
"ByUsername": byUsername,
"Type": postType,
"InForum": inForum,
"Sort": sort,
}
if err := tmpl.Execute(w, r, vars); err != nil {

View File

@ -81,7 +81,7 @@ type ForumSearchFilters struct {
}
// SearchForum searches the forum.
func SearchForum(user *User, search *Search, filters ForumSearchFilters, pager *Pagination) ([]*Comment, error) {
func SearchForum(user *User, categories []string, search *Search, filters ForumSearchFilters, pager *Pagination) ([]*Comment, error) {
var (
coms = []*Comment{}
query = (&Comment{}).Preload()
@ -90,6 +90,11 @@ func SearchForum(user *User, search *Search, filters ForumSearchFilters, pager *
placeholders = []interface{}{}
)
if len(categories) > 0 {
wheres = append(wheres, "category IN ?")
placeholders = append(placeholders, categories)
}
// Hide explicit forum if user hasn't opted into it.
if !user.Explicit && !user.IsAdmin {
wheres = append(wheres, "forums.explicit = false")

View File

@ -873,11 +873,11 @@
<h3 id="create-forums">Can I create my own forums?</h3>
{{if .FeatureUserForumsEnabled}}
<p>
<span class="tag is-success">NEW: August 30, 2024</span>
</p>
{{if .FeatureUserForumsEnabled}}
<p>
<strong>Yes!</strong> As of August 30, 2024 (the two-year anniversary of {{PrettyTitle}}),
we now have <strong>Community Forums</strong> where members are allowed to create their own

View File

@ -85,7 +85,7 @@
</p>
</div>
{{if .CurrentUser.IsAdmin}}
{{if .CurrentUser.HasAdminScope "admin.forum.manage"}}
<div class="field">
<label class="label" for="category">
Category

View File

@ -66,7 +66,7 @@
</div>
<div class="columns">
<div class="column px-1">
<div class="column pr-1">
<div class="field">
<label class="label" for="type">Show:</label>
<div class="select is-fullwidth">
@ -78,6 +78,24 @@
</div>
</div>
{{if .FeatureUserForumsEnabled}}
<div class="column px-1">
<div class="field">
<label class="label" for="in_forum">In forums:</label>
<div class="select is-fullwidth">
<select id="in_forum" name="in">
<option value="">All forums</option>
<option value="official"{{if eq .InForum "official"}} selected{{end}}>Official nonshy forums</option>
<option value="community"{{if eq .InForum "community"}} selected{{end}}>Community forums only</option>
{{if .CurrentUser.HasForumSubscriptions}}
<option value="followed"{{if eq .InForum "followed"}} selected{{end}}>My List</option>
{{end}}
</select>
</div>
</div>
</div>
{{end}}
<div class="column px-1">
<div class="field">
<label class="label" for="sort">Sort by:</label>